prepare for multiple apps
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/logger.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
import 'package:weblibre/features/web_feed/data/providers.dart';
|
||||
|
||||
part 'article_content_processor.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class ArticleContentProcessorService extends _$ArticleContentProcessorService {
|
||||
@override
|
||||
void build() {
|
||||
final db = ref.watch(feedDatabaseProvider);
|
||||
|
||||
final processSub = db.articleDao.getUnprocessedArticles().watch().listen((
|
||||
articles,
|
||||
) async {
|
||||
try {
|
||||
final content = await GeckoBrowserExtensionService.turndownHtml(
|
||||
articles.map((article) => article.contentHtml ?? '').toList(),
|
||||
);
|
||||
final summary = await GeckoBrowserExtensionService.turndownHtml(
|
||||
articles.map((article) => article.summaryHtml ?? '').toList(),
|
||||
);
|
||||
|
||||
await db.articleDao.updateArticleContent(
|
||||
articles
|
||||
.mapIndexed(
|
||||
(index, article) => article.copyWith(
|
||||
contentMarkdown: content[index].markdown ?? '',
|
||||
contentPlain: content[index].plain,
|
||||
summaryMarkdown: summary[index].markdown ?? '',
|
||||
summaryPlain: summary[index].plain,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
|
||||
logger.i('Processed ${articles.length} articles');
|
||||
} catch (e, s) {
|
||||
logger.e('Error processing articles', error: e, stackTrace: s);
|
||||
}
|
||||
});
|
||||
|
||||
ref.onDispose(() async {
|
||||
await processSub.cancel();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'article_content_processor.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(ArticleContentProcessorService)
|
||||
final articleContentProcessorServiceProvider =
|
||||
ArticleContentProcessorServiceProvider._();
|
||||
|
||||
final class ArticleContentProcessorServiceProvider
|
||||
extends $NotifierProvider<ArticleContentProcessorService, void> {
|
||||
ArticleContentProcessorServiceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'articleContentProcessorServiceProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$articleContentProcessorServiceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
ArticleContentProcessorService create() => ArticleContentProcessorService();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$articleContentProcessorServiceHash() =>
|
||||
r'e7cc3da71f6dcf39b0c10df4dcd061f816d5c12e';
|
||||
|
||||
abstract class _$ArticleContentProcessorService extends $Notifier<void> {
|
||||
void build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<void, void>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<void, void>,
|
||||
void,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/extensions/http_encoding.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_parse_result.dart';
|
||||
import 'package:weblibre/features/web_feed/utils/feed_parser.dart';
|
||||
|
||||
part 'feed_reader.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class FeedReader extends _$FeedReader {
|
||||
Future<FeedParseResult> parseFeed(Uri url) async {
|
||||
final rootIsolateToken = ServicesBinding.rootIsolateToken!;
|
||||
|
||||
final result = await compute((args) async {
|
||||
// Initialize BackgroundIsolateBinaryMessenger with the token
|
||||
BackgroundIsolateBinaryMessenger.ensureInitialized(
|
||||
args['token']! as RootIsolateToken,
|
||||
);
|
||||
|
||||
final client = http.Client();
|
||||
try {
|
||||
final url = Uri.parse(args['url']! as String);
|
||||
final response = await client
|
||||
.get(url)
|
||||
.timeout(const Duration(seconds: 30));
|
||||
|
||||
final parser = FeedParser.parse(
|
||||
url: url,
|
||||
xmlString: response.bodyUnicodeFallback,
|
||||
);
|
||||
final result = FeedParseResult(
|
||||
feedData: parser.readGeneralData(),
|
||||
articleData: parser.readArticles(),
|
||||
);
|
||||
|
||||
return result.toJson();
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}, {'token': rootIsolateToken, 'url': url.toString()});
|
||||
|
||||
return FeedParseResult.fromJson(result);
|
||||
}
|
||||
|
||||
@override
|
||||
void build() {}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_reader.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(FeedReader)
|
||||
final feedReaderProvider = FeedReaderProvider._();
|
||||
|
||||
final class FeedReaderProvider extends $NotifierProvider<FeedReader, void> {
|
||||
FeedReaderProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'feedReaderProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$feedReaderHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
FeedReader create() => FeedReader();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$feedReaderHash() => r'5d1ca364fe7ad702628a7f2bbd3e706876bc3111';
|
||||
|
||||
abstract class _$FeedReader extends $Notifier<void> {
|
||||
void build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<void, void>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<void, void>,
|
||||
void,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user