prepare for multiple apps
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 'package:exceptions/exceptions.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/http_error_handler.dart';
|
||||
import 'package:weblibre/features/search/domain/entities/abstract/i_search_suggestion_provider.dart';
|
||||
|
||||
part 'brave.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class BraveAutosuggestService extends _$BraveAutosuggestService
|
||||
implements ISearchSuggestionProvider {
|
||||
static final _baseUrl = Uri.https('search.brave.com', 'api/suggest');
|
||||
|
||||
late http.Client _client;
|
||||
|
||||
@override
|
||||
void build() {
|
||||
_client = http.Client();
|
||||
|
||||
ref.onDispose(() {
|
||||
_client.close();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<String>>> getSuggestions(String query) {
|
||||
return Result.fromAsync(() async {
|
||||
final response = await _client
|
||||
.get(_baseUrl.replace(queryParameters: {'q': query}))
|
||||
.timeout(const Duration(seconds: 5));
|
||||
|
||||
final results = jsonDecode(utf8.decode(response.bodyBytes)) as List;
|
||||
return switch (results.last) {
|
||||
final String result => [result],
|
||||
final List resultList => resultList.cast(),
|
||||
_ => [],
|
||||
};
|
||||
}, exceptionHandler: handleHttpError);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'brave.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(BraveAutosuggestService)
|
||||
final braveAutosuggestServiceProvider = BraveAutosuggestServiceProvider._();
|
||||
|
||||
final class BraveAutosuggestServiceProvider
|
||||
extends $NotifierProvider<BraveAutosuggestService, void> {
|
||||
BraveAutosuggestServiceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'braveAutosuggestServiceProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$braveAutosuggestServiceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
BraveAutosuggestService create() => BraveAutosuggestService();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$braveAutosuggestServiceHash() =>
|
||||
r'3b2f465dcf4b44b0450975d3909fc7066d171bf2';
|
||||
|
||||
abstract class _$BraveAutosuggestService 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,61 @@
|
||||
/*
|
||||
* 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 'package:exceptions/exceptions.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/http_error_handler.dart';
|
||||
import 'package:weblibre/features/search/domain/entities/abstract/i_search_suggestion_provider.dart';
|
||||
|
||||
part 'duckduckgo.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class DuckDuckGoAutosuggestService extends _$DuckDuckGoAutosuggestService
|
||||
implements ISearchSuggestionProvider {
|
||||
static final _baseUrl = Uri.https('duckduckgo.com', 'ac/');
|
||||
|
||||
late http.Client _client;
|
||||
|
||||
@override
|
||||
void build() {
|
||||
_client = http.Client();
|
||||
|
||||
ref.onDispose(() {
|
||||
_client.close();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<String>>> getSuggestions(String query) {
|
||||
return Result.fromAsync(() async {
|
||||
final response = await _client
|
||||
.get(_baseUrl.replace(queryParameters: {'type': 'list', 'q': query}))
|
||||
.timeout(const Duration(seconds: 5));
|
||||
|
||||
final results = jsonDecode(utf8.decode(response.bodyBytes)) as List;
|
||||
return switch (results.last) {
|
||||
final String result => [result],
|
||||
final List resultList => resultList.cast(),
|
||||
_ => [],
|
||||
};
|
||||
}, exceptionHandler: handleHttpError);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'duckduckgo.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(DuckDuckGoAutosuggestService)
|
||||
final duckDuckGoAutosuggestServiceProvider =
|
||||
DuckDuckGoAutosuggestServiceProvider._();
|
||||
|
||||
final class DuckDuckGoAutosuggestServiceProvider
|
||||
extends $NotifierProvider<DuckDuckGoAutosuggestService, void> {
|
||||
DuckDuckGoAutosuggestServiceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'duckDuckGoAutosuggestServiceProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$duckDuckGoAutosuggestServiceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
DuckDuckGoAutosuggestService create() => DuckDuckGoAutosuggestService();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$duckDuckGoAutosuggestServiceHash() =>
|
||||
r'd9f30a577b276049b252be890bc73eb18aa118f2';
|
||||
|
||||
abstract class _$DuckDuckGoAutosuggestService 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,36 @@
|
||||
/*
|
||||
* 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:exceptions/exceptions.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/features/search/domain/entities/abstract/i_search_suggestion_provider.dart';
|
||||
|
||||
part 'empty.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class EmptyAutosuggestService extends _$EmptyAutosuggestService
|
||||
implements ISearchSuggestionProvider {
|
||||
@override
|
||||
void build() {}
|
||||
|
||||
@override
|
||||
Future<Result<List<String>>> getSuggestions(String query) {
|
||||
return Future.value(Result.success([]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'empty.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(EmptyAutosuggestService)
|
||||
final emptyAutosuggestServiceProvider = EmptyAutosuggestServiceProvider._();
|
||||
|
||||
final class EmptyAutosuggestServiceProvider
|
||||
extends $NotifierProvider<EmptyAutosuggestService, void> {
|
||||
EmptyAutosuggestServiceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'emptyAutosuggestServiceProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$emptyAutosuggestServiceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
EmptyAutosuggestService create() => EmptyAutosuggestService();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$emptyAutosuggestServiceHash() =>
|
||||
r'7fbe81807baf379cf621ef46fba00e46778978f8';
|
||||
|
||||
abstract class _$EmptyAutosuggestService 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,61 @@
|
||||
/*
|
||||
* 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 'package:exceptions/exceptions.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/http_error_handler.dart';
|
||||
import 'package:weblibre/features/search/domain/entities/abstract/i_search_suggestion_provider.dart';
|
||||
|
||||
part 'kagi.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class KagiAutosuggestService extends _$KagiAutosuggestService
|
||||
implements ISearchSuggestionProvider {
|
||||
static final _baseUrl = Uri.https('kagi.com', 'api/autosuggest');
|
||||
|
||||
late http.Client _client;
|
||||
|
||||
@override
|
||||
void build() {
|
||||
_client = http.Client();
|
||||
|
||||
ref.onDispose(() {
|
||||
_client.close();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<String>>> getSuggestions(String query) {
|
||||
return Result.fromAsync(() async {
|
||||
final response = await _client
|
||||
.get(_baseUrl.replace(queryParameters: {'q': query}))
|
||||
.timeout(const Duration(seconds: 5));
|
||||
|
||||
final results = jsonDecode(utf8.decode(response.bodyBytes)) as List;
|
||||
return switch (results.last) {
|
||||
final String result => [result],
|
||||
final List resultList => resultList.cast(),
|
||||
_ => [],
|
||||
};
|
||||
}, exceptionHandler: handleHttpError);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'kagi.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(KagiAutosuggestService)
|
||||
final kagiAutosuggestServiceProvider = KagiAutosuggestServiceProvider._();
|
||||
|
||||
final class KagiAutosuggestServiceProvider
|
||||
extends $NotifierProvider<KagiAutosuggestService, void> {
|
||||
KagiAutosuggestServiceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'kagiAutosuggestServiceProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$kagiAutosuggestServiceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
KagiAutosuggestService create() => KagiAutosuggestService();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$kagiAutosuggestServiceHash() =>
|
||||
r'039fe84dd480316eab38c80b41e16d16d6c14a7c';
|
||||
|
||||
abstract class _$KagiAutosuggestService 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,66 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
// ignore_for_file: avoid_dynamic_calls
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:exceptions/exceptions.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/http_error_handler.dart';
|
||||
import 'package:weblibre/features/search/domain/entities/abstract/i_search_suggestion_provider.dart';
|
||||
|
||||
part 'qwant.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class QwantAutosuggestService extends _$QwantAutosuggestService
|
||||
implements ISearchSuggestionProvider {
|
||||
static final _baseUrl = Uri.https('api.qwant.com', 'v3/suggest');
|
||||
|
||||
late http.Client _client;
|
||||
|
||||
@override
|
||||
void build() {
|
||||
_client = http.Client();
|
||||
|
||||
ref.onDispose(() {
|
||||
_client.close();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<String>>> getSuggestions(String query) {
|
||||
return Result.fromAsync(() async {
|
||||
final response = await _client
|
||||
.get(_baseUrl.replace(queryParameters: {'q': query}))
|
||||
.timeout(const Duration(seconds: 5));
|
||||
|
||||
final results =
|
||||
jsonDecode(utf8.decode(response.bodyBytes)) as Map<String, dynamic>;
|
||||
if (results['status'] != 'success') {
|
||||
throw Exception('qwant api error');
|
||||
}
|
||||
|
||||
final items = results['data']['items'] as List;
|
||||
return items.map((item) => item['value'] as String).toList();
|
||||
}, exceptionHandler: handleHttpError);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'qwant.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(QwantAutosuggestService)
|
||||
final qwantAutosuggestServiceProvider = QwantAutosuggestServiceProvider._();
|
||||
|
||||
final class QwantAutosuggestServiceProvider
|
||||
extends $NotifierProvider<QwantAutosuggestService, void> {
|
||||
QwantAutosuggestServiceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'qwantAutosuggestServiceProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$qwantAutosuggestServiceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
QwantAutosuggestService create() => QwantAutosuggestService();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$qwantAutosuggestServiceHash() =>
|
||||
r'a942cd073289d20d43647de5c0f43fb08790045f';
|
||||
|
||||
abstract class _$QwantAutosuggestService 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