prepare for multiple apps

This commit is contained in:
Fabian Freund
2026-04-06 12:23:11 +02:00
parent bd1600e8dc
commit 5afc323f04
904 changed files with 29 additions and 29 deletions
@@ -0,0 +1,82 @@
/*
* 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:nullability/nullability.dart';
import 'package:rss_dart/dart_rss.dart';
import 'package:weblibre/features/web_feed/data/models/feed_author.dart';
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
extension ParseAtomLink on List<AtomLink> {
List<FeedLink> toFeedLinks() {
return map((link) {
final uri = link.href.mapNotNull(Uri.tryParse);
if (uri == null) {
return null;
}
final relation = link.rel.mapNotNull(
(rel) => FeedLinkRelation.values.firstWhereOrNull((e) => e.name == rel),
);
return FeedLink(
uri: uri,
relation: relation,
title: link.title.whenNotEmpty,
);
}).nonNulls.toList();
}
}
extension SelectFeedLink on List<FeedLink> {
FeedLink? getRelation(FeedLinkRelation? relation) {
return firstWhereOrNull((link) => link.relation == relation);
}
}
extension ParseAtomCategory on List<AtomCategory> {
List<FeedCategory> toFeedCategories() {
return where((category) => category.term.isNotEmpty)
.map(
(category) => FeedCategory(
id: category.term!,
title: category.label.whenNotEmpty,
),
)
.toList();
}
}
extension ParseAtomPerson on List<AtomPerson> {
List<FeedAuthor> toFeedAuthors() {
return where(
(author) =>
author.name.whenNotEmpty != null ||
author.email.whenNotEmpty != null,
)
.map(
(author) => FeedAuthor(
name: author.name.whenNotEmpty,
email: author.email.whenNotEmpty,
),
)
.toList();
}
}
@@ -0,0 +1,34 @@
/*
* 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:nullability/nullability.dart';
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
import 'package:weblibre/features/web_feed/extensions/atom.dart';
extension FeedArticleX on FeedArticle {
String get displayTitle =>
title ??
links
?.getRelation(FeedLinkRelation.alternate)
.mapNotNull(
(link) => link.title.whenNotEmpty ?? link.uri.toString(),
) ??
'Unnamed Article';
}
@@ -0,0 +1,44 @@
/*
* 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:nullability/nullability.dart';
import 'package:rss_dart/dart_rss.dart';
import 'package:rss_dart/domain/dublin_core/dublin_core.dart';
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
extension ParseDublinCategory on DublinCore {
List<FeedCategory> toFeedCategories() {
return subjects
.where((subject) => subject.isNotEmpty)
.map((subject) => FeedCategory(id: subject))
.toList();
}
}
extension ParseRssCategory on List<RssCategory> {
List<FeedCategory> toFeedCategories() {
return where((category) => category.value.isNotEmpty)
.map(
(category) => FeedCategory(
id: '${category.domain ?? ''} ${category.value ?? ''}'.trim(),
),
)
.toList();
}
}
@@ -0,0 +1,64 @@
/*
* 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:rss_dart/dart_rss.dart';
extension WebFeedJson on WebFeed {
Map<String, dynamic> toJson() {
return {
'title': title,
'description': description,
'links': links.where((link) => link != null).toList(),
'items': items.map((item) => item.toJson()).toList(),
};
}
static WebFeed fromJson(Map<String, dynamic> json) {
return WebFeed(
title: json['title'] as String,
description: json['description'] as String,
links: (json['links'] as List).cast<String?>(),
items: (json['items'] as List)
.map((item) => WebFeedItemJson.fromJson(item as Map<String, dynamic>))
.toList(),
);
}
}
extension WebFeedItemJson on WebFeedItem {
Map<String, dynamic> toJson() {
return {
'title': title,
'body': body,
'links': links.where((link) => link != null).toList(),
'updated': updated?.toIso8601String(),
};
}
static WebFeedItem fromJson(Map<String, dynamic> json) {
return WebFeedItem(
title: json['title'] as String,
body: json['body'] as String,
links: (json['links'] as List).cast<String?>(),
updated: json['updated'] != null
? DateTime.parse(json['updated'] as String)
: null,
);
}
}