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);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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:drift_dev/api/migrations_native.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_item_dao.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_visit_dao.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/wander_console_dao.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/database.drift.dart';
|
||||
|
||||
@DriftDatabase(
|
||||
include: {'definitions.drift'},
|
||||
daos: [SmallWebItemDao, SmallWebVisitDao, WanderConsoleDao],
|
||||
)
|
||||
class SmallWebDatabase extends $SmallWebDatabase {
|
||||
SmallWebDatabase(super.e);
|
||||
|
||||
@override
|
||||
int get schemaVersion => 1;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
beforeOpen: (details) async {
|
||||
if (kDebugMode) {
|
||||
await validateDatabaseSchema();
|
||||
}
|
||||
await customStatement('PRAGMA foreign_keys = ON;');
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/small_web/data/database/definitions.drift.dart'
|
||||
as i1;
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_item_dao.dart'
|
||||
as i2;
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart' as i3;
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_visit_dao.dart'
|
||||
as i4;
|
||||
import 'package:weblibre/features/small_web/data/database/daos/wander_console_dao.dart'
|
||||
as i5;
|
||||
import 'package:drift/internal/modular.dart' as i6;
|
||||
import 'package:sqlite3/common.dart' as i7;
|
||||
|
||||
abstract class $SmallWebDatabase extends i0.GeneratedDatabase {
|
||||
$SmallWebDatabase(i0.QueryExecutor e) : super(e);
|
||||
$SmallWebDatabaseManager get managers => $SmallWebDatabaseManager(this);
|
||||
late final i1.SmallWebItems smallWebItems = i1.SmallWebItems(this);
|
||||
late final i1.SmallWebMemberships smallWebMemberships =
|
||||
i1.SmallWebMemberships(this);
|
||||
late final i1.WanderConsoles wanderConsoles = i1.WanderConsoles(this);
|
||||
late final i1.WanderConsoleNeighbors wanderConsoleNeighbors =
|
||||
i1.WanderConsoleNeighbors(this);
|
||||
late final i1.SmallWebVisits smallWebVisits = i1.SmallWebVisits(this);
|
||||
late final i2.SmallWebItemDao smallWebItemDao = i2.SmallWebItemDao(
|
||||
this as i3.SmallWebDatabase,
|
||||
);
|
||||
late final i4.SmallWebVisitDao smallWebVisitDao = i4.SmallWebVisitDao(
|
||||
this as i3.SmallWebDatabase,
|
||||
);
|
||||
late final i5.WanderConsoleDao wanderConsoleDao = i5.WanderConsoleDao(
|
||||
this as i3.SmallWebDatabase,
|
||||
);
|
||||
i1.DefinitionsDrift get definitionsDrift => i6.ReadDatabaseContainer(
|
||||
this,
|
||||
).accessor<i1.DefinitionsDrift>(i1.DefinitionsDrift.new);
|
||||
@override
|
||||
Iterable<i0.TableInfo<i0.Table, Object?>> get allTables =>
|
||||
allSchemaEntities.whereType<i0.TableInfo<i0.Table, Object?>>();
|
||||
@override
|
||||
List<i0.DatabaseSchemaEntity> get allSchemaEntities => [
|
||||
smallWebItems,
|
||||
smallWebMemberships,
|
||||
i1.idxMembershipSourceMode,
|
||||
i1.idxMembershipItem,
|
||||
wanderConsoles,
|
||||
wanderConsoleNeighbors,
|
||||
smallWebVisits,
|
||||
i1.idxVisitMode,
|
||||
i1.idxVisitItem,
|
||||
];
|
||||
@override
|
||||
i0.StreamQueryUpdateRules get streamUpdateRules =>
|
||||
const i0.StreamQueryUpdateRules([
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName(
|
||||
'small_web_items',
|
||||
limitUpdateKind: i0.UpdateKind.delete,
|
||||
),
|
||||
result: [
|
||||
i0.TableUpdate('small_web_memberships', kind: i0.UpdateKind.delete),
|
||||
],
|
||||
),
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName(
|
||||
'wander_consoles',
|
||||
limitUpdateKind: i0.UpdateKind.delete,
|
||||
),
|
||||
result: [
|
||||
i0.TableUpdate(
|
||||
'wander_console_neighbors',
|
||||
kind: i0.UpdateKind.delete,
|
||||
),
|
||||
],
|
||||
),
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName(
|
||||
'small_web_items',
|
||||
limitUpdateKind: i0.UpdateKind.delete,
|
||||
),
|
||||
result: [
|
||||
i0.TableUpdate('small_web_visits', kind: i0.UpdateKind.delete),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
class $SmallWebDatabaseManager {
|
||||
final $SmallWebDatabase _db;
|
||||
$SmallWebDatabaseManager(this._db);
|
||||
i1.$SmallWebItemsTableManager get smallWebItems =>
|
||||
i1.$SmallWebItemsTableManager(_db, _db.smallWebItems);
|
||||
i1.$SmallWebMembershipsTableManager get smallWebMemberships =>
|
||||
i1.$SmallWebMembershipsTableManager(_db, _db.smallWebMemberships);
|
||||
i1.$WanderConsolesTableManager get wanderConsoles =>
|
||||
i1.$WanderConsolesTableManager(_db, _db.wanderConsoles);
|
||||
i1.$WanderConsoleNeighborsTableManager get wanderConsoleNeighbors =>
|
||||
i1.$WanderConsoleNeighborsTableManager(_db, _db.wanderConsoleNeighbors);
|
||||
i1.$SmallWebVisitsTableManager get smallWebVisits =>
|
||||
i1.$SmallWebVisitsTableManager(_db, _db.smallWebVisits);
|
||||
}
|
||||
|
||||
extension DefineFunctions on i7.CommonDatabase {
|
||||
void defineFunctions({
|
||||
required String Function(int, String?) lexoRankNext,
|
||||
required String Function(int, String?) lexoRankPrevious,
|
||||
required String Function(String?, String?) lexoRankReorderAfter,
|
||||
required String Function(String?, String?) lexoRankReorderBefore,
|
||||
}) {
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_next',
|
||||
argumentCount: const i7.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as int;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankNext(arg0, arg1);
|
||||
},
|
||||
);
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_previous',
|
||||
argumentCount: const i7.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as int;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankPrevious(arg0, arg1);
|
||||
},
|
||||
);
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_reorder_after',
|
||||
argumentCount: const i7.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as String?;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankReorderAfter(arg0, arg1);
|
||||
},
|
||||
);
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_reorder_before',
|
||||
argumentCount: const i7.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as String?;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankReorderBefore(arg0, arg1);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import 'package:weblibre/data/database/converters/uri.dart';
|
||||
import 'package:weblibre/data/database/converters/string_list.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/small_web_source_kind.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/wander_console_source.dart';
|
||||
|
||||
CREATE TABLE small_web_items (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
url TEXT NOT NULL UNIQUE MAPPED BY `const UriConverter()`,
|
||||
title TEXT,
|
||||
domain TEXT NOT NULL,
|
||||
author TEXT,
|
||||
summary TEXT,
|
||||
published_at DATETIME,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) AS SmallWebItem;
|
||||
|
||||
CREATE TABLE small_web_memberships (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
item_id TEXT NOT NULL REFERENCES small_web_items(id) ON DELETE CASCADE,
|
||||
source_kind ENUM(SmallWebSourceKind) NOT NULL,
|
||||
mode TEXT,
|
||||
console_url TEXT MAPPED BY `const UriConverterNullable()`,
|
||||
categories TEXT NOT NULL DEFAULT '[]' MAPPED BY `const StringListConverter()`,
|
||||
fetched_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(item_id, source_kind, mode, console_url)
|
||||
) AS SmallWebMembership;
|
||||
|
||||
CREATE INDEX idx_membership_source_mode ON small_web_memberships (source_kind, mode);
|
||||
CREATE INDEX idx_membership_item ON small_web_memberships (item_id);
|
||||
|
||||
CREATE TABLE wander_consoles (
|
||||
url TEXT NOT NULL PRIMARY KEY MAPPED BY `const UriConverter()`,
|
||||
wander_js_url TEXT NOT NULL MAPPED BY `const UriConverter()`,
|
||||
last_fetched_at DATETIME,
|
||||
last_fetch_failed BOOL,
|
||||
discovered_from_url TEXT MAPPED BY `const UriConverterNullable()`,
|
||||
source ENUM(WanderConsoleSource) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) AS WanderConsole;
|
||||
|
||||
CREATE TABLE wander_console_neighbors (
|
||||
source_console_url TEXT NOT NULL REFERENCES wander_consoles(url) ON DELETE CASCADE,
|
||||
target_console_url TEXT NOT NULL,
|
||||
discovered_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (source_console_url, target_console_url)
|
||||
) AS WanderConsoleNeighbor;
|
||||
|
||||
CREATE TABLE small_web_visits (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
item_id TEXT NOT NULL REFERENCES small_web_items(id) ON DELETE CASCADE,
|
||||
source_kind ENUM(SmallWebSourceKind) NOT NULL,
|
||||
mode TEXT,
|
||||
console_url TEXT MAPPED BY `const UriConverterNullable()`,
|
||||
visited_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) AS SmallWebVisit;
|
||||
|
||||
CREATE INDEX idx_visit_mode ON small_web_visits (source_kind, mode, visited_at);
|
||||
CREATE INDEX idx_visit_item ON small_web_visits (item_id);
|
||||
|
||||
getDiscoverableKagiItems:
|
||||
SELECT i.* FROM small_web_items i
|
||||
INNER JOIN small_web_memberships m ON m.item_id = i.id
|
||||
WHERE m.source_kind = :sourceKind
|
||||
AND m.mode = :mode
|
||||
AND (:category IS NULL OR EXISTS (
|
||||
SELECT 1 FROM json_each(m.categories) WHERE value = :category
|
||||
))
|
||||
AND i.id NOT IN (
|
||||
SELECT v.item_id FROM small_web_visits v
|
||||
WHERE v.source_kind = :sourceKind AND v.mode = :mode
|
||||
ORDER BY v.visited_at DESC LIMIT 20
|
||||
);
|
||||
|
||||
getRecentVisits:
|
||||
SELECT v.*, i.url, i.title, i.domain
|
||||
FROM small_web_visits v
|
||||
INNER JOIN small_web_items i ON i.id = v.item_id
|
||||
WHERE v.source_kind = :sourceKind
|
||||
AND ((:mode IS NULL AND v.mode IS NULL) OR v.mode = :mode)
|
||||
ORDER BY v.visited_at DESC
|
||||
LIMIT :limit;
|
||||
|
||||
getDiscoveredConsoleUrls:
|
||||
SELECT url FROM wander_consoles ORDER BY created_at DESC LIMIT :limit;
|
||||
|
||||
getWanderPagesForConsole:
|
||||
SELECT i.* FROM small_web_items i
|
||||
INNER JOIN small_web_memberships m ON m.item_id = i.id
|
||||
WHERE m.source_kind = :sourceKind AND m.console_url = CAST(:consoleUrl AS TEXT);
|
||||
|
||||
getConsoleNeighborCount:
|
||||
SELECT COUNT(*) AS c FROM wander_console_neighbors WHERE source_console_url = :consoleUrl;
|
||||
|
||||
getAllModeItemCounts:
|
||||
SELECT source_kind, mode, COUNT(*) AS c
|
||||
FROM small_web_memberships
|
||||
GROUP BY source_kind, mode;
|
||||
|
||||
getRecentVisitItemIds:
|
||||
SELECT DISTINCT item_id FROM small_web_visits
|
||||
WHERE source_kind = :sourceKind
|
||||
AND ((:mode IS NULL AND mode IS NULL) OR mode = :mode)
|
||||
ORDER BY visited_at DESC
|
||||
LIMIT :limit;
|
||||
|
||||
getNeighborConsolesWithPageCounts:
|
||||
SELECT wc.url, wc.last_fetched_at, wc.last_fetch_failed,
|
||||
(SELECT COUNT(*) FROM small_web_memberships m
|
||||
WHERE m.source_kind = :sourceKind AND m.console_url = CAST(wc.url AS TEXT)) AS page_count
|
||||
FROM wander_console_neighbors n
|
||||
INNER JOIN wander_consoles wc ON CAST(wc.url AS TEXT) = n.target_console_url
|
||||
WHERE n.source_console_url = :sourceConsoleUrl
|
||||
AND COALESCE(wc.last_fetch_failed, 0) = 0
|
||||
ORDER BY page_count DESC;
|
||||
|
||||
getAllConsolesWithPageCounts:
|
||||
SELECT wc.url, wc.last_fetched_at, wc.last_fetch_failed,
|
||||
(SELECT COUNT(*) FROM small_web_memberships m
|
||||
WHERE m.source_kind = :sourceKind AND m.console_url = CAST(wc.url AS TEXT)) AS page_count
|
||||
FROM wander_consoles wc
|
||||
WHERE COALESCE(wc.last_fetch_failed, 0) = 0
|
||||
AND (:query = '' OR CAST(wc.url AS TEXT) LIKE '%' || :query || '%')
|
||||
ORDER BY page_count DESC;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
class KagiCategoryDefinition {
|
||||
final String slug;
|
||||
final String label;
|
||||
final String description;
|
||||
final String emoji;
|
||||
|
||||
const KagiCategoryDefinition({
|
||||
required this.slug,
|
||||
required this.label,
|
||||
required this.description,
|
||||
required this.emoji,
|
||||
});
|
||||
}
|
||||
|
||||
class KagiCategories {
|
||||
final Map<String, KagiCategoryDefinition> categories;
|
||||
final Map<String, List<String>> groups;
|
||||
final Map<String, String> remap;
|
||||
|
||||
const KagiCategories({
|
||||
required this.categories,
|
||||
required this.groups,
|
||||
required this.remap,
|
||||
});
|
||||
|
||||
factory KagiCategories.fromJson(Map<String, dynamic> json) {
|
||||
final rawCategories = json['categories'] as Map<String, dynamic>;
|
||||
final categories = rawCategories.map(
|
||||
(slug, data) => MapEntry(
|
||||
slug,
|
||||
KagiCategoryDefinition(
|
||||
slug: slug,
|
||||
label: (data as Map<String, dynamic>)['label'] as String,
|
||||
description: data['description'] as String,
|
||||
emoji: data['emoji'] as String,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final rawGroups = json['groups'] as Map<String, dynamic>;
|
||||
final groups = rawGroups.map(
|
||||
(name, slugs) => MapEntry(
|
||||
name,
|
||||
(slugs as List<dynamic>).cast<String>(),
|
||||
),
|
||||
);
|
||||
|
||||
final rawRemap = json['remap'] as Map<String, dynamic>;
|
||||
final remap = rawRemap.cast<String, String>();
|
||||
|
||||
return KagiCategories(
|
||||
categories: categories,
|
||||
groups: groups,
|
||||
remap: remap,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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:fast_equatable/fast_equatable.dart';
|
||||
|
||||
class KagiFeedEntry with FastEquatable {
|
||||
final Uri url;
|
||||
final String? title;
|
||||
final String? author;
|
||||
final String? summary;
|
||||
final DateTime? publishedAt;
|
||||
final List<String> categories;
|
||||
|
||||
KagiFeedEntry({
|
||||
required this.url,
|
||||
this.title,
|
||||
this.author,
|
||||
this.summary,
|
||||
this.publishedAt,
|
||||
this.categories = const [],
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
url,
|
||||
title,
|
||||
author,
|
||||
summary,
|
||||
publishedAt,
|
||||
categories,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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/material.dart';
|
||||
|
||||
enum KagiSmallWebMode {
|
||||
web('Web', Icons.language, 'https://kagi.com/api/v1/smallweb/feed?nso'),
|
||||
appreciated(
|
||||
'Appreciated',
|
||||
Icons.thumb_up_outlined,
|
||||
'https://kagi.com/smallweb/appreciated',
|
||||
),
|
||||
videos(
|
||||
'Videos',
|
||||
Icons.play_circle_outline,
|
||||
'https://kagi.com/api/v1/smallweb/feed?yt',
|
||||
),
|
||||
code('Code', Icons.code, 'https://kagi.com/api/v1/smallweb/feed?gh'),
|
||||
comics(
|
||||
'Comics',
|
||||
Icons.auto_stories,
|
||||
'https://kagi.com/api/v1/smallweb/feed?comic',
|
||||
);
|
||||
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final String feedUrlString;
|
||||
|
||||
const KagiSmallWebMode(this.label, this.icon, this.feedUrlString);
|
||||
|
||||
Uri get feedUrl => Uri.parse(feedUrlString);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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/material.dart';
|
||||
|
||||
enum SmallWebSourceKind {
|
||||
kagi('Kagi', Icons.travel_explore, 'Small Web by Kagi Search'),
|
||||
wander('Wander', Icons.dns, 'Console-based web ring');
|
||||
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final String description;
|
||||
|
||||
const SmallWebSourceKind(this.label, this.icon, this.description);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
enum WanderConsoleSource { seed, manual, discovered }
|
||||
@@ -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 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:sqlite3_flutter_libs/sqlite3_flutter_libs.dart';
|
||||
import 'package:weblibre/core/database_registry.dart';
|
||||
import 'package:weblibre/core/filesystem.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/kagi_category.dart';
|
||||
|
||||
part 'providers.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
SmallWebDatabase smallWebDatabase(Ref ref) {
|
||||
final db = SmallWebDatabase(
|
||||
LazyDatabase(() async {
|
||||
final file = File(
|
||||
p.join(filesystem.profileDatabasesDir.path, 'small_web.db'),
|
||||
);
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
await applyWorkaroundToOpenSqlite3OnOldAndroidVersions();
|
||||
}
|
||||
|
||||
return NativeDatabase.createInBackground(file);
|
||||
}),
|
||||
);
|
||||
|
||||
DatabaseRegistry.instance.register('small_web', db);
|
||||
|
||||
ref.onDispose(() async {
|
||||
await db.close();
|
||||
});
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Future<KagiCategories> kagiCategories(Ref ref) async {
|
||||
final jsonStr = await rootBundle.loadString(
|
||||
'assets/small_web/kagi_categories.json',
|
||||
);
|
||||
|
||||
return KagiCategories.fromJson(jsonDecode(jsonStr) as Map<String, dynamic>);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'providers.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(smallWebDatabase)
|
||||
final smallWebDatabaseProvider = SmallWebDatabaseProvider._();
|
||||
|
||||
final class SmallWebDatabaseProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
SmallWebDatabase,
|
||||
SmallWebDatabase,
|
||||
SmallWebDatabase
|
||||
>
|
||||
with $Provider<SmallWebDatabase> {
|
||||
SmallWebDatabaseProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'smallWebDatabaseProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$smallWebDatabaseHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<SmallWebDatabase> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
SmallWebDatabase create(Ref ref) {
|
||||
return smallWebDatabase(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(SmallWebDatabase value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<SmallWebDatabase>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$smallWebDatabaseHash() => r'e199e8c1261e8152110fb99f883fed1e550ffdc6';
|
||||
|
||||
@ProviderFor(kagiCategories)
|
||||
final kagiCategoriesProvider = KagiCategoriesProvider._();
|
||||
|
||||
final class KagiCategoriesProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<KagiCategories>,
|
||||
KagiCategories,
|
||||
FutureOr<KagiCategories>
|
||||
>
|
||||
with $FutureModifier<KagiCategories>, $FutureProvider<KagiCategories> {
|
||||
KagiCategoriesProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'kagiCategoriesProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$kagiCategoriesHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<KagiCategories> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<KagiCategories> create(Ref ref) {
|
||||
return kagiCategories(ref);
|
||||
}
|
||||
}
|
||||
|
||||
String _$kagiCategoriesHash() => r'de97daabc1aba5360209e15f1de0e5488435aa54';
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
const wanderSeedConsoles = ['https://susam.net/wander/'];
|
||||
Reference in New Issue
Block a user