web feed intermediate
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_author.dart';
|
||||
|
||||
class FeedAuthorsConverter extends TypeConverter<List<FeedAuthor>, String> {
|
||||
const FeedAuthorsConverter();
|
||||
|
||||
@override
|
||||
List<FeedAuthor> fromSql(String fromDb) {
|
||||
final authors = jsonDecode(fromDb) as List<dynamic>;
|
||||
return authors
|
||||
.map((author) => FeedAuthor.fromJson(author as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
String toSql(List<FeedAuthor> value) {
|
||||
return jsonEncode(value.map((author) => author.toJson()).toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_category.dart';
|
||||
|
||||
class FeedCategoriesConverter
|
||||
extends TypeConverter<List<FeedCategory>, String> {
|
||||
const FeedCategoriesConverter();
|
||||
|
||||
@override
|
||||
List<FeedCategory> fromSql(String fromDb) {
|
||||
final categories = jsonDecode(fromDb) as List<dynamic>;
|
||||
return categories
|
||||
.map(
|
||||
(category) => FeedCategory.fromJson(category as Map<String, dynamic>),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
String toSql(List<FeedCategory> value) {
|
||||
return jsonEncode(value.map((category) => category.toJson()).toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/database.dart';
|
||||
|
||||
class FeedDataConverter extends JsonConverter<FeedData, Map<String, dynamic>> {
|
||||
const FeedDataConverter();
|
||||
|
||||
@override
|
||||
FeedData fromJson(Map<String, dynamic> json) {
|
||||
return FeedData.fromJson(json);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson(FeedData object) {
|
||||
return object.toJson();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_link.dart';
|
||||
|
||||
class FeedLinksConverter extends TypeConverter<List<FeedLink>, String> {
|
||||
const FeedLinksConverter();
|
||||
|
||||
@override
|
||||
List<FeedLink> fromSql(String fromDb) {
|
||||
final links = jsonDecode(fromDb) as List<dynamic>;
|
||||
return links
|
||||
.map((link) => FeedLink.fromJson(link as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
String toSql(List<FeedLink> value) {
|
||||
return jsonEncode(value.map((link) => link.toJson()).toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/database.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_article.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_article_query_result.dart';
|
||||
|
||||
part 'article.g.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class ArticleDao extends DatabaseAccessor<FeedDatabase> with _$ArticleDaoMixin {
|
||||
ArticleDao(super.attachedDatabase);
|
||||
|
||||
Selectable<FeedArticle> getFeedArticles(Uri? url) {
|
||||
final select = db.article.select();
|
||||
|
||||
if (url != null) {
|
||||
select.where((article) => article.feedId.equalsValue(url));
|
||||
}
|
||||
|
||||
return select..orderBy([
|
||||
(row) => OrderingTerm(
|
||||
expression: coalesce([row.updated, row.created]),
|
||||
mode: OrderingMode.desc,
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
SingleOrNullSelectable<FeedArticle> getArticleById(String articleId) {
|
||||
return db.article.select()..where((row) => row.id.equals(articleId));
|
||||
}
|
||||
|
||||
Future<void> upsertArticles(List<FeedArticle> articles) {
|
||||
return db.transaction(() async {
|
||||
await Future.wait(
|
||||
articles
|
||||
.map(
|
||||
(article) => db.article.insertOne(
|
||||
article,
|
||||
onConflict: DoUpdate(
|
||||
(old) {
|
||||
return ArticleCompanion(
|
||||
authors: Value(article.authors),
|
||||
contentMarkdown: Value(article.contentMarkdown),
|
||||
contentPlain: Value(article.contentPlain),
|
||||
links: Value(article.links),
|
||||
summaryMarkdown: Value(article.summaryMarkdown),
|
||||
summaryPlain: Value(article.summaryPlain),
|
||||
tags: Value(article.tags),
|
||||
title: Value(article.title),
|
||||
updated: Value(article.updated),
|
||||
);
|
||||
},
|
||||
where:
|
||||
(old) =>
|
||||
old.updated.isNotNull() &
|
||||
old.updated.isSmallerThanValue(
|
||||
article.updated ?? DateTime(0),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<int> updateArticleRead(String articleId, DateTime? read) {
|
||||
final statement =
|
||||
db.article.update()..where((article) => article.id.equals(articleId));
|
||||
|
||||
return statement.write(ArticleCompanion(lastRead: Value(read)));
|
||||
}
|
||||
|
||||
Selectable<(String, int)> getUnreadArticleCount() {
|
||||
final count = countAll();
|
||||
|
||||
final countByFeed =
|
||||
db.article.selectOnly()
|
||||
..addColumns([db.article.feedId, count])
|
||||
..where(
|
||||
db.article.lastRead.isNull() |
|
||||
(db.article.updated.isNotNull() &
|
||||
db.article.lastRead.isSmallerThan(db.article.lastRead)),
|
||||
)
|
||||
..groupBy([db.article.feedId]);
|
||||
|
||||
return countByFeed.map(
|
||||
(result) => (result.read(db.article.feedId)!, result.read(count)!),
|
||||
);
|
||||
}
|
||||
|
||||
Selectable<FeedArticleQueryResult> queryArticles({
|
||||
required String matchPrefix,
|
||||
required String matchSuffix,
|
||||
required String ellipsis,
|
||||
required int snippetLength,
|
||||
required String searchString,
|
||||
required Uri? feedId,
|
||||
}) {
|
||||
final ftsQuery = db.buildFtsQuery(searchString);
|
||||
|
||||
if (ftsQuery.isNotEmpty) {
|
||||
return db.queryArticlesFullContent(
|
||||
feedId: feedId?.toString(),
|
||||
query: ftsQuery,
|
||||
snippetLength: snippetLength,
|
||||
beforeMatch: matchPrefix,
|
||||
afterMatch: matchSuffix,
|
||||
ellipsis: ellipsis,
|
||||
);
|
||||
} else {
|
||||
return db.queryArticlesBasic(
|
||||
feedId: feedId?.toString(),
|
||||
query: db.buildLikeQuery(searchString),
|
||||
beforeMatch: matchPrefix,
|
||||
afterMatch: matchSuffix,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'article.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
mixin _$ArticleDaoMixin on DatabaseAccessor<FeedDatabase> {}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/database.dart';
|
||||
|
||||
part 'feed.g.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class FeedDao extends DatabaseAccessor<FeedDatabase> with _$FeedDaoMixin {
|
||||
FeedDao(super.attachedDatabase);
|
||||
|
||||
Selectable<FeedData> getFeeds() {
|
||||
return db.feed.select();
|
||||
}
|
||||
|
||||
Future<int> updateFeedFetched(Uri url, DateTime fetched) {
|
||||
final statement =
|
||||
db.feed.update()..where((feed) => feed.url.equalsValue(url));
|
||||
|
||||
return statement.write(FeedCompanion(lastFetched: Value(fetched)));
|
||||
}
|
||||
|
||||
Future<int> deleteFeed(Uri url) {
|
||||
return db.feed.deleteWhere((feed) => feed.url.equals(url.toString()));
|
||||
}
|
||||
|
||||
Future<int> upsertFeed(FeedData feedData) {
|
||||
return db.feed.insertOne(
|
||||
feedData,
|
||||
onConflict: DoUpdate((old) {
|
||||
return FeedCompanion(
|
||||
authors: Value(feedData.authors),
|
||||
title: Value(feedData.title),
|
||||
description: Value(feedData.description),
|
||||
tags: Value(feedData.tags),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
mixin _$FeedDaoMixin on DatabaseAccessor<FeedDatabase> {}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:lensai/data/database/converters/uri.dart';
|
||||
import 'package:lensai/features/search/domain/fts_tokenizer.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/converters/feed_authors.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/converters/feed_categories.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/converters/feed_links.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/daos/article.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/daos/feed.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_article.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_article_query_result.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_author.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_category.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_link.dart';
|
||||
|
||||
part 'database.g.dart';
|
||||
|
||||
@DriftDatabase(include: {'database.drift'}, daos: [ArticleDao, FeedDao])
|
||||
class FeedDatabase extends _$FeedDatabase with TrigramQueryBuilderMixin {
|
||||
@override
|
||||
final int schemaVersion = 1;
|
||||
|
||||
@override
|
||||
final int ftsTokenLimit = 10;
|
||||
@override
|
||||
final int ftsMinTokenLength = 3;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
beforeOpen: (details) async {
|
||||
await customStatement('PRAGMA foreign_keys = ON;');
|
||||
await optimizeFtsIndex();
|
||||
},
|
||||
);
|
||||
|
||||
FeedDatabase(super.e);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import 'package:lensai/data/database/converters/uri.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_article_query_result.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/converters/feed_authors.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/converters/feed_categories.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/converters/feed_links.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_article.dart';
|
||||
|
||||
CREATE TABLE feed (
|
||||
url TEXT PRIMARY KEY NOT NULL MAPPED BY `const UriConverter()`,
|
||||
title TEXT,
|
||||
description TEXT,
|
||||
authors TEXT MAPPED BY `const FeedAuthorsConverter()`,
|
||||
tags TEXT MAPPED BY `const FeedCategoriesConverter()`,
|
||||
last_fetched DATETIME
|
||||
);
|
||||
|
||||
CREATE TABLE article (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
feed_id TEXT NOT NULL MAPPED BY `const UriConverter()` REFERENCES feed ("url") ON DELETE CASCADE,
|
||||
fetched DATETIME NOT NULL,
|
||||
created DATETIME,
|
||||
updated DATETIME,
|
||||
last_read DATETIME,
|
||||
title TEXT,
|
||||
authors TEXT MAPPED BY `const FeedAuthorsConverter()`,
|
||||
tags TEXT MAPPED BY `const FeedCategoriesConverter()`,
|
||||
links TEXT MAPPED BY `const FeedLinksConverter()`,
|
||||
summaryMarkdown TEXT,
|
||||
summaryPlain TEXT,
|
||||
contentMarkdown TEXT,
|
||||
contentPlain TEXT
|
||||
) WITH FeedArticle;
|
||||
|
||||
CREATE INDEX article_feed_id ON article (feed_id);
|
||||
|
||||
CREATE VIRTUAL TABLE article_fts
|
||||
USING fts5(
|
||||
title,
|
||||
summaryPlain,
|
||||
contentPlain,
|
||||
content=article,
|
||||
tokenize="trigram"
|
||||
);
|
||||
|
||||
-- Triggers to keep the FTS index up to date.
|
||||
CREATE TRIGGER article_after_insert AFTER INSERT ON article BEGIN
|
||||
INSERT INTO
|
||||
article_fts(rowid, title, summaryPlain, contentPlain)
|
||||
VALUES (new.rowid, new.title, new.summaryPlain, new.contentPlain);
|
||||
END;
|
||||
CREATE TRIGGER article_after_delete AFTER DELETE ON article BEGIN
|
||||
INSERT INTO
|
||||
article_fts(article_fts, rowid, title, summaryPlain, contentPlain)
|
||||
VALUES('delete', old.rowid, old.title, old.summaryPlain, old.contentPlain);
|
||||
END;
|
||||
CREATE TRIGGER article_after_update AFTER UPDATE ON article BEGIN
|
||||
INSERT INTO
|
||||
article_fts(article_fts, rowid, title, summaryPlain, contentPlain)
|
||||
VALUES('delete', old.rowid, old.title, old.summaryPlain, old.contentPlain);
|
||||
INSERT INTO
|
||||
article_fts(rowid, title, summaryPlain, contentPlain)
|
||||
VALUES (new.rowid, new.title, new.summaryPlain, new.contentPlain);
|
||||
END;
|
||||
|
||||
optimizeFtsIndex:
|
||||
INSERT INTO article_fts(article_fts) VALUES ('optimize');
|
||||
|
||||
queryArticlesBasic(:feed_id AS TEXT OR NULL) WITH FeedArticleQueryResult:
|
||||
WITH weights AS (
|
||||
SELECT
|
||||
-- Customize these weights (higher = more important)
|
||||
1.0 as title_weight -- Title matches are most important
|
||||
)
|
||||
SELECT
|
||||
a.*,
|
||||
highlight(article_fts, 0, :beforeMatch, :afterMatch) AS title,
|
||||
(
|
||||
bm25(article_fts, weights.title_weight)
|
||||
) AS weighted_rank
|
||||
FROM article_fts(:query) fts
|
||||
INNER JOIN
|
||||
article a ON a.rowid = fts.rowid
|
||||
CROSS JOIN weights
|
||||
WHERE
|
||||
fts.title LIKE :query AND
|
||||
:feed_id IS NULL OR a.feed_id = :feed_id
|
||||
ORDER BY
|
||||
weighted_rank ASC,
|
||||
a.created DESC NULLS LAST;
|
||||
|
||||
queryArticlesFullContent(:feed_id AS TEXT OR NULL) WITH FeedArticleQueryResult:
|
||||
WITH weights AS (
|
||||
SELECT
|
||||
-- Customize these weights (higher = more important)
|
||||
5.0 as title_weight, -- Title matches are most important
|
||||
2.0 as summary_weight, -- Summary matches are quite important
|
||||
1.0 as content_weight -- Content matches are basic
|
||||
)
|
||||
SELECT
|
||||
a.*,
|
||||
highlight(article_fts, 0, :beforeMatch, :afterMatch) AS title,
|
||||
snippet(article_fts, 1, :beforeMatch, :afterMatch, :ellipsis, :snippetLength) AS summary,
|
||||
snippet(article_fts, 2, :beforeMatch, :afterMatch, :ellipsis, :snippetLength) AS content,
|
||||
(
|
||||
bm25(article_fts, weights.title_weight, weights.summary_weight,
|
||||
weights.content_weight)
|
||||
) AS weighted_rank
|
||||
FROM article_fts(:query) fts
|
||||
INNER JOIN
|
||||
article a ON a.rowid = fts.rowid
|
||||
CROSS JOIN weights
|
||||
WHERE
|
||||
:feed_id IS NULL OR a.feed_id = :feed_id
|
||||
ORDER BY
|
||||
weighted_rank ASC,
|
||||
a.created DESC NULLS LAST;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,116 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/database.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_author.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_category.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_link.dart';
|
||||
|
||||
part 'feed_article.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class FeedArticle with FastEquatable implements Insertable<FeedArticle> {
|
||||
final String id;
|
||||
final Uri feedId;
|
||||
final DateTime fetched;
|
||||
final DateTime? created;
|
||||
final DateTime? updated;
|
||||
final DateTime? lastRead;
|
||||
final String? title;
|
||||
final List<FeedAuthor>? authors;
|
||||
final List<FeedCategory>? tags;
|
||||
final List<FeedLink>? links;
|
||||
final String? summaryMarkdown;
|
||||
final String? summaryPlain;
|
||||
final String? contentMarkdown;
|
||||
final String? contentPlain;
|
||||
|
||||
FeedArticle({
|
||||
required this.id,
|
||||
required this.feedId,
|
||||
required this.fetched,
|
||||
this.created,
|
||||
this.updated,
|
||||
this.lastRead,
|
||||
this.title,
|
||||
this.authors,
|
||||
this.tags,
|
||||
this.links,
|
||||
this.summaryMarkdown,
|
||||
this.summaryPlain,
|
||||
this.contentMarkdown,
|
||||
this.contentPlain,
|
||||
});
|
||||
|
||||
factory FeedArticle.fromJson(Map<String, dynamic> json) =>
|
||||
_$FeedArticleFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FeedArticleToJson(this);
|
||||
|
||||
@override
|
||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, Expression>{};
|
||||
map['id'] = Variable<String>(id);
|
||||
{
|
||||
map['feed_id'] = Variable<String>(Article.$converterfeedId.toSql(feedId));
|
||||
}
|
||||
map['fetched'] = Variable<DateTime>(fetched);
|
||||
if (!nullToAbsent || created != null) {
|
||||
map['created'] = Variable<DateTime>(created);
|
||||
}
|
||||
if (!nullToAbsent || updated != null) {
|
||||
map['updated'] = Variable<DateTime>(updated);
|
||||
}
|
||||
if (!nullToAbsent || lastRead != null) {
|
||||
map['last_read'] = Variable<DateTime>(lastRead);
|
||||
}
|
||||
if (!nullToAbsent || title != null) {
|
||||
map['title'] = Variable<String>(title);
|
||||
}
|
||||
if (!nullToAbsent || authors != null) {
|
||||
map['authors'] = Variable<String>(
|
||||
Article.$converterauthorsn.toSql(authors),
|
||||
);
|
||||
}
|
||||
if (!nullToAbsent || tags != null) {
|
||||
map['tags'] = Variable<String>(Article.$convertertagsn.toSql(tags));
|
||||
}
|
||||
if (!nullToAbsent || links != null) {
|
||||
map['links'] = Variable<String>(Article.$converterlinksn.toSql(links));
|
||||
}
|
||||
if (!nullToAbsent || summaryMarkdown != null) {
|
||||
map['summaryMarkdown'] = Variable<String>(summaryMarkdown);
|
||||
}
|
||||
if (!nullToAbsent || summaryPlain != null) {
|
||||
map['summaryPlain'] = Variable<String>(summaryPlain);
|
||||
}
|
||||
if (!nullToAbsent || contentMarkdown != null) {
|
||||
map['contentMarkdown'] = Variable<String>(contentMarkdown);
|
||||
}
|
||||
if (!nullToAbsent || contentPlain != null) {
|
||||
map['contentPlain'] = Variable<String>(contentPlain);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
id,
|
||||
feedId,
|
||||
fetched,
|
||||
created,
|
||||
updated,
|
||||
lastRead,
|
||||
title,
|
||||
authors,
|
||||
tags,
|
||||
links,
|
||||
summaryMarkdown,
|
||||
summaryPlain,
|
||||
contentMarkdown,
|
||||
contentPlain,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_article.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FeedArticle _$FeedArticleFromJson(Map<String, dynamic> json) => FeedArticle(
|
||||
id: json['id'] as String,
|
||||
feedId: Uri.parse(json['feedId'] as String),
|
||||
fetched: DateTime.parse(json['fetched'] as String),
|
||||
created:
|
||||
json['created'] == null
|
||||
? null
|
||||
: DateTime.parse(json['created'] as String),
|
||||
updated:
|
||||
json['updated'] == null
|
||||
? null
|
||||
: DateTime.parse(json['updated'] as String),
|
||||
lastRead:
|
||||
json['lastRead'] == null
|
||||
? null
|
||||
: DateTime.parse(json['lastRead'] as String),
|
||||
title: json['title'] as String?,
|
||||
authors:
|
||||
(json['authors'] as List<dynamic>?)
|
||||
?.map((e) => FeedAuthor.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
tags:
|
||||
(json['tags'] as List<dynamic>?)
|
||||
?.map((e) => FeedCategory.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
links:
|
||||
(json['links'] as List<dynamic>?)
|
||||
?.map((e) => FeedLink.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
summaryMarkdown: json['summaryMarkdown'] as String?,
|
||||
summaryPlain: json['summaryPlain'] as String?,
|
||||
contentMarkdown: json['contentMarkdown'] as String?,
|
||||
contentPlain: json['contentPlain'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FeedArticleToJson(FeedArticle instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'feedId': instance.feedId.toString(),
|
||||
'fetched': instance.fetched.toIso8601String(),
|
||||
'created': instance.created?.toIso8601String(),
|
||||
'updated': instance.updated?.toIso8601String(),
|
||||
'lastRead': instance.lastRead?.toIso8601String(),
|
||||
'title': instance.title,
|
||||
'authors': instance.authors?.map((e) => e.toJson()).toList(),
|
||||
'tags': instance.tags?.map((e) => e.toJson()).toList(),
|
||||
'links': instance.links?.map((e) => e.toJson()).toList(),
|
||||
'summaryMarkdown': instance.summaryMarkdown,
|
||||
'summaryPlain': instance.summaryPlain,
|
||||
'contentMarkdown': instance.contentMarkdown,
|
||||
'contentPlain': instance.contentPlain,
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:lensai/features/web_feed/data/models/feed_article.dart';
|
||||
|
||||
class FeedArticleQueryResult extends FeedArticle {
|
||||
final double weightedRank;
|
||||
|
||||
FeedArticleQueryResult({
|
||||
required super.id,
|
||||
required super.feedId,
|
||||
required super.fetched,
|
||||
required this.weightedRank,
|
||||
super.created,
|
||||
super.updated,
|
||||
super.lastRead,
|
||||
super.title,
|
||||
super.authors,
|
||||
super.tags,
|
||||
super.links,
|
||||
super.summaryMarkdown,
|
||||
super.summaryPlain,
|
||||
super.contentMarkdown,
|
||||
super.contentPlain,
|
||||
});
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [...super.hashParameters, weightedRank];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'feed_author.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class FeedAuthor with FastEquatable {
|
||||
final String? name;
|
||||
final String? email;
|
||||
|
||||
FeedAuthor({this.name, this.email});
|
||||
|
||||
factory FeedAuthor.fromJson(Map<String, dynamic> json) =>
|
||||
_$FeedAuthorFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FeedAuthorToJson(this);
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [name, email];
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_author.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FeedAuthor _$FeedAuthorFromJson(Map<String, dynamic> json) =>
|
||||
FeedAuthor(name: json['name'] as String?, email: json['email'] as String?);
|
||||
|
||||
Map<String, dynamic> _$FeedAuthorToJson(FeedAuthor instance) =>
|
||||
<String, dynamic>{'name': instance.name, 'email': instance.email};
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'feed_category.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class FeedCategory with FastEquatable {
|
||||
final String id;
|
||||
final String? title;
|
||||
|
||||
FeedCategory({required this.id, this.title});
|
||||
|
||||
factory FeedCategory.fromJson(Map<String, dynamic> json) =>
|
||||
_$FeedCategoryFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FeedCategoryToJson(this);
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [id, title];
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_category.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FeedCategory _$FeedCategoryFromJson(Map<String, dynamic> json) =>
|
||||
FeedCategory(id: json['id'] as String, title: json['title'] as String?);
|
||||
|
||||
Map<String, dynamic> _$FeedCategoryToJson(FeedCategory instance) =>
|
||||
<String, dynamic>{'id': instance.id, 'title': instance.title};
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
|
||||
part 'feed_filter.g.dart';
|
||||
|
||||
@CopyWith()
|
||||
class FeedFilter with FastEquatable {
|
||||
final Uri? feedId;
|
||||
final String? query;
|
||||
final Set<String>? tags;
|
||||
|
||||
FeedFilter({this.feedId, this.query, this.tags});
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [feedId, query, tags];
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_filter.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// CopyWithGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class _$FeedFilterCWProxy {
|
||||
FeedFilter feedId(Uri? feedId);
|
||||
|
||||
FeedFilter query(String? query);
|
||||
|
||||
FeedFilter tags(Set<String>? tags);
|
||||
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FeedFilter(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
/// Usage
|
||||
/// ```dart
|
||||
/// FeedFilter(...).copyWith(id: 12, name: "My name")
|
||||
/// ````
|
||||
FeedFilter call({Uri? feedId, String? query, Set<String>? tags});
|
||||
}
|
||||
|
||||
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfFeedFilter.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfFeedFilter.copyWith.fieldName(...)`
|
||||
class _$FeedFilterCWProxyImpl implements _$FeedFilterCWProxy {
|
||||
const _$FeedFilterCWProxyImpl(this._value);
|
||||
|
||||
final FeedFilter _value;
|
||||
|
||||
@override
|
||||
FeedFilter feedId(Uri? feedId) => this(feedId: feedId);
|
||||
|
||||
@override
|
||||
FeedFilter query(String? query) => this(query: query);
|
||||
|
||||
@override
|
||||
FeedFilter tags(Set<String>? tags) => this(tags: tags);
|
||||
|
||||
@override
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FeedFilter(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
/// Usage
|
||||
/// ```dart
|
||||
/// FeedFilter(...).copyWith(id: 12, name: "My name")
|
||||
/// ````
|
||||
FeedFilter call({
|
||||
Object? feedId = const $CopyWithPlaceholder(),
|
||||
Object? query = const $CopyWithPlaceholder(),
|
||||
Object? tags = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return FeedFilter(
|
||||
feedId:
|
||||
feedId == const $CopyWithPlaceholder()
|
||||
? _value.feedId
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: feedId as Uri?,
|
||||
query:
|
||||
query == const $CopyWithPlaceholder()
|
||||
? _value.query
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: query as String?,
|
||||
tags:
|
||||
tags == const $CopyWithPlaceholder()
|
||||
? _value.tags
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: tags as Set<String>?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension $FeedFilterCopyWith on FeedFilter {
|
||||
/// Returns a callable class that can be used as follows: `instanceOfFeedFilter.copyWith(...)` or like so:`instanceOfFeedFilter.copyWith.fieldName(...)`.
|
||||
// ignore: library_private_types_in_public_api
|
||||
_$FeedFilterCWProxy get copyWith => _$FeedFilterCWProxyImpl(this);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'feed_link.g.dart';
|
||||
|
||||
enum FeedLinkRelation {
|
||||
///an alternate representation of the entry or feed, for example a permalink to the html version of the entry, or the front page of the weblog.
|
||||
alternate,
|
||||
|
||||
///a related resource which is potentially large in size and might require special handling, for example an audio or video recording.
|
||||
enclosure,
|
||||
|
||||
///an document related to the entry or feed.
|
||||
related,
|
||||
|
||||
///the feed itself.
|
||||
self,
|
||||
|
||||
///the source of the information provided in the entry.
|
||||
via,
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class FeedLink with FastEquatable {
|
||||
final Uri uri;
|
||||
final FeedLinkRelation? relation;
|
||||
final String? title;
|
||||
|
||||
FeedLink({required this.uri, this.relation, this.title});
|
||||
|
||||
factory FeedLink.fromJson(Map<String, dynamic> json) =>
|
||||
_$FeedLinkFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FeedLinkToJson(this);
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [uri, relation, title];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_link.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FeedLink _$FeedLinkFromJson(Map<String, dynamic> json) => FeedLink(
|
||||
uri: Uri.parse(json['uri'] as String),
|
||||
relation: $enumDecodeNullable(_$FeedLinkRelationEnumMap, json['relation']),
|
||||
title: json['title'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FeedLinkToJson(FeedLink instance) => <String, dynamic>{
|
||||
'uri': instance.uri.toString(),
|
||||
'relation': _$FeedLinkRelationEnumMap[instance.relation],
|
||||
'title': instance.title,
|
||||
};
|
||||
|
||||
const _$FeedLinkRelationEnumMap = {
|
||||
FeedLinkRelation.alternate: 'alternate',
|
||||
FeedLinkRelation.enclosure: 'enclosure',
|
||||
FeedLinkRelation.related: 'related',
|
||||
FeedLinkRelation.self: 'self',
|
||||
FeedLinkRelation.via: 'via',
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/converters/feed_data.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/database.dart';
|
||||
import 'package:lensai/features/web_feed/data/models/feed_article.dart';
|
||||
|
||||
part 'feed_parse_result.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class FeedParseResult {
|
||||
@FeedDataConverter()
|
||||
final FeedData feedData;
|
||||
final List<FeedArticle> articleData;
|
||||
|
||||
FeedParseResult({required this.feedData, required this.articleData});
|
||||
|
||||
factory FeedParseResult.fromJson(Map<String, dynamic> json) =>
|
||||
_$FeedParseResultFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FeedParseResultToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_parse_result.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FeedParseResult _$FeedParseResultFromJson(Map<String, dynamic> json) =>
|
||||
FeedParseResult(
|
||||
feedData: const FeedDataConverter().fromJson(
|
||||
json['feedData'] as Map<String, dynamic>,
|
||||
),
|
||||
articleData:
|
||||
(json['articleData'] as List<dynamic>)
|
||||
.map((e) => FeedArticle.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FeedParseResultToJson(FeedParseResult instance) =>
|
||||
<String, dynamic>{
|
||||
'feedData': const FeedDataConverter().toJson(instance.feedData),
|
||||
'articleData': instance.articleData.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/features/web_feed/data/database/database.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart' as path_provider;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
import 'package:sqlite3_flutter_libs/sqlite3_flutter_libs.dart';
|
||||
|
||||
part 'providers.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
FeedDatabase feedDatabase(Ref ref) {
|
||||
final db = FeedDatabase(
|
||||
LazyDatabase(() async {
|
||||
// put the database file, called db.sqlite here, into the documents folder
|
||||
// for your app.
|
||||
final dbFolder = await path_provider.getApplicationDocumentsDirectory();
|
||||
final file = File(p.join(dbFolder.path, 'feed.db'));
|
||||
|
||||
// Also work around limitations on old Android versions
|
||||
if (Platform.isAndroid) {
|
||||
await applyWorkaroundToOpenSqlite3OnOldAndroidVersions();
|
||||
}
|
||||
|
||||
// Make sqlite3 pick a more suitable location for temporary files - the
|
||||
// one from the system may be inaccessible due to sandboxing.
|
||||
final cachebase = (await path_provider.getTemporaryDirectory()).path;
|
||||
// We can't access /tmp on Android, which sqlite3 would try by default.
|
||||
// Explicitly tell it about the correct temporary directory.
|
||||
sqlite3.tempDirectory = cachebase;
|
||||
|
||||
return NativeDatabase.createInBackground(file);
|
||||
}),
|
||||
);
|
||||
|
||||
ref.onDispose(() {
|
||||
unawaited(db.close());
|
||||
});
|
||||
|
||||
return db;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'providers.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$feedDatabaseHash() => r'a4a1ffa36b73c2aecbe17bf096e30fa9b9ad23c9';
|
||||
|
||||
/// See also [feedDatabase].
|
||||
@ProviderFor(feedDatabase)
|
||||
final feedDatabaseProvider = Provider<FeedDatabase>.internal(
|
||||
feedDatabase,
|
||||
name: r'feedDatabaseProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$feedDatabaseHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef FeedDatabaseRef = ProviderRef<FeedDatabase>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
||||
Reference in New Issue
Block a user