small web feature initial
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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:drift/drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_item_dao.drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/kagi_small_web_mode.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/small_web_source_kind.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class SmallWebItemDao extends DatabaseAccessor<SmallWebDatabase>
|
||||
with $SmallWebItemDaoMixin {
|
||||
SmallWebItemDao(super.attachedDatabase);
|
||||
|
||||
SingleOrNullSelectable<DateTime?> getLatestFetchedAt(
|
||||
SmallWebSourceKind sourceKind,
|
||||
KagiSmallWebMode? mode,
|
||||
) {
|
||||
final query = selectOnly(db.smallWebMemberships)
|
||||
..addColumns([db.smallWebMemberships.fetchedAt])
|
||||
..where(
|
||||
db.smallWebMemberships.sourceKind.equalsValue(sourceKind) &
|
||||
(mode == null
|
||||
? db.smallWebMemberships.mode.isNull()
|
||||
: db.smallWebMemberships.mode.equals(mode.name)),
|
||||
)
|
||||
..orderBy([
|
||||
OrderingTerm(
|
||||
expression: db.smallWebMemberships.fetchedAt,
|
||||
mode: OrderingMode.desc,
|
||||
),
|
||||
])
|
||||
..limit(1);
|
||||
|
||||
return query.map((row) => row.read(db.smallWebMemberships.fetchedAt));
|
||||
}
|
||||
|
||||
Selectable<SmallWebItem> getDiscoverableKagiItems(
|
||||
KagiSmallWebMode mode,
|
||||
String? category,
|
||||
) {
|
||||
return db.definitionsDrift.getDiscoverableKagiItems(
|
||||
sourceKind: SmallWebSourceKind.kagi,
|
||||
mode: mode.name,
|
||||
category: category,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> updateTitle(String id, String title) {
|
||||
return (db.smallWebItems.update()..where((i) => i.id.equals(id))).write(
|
||||
SmallWebItemsCompanion(
|
||||
title: Value(title),
|
||||
updatedAt: Value(DateTime.now()),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart' as i1;
|
||||
|
||||
mixin $SmallWebItemDaoMixin on i0.DatabaseAccessor<i1.SmallWebDatabase> {
|
||||
SmallWebItemDaoManager get managers => SmallWebItemDaoManager(this);
|
||||
}
|
||||
|
||||
class SmallWebItemDaoManager {
|
||||
final $SmallWebItemDaoMixin _db;
|
||||
SmallWebItemDaoManager(this._db);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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:drift/drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_visit_dao.drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/kagi_small_web_mode.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/small_web_source_kind.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class SmallWebVisitDao extends DatabaseAccessor<SmallWebDatabase>
|
||||
with $SmallWebVisitDaoMixin {
|
||||
SmallWebVisitDao(super.attachedDatabase);
|
||||
|
||||
Future<void> insertVisit(SmallWebVisit visit) {
|
||||
return db.smallWebVisits.insertOne(visit);
|
||||
}
|
||||
|
||||
Selectable<GetRecentVisitsResult> getRecentVisits({
|
||||
required SmallWebSourceKind sourceKind,
|
||||
required KagiSmallWebMode? mode,
|
||||
int limit = 50,
|
||||
}) {
|
||||
return db.definitionsDrift.getRecentVisits(
|
||||
sourceKind: sourceKind,
|
||||
mode: mode?.name,
|
||||
limit: limit,
|
||||
);
|
||||
}
|
||||
|
||||
Selectable<String> getRecentItemIds({
|
||||
required SmallWebSourceKind sourceKind,
|
||||
required KagiSmallWebMode? mode,
|
||||
int limit = 20,
|
||||
}) {
|
||||
return db.definitionsDrift.getRecentVisitItemIds(
|
||||
sourceKind: sourceKind,
|
||||
mode: mode?.name,
|
||||
limit: limit,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteVisitById(String visitId) {
|
||||
return (db.delete(
|
||||
db.smallWebVisits,
|
||||
)..where((t) => t.id.equals(visitId))).go();
|
||||
}
|
||||
|
||||
Future<void> deleteVisitsBySourceAndMode({
|
||||
required SmallWebSourceKind sourceKind,
|
||||
required KagiSmallWebMode? mode,
|
||||
}) {
|
||||
return (db.delete(db.smallWebVisits)..where(
|
||||
(t) =>
|
||||
t.sourceKind.equalsValue(sourceKind) &
|
||||
(mode == null ? t.mode.isNull() : t.mode.equals(mode.name)),
|
||||
))
|
||||
.go();
|
||||
}
|
||||
|
||||
Future<void> deleteAllVisits() {
|
||||
return db.delete(db.smallWebVisits).go();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart' as i1;
|
||||
|
||||
mixin $SmallWebVisitDaoMixin on i0.DatabaseAccessor<i1.SmallWebDatabase> {
|
||||
SmallWebVisitDaoManager get managers => SmallWebVisitDaoManager(this);
|
||||
}
|
||||
|
||||
class SmallWebVisitDaoManager {
|
||||
final $SmallWebVisitDaoMixin _db;
|
||||
SmallWebVisitDaoManager(this._db);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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:drift/drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/wander_console_dao.drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/definitions.drift.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class WanderConsoleDao extends DatabaseAccessor<SmallWebDatabase>
|
||||
with $WanderConsoleDaoMixin {
|
||||
WanderConsoleDao(super.attachedDatabase);
|
||||
|
||||
Future<void> upsertConsole(WanderConsole console) {
|
||||
return db.wanderConsoles.insertOne(
|
||||
console,
|
||||
onConflict: DoUpdate(
|
||||
(old) => WanderConsolesCompanion(
|
||||
lastFetchedAt: Value(console.lastFetchedAt),
|
||||
lastFetchFailed: Value(console.lastFetchFailed),
|
||||
),
|
||||
target: [db.wanderConsoles.url],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
SingleOrNullSelectable<WanderConsole?> getConsole(Uri url) {
|
||||
return (db.wanderConsoles.select()..where((c) => c.url.equalsValue(url)));
|
||||
}
|
||||
|
||||
Selectable<Uri> getExistingConsoleUrls(List<Uri> urls) {
|
||||
final query = selectOnly(db.wanderConsoles)
|
||||
..addColumns([db.wanderConsoles.url])
|
||||
..where(db.wanderConsoles.url.isInValues(urls));
|
||||
|
||||
return query.map((row) => row.readWithConverter(db.wanderConsoles.url)!);
|
||||
}
|
||||
|
||||
Selectable<Uri> getDiscoveredConsoleUrls({int limit = 1000}) {
|
||||
return db.definitionsDrift.getDiscoveredConsoleUrls(limit: limit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart' as i1;
|
||||
|
||||
mixin $WanderConsoleDaoMixin on i0.DatabaseAccessor<i1.SmallWebDatabase> {
|
||||
WanderConsoleDaoManager get managers => WanderConsoleDaoManager(this);
|
||||
}
|
||||
|
||||
class WanderConsoleDaoManager {
|
||||
final $WanderConsoleDaoMixin _db;
|
||||
WanderConsoleDaoManager(this._db);
|
||||
}
|
||||
Reference in New Issue
Block a user