Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
h-akatsuki committed Dec 28, 2024
1 parent 6fb3505 commit 51dc7fe
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:hitomi_search_plus/download/background.dart';
import 'package:hitomi_search_plus/download/download.dart';
import 'package:hitomi_search_plus/page/home.dart';
import 'package:hitomi_search_plus/page/settings.dart';
import 'package:hitomi_search_plus/server/query.dart';
import 'package:hitomi_search_plus/server/tags.dart';
import 'package:hitomi_search_plus/src/rust/frb_generated.dart';
import 'package:hitomi_search_plus/tools/theme.dart';
Expand Down Expand Up @@ -39,6 +40,7 @@ Future<void> initPath() async {
await Future.wait([
initSettings(),
initDefaultQuery(),
initQuery(),
]);
}

Expand Down
9 changes: 9 additions & 0 deletions lib/page/settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:hitomi_search_plus/component/thumbnail.dart';
import 'package:hitomi_search_plus/db/kv.dart';
import 'package:hitomi_search_plus/server/query.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

Expand Down Expand Up @@ -81,6 +82,14 @@ class SettingsScreen extends HookConsumerWidget {
ref.read(useJapaneseProvider.notifier).toggle();
},
),
const Divider(),
TextSettingItem(
title: 'Override search api',
initialValue: ref.read(queryAPIUriProvider),
onChanged: (String value) {
ref.read(queryAPIUriProvider.notifier).set(value);
},
),
],
),
);
Expand Down
27 changes: 25 additions & 2 deletions lib/server/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,34 @@ import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hitomi_search_plus/db/default_query.dart';
import 'package:hitomi_search_plus/db/kv.dart';
import 'package:http/http.dart' as http;
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'query.freezed.dart';
part 'query.g.dart';

String _apiUri = 'https://hitomi.hiro.red';

Future<void> initQuery() async {
final apiUri = await getKV('__api_uri__');
if (apiUri != null) {
_apiUri = apiUri;
}
}

@riverpod
class QueryAPIUri extends _$QueryAPIUri {
@override
String build() => _apiUri;

void set(String uri) {
_apiUri = uri;
state = uri;
setKV('__api_uri__', uri);
}
}

@freezed
class SearchBuilder with _$SearchBuilder {
factory SearchBuilder({
Expand Down Expand Up @@ -75,7 +98,7 @@ List<SearchResults> parseSearchResults(Uint8List data) {
}

Future<List<SearchResults>> search(SearchParams params) async {
final url = Uri.parse('https://hitomi.hiro.red/search');
final url = Uri.parse('$_apiUri/search');
final response = await http.post(
url,
body: jsonEncode(params.toJson()),
Expand Down Expand Up @@ -172,7 +195,7 @@ class SearchResultsReader {
}

Future<SearchResultsReader> searchReader(SearchParams params) async {
final url = Uri.parse('https://hitomi.hiro.red/search');
final url = Uri.parse('$_apiUri/search');
final response = await http.post(
url,
body: jsonEncode(params.toJson()),
Expand Down
22 changes: 22 additions & 0 deletions lib/server/query.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/server/update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'update.g.dart';

const v = 'v0.2.5';
const v = 'v0.2.6';

@Riverpod(keepAlive: true)
class LatestVersion extends _$LatestVersion {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.2.5+1
version: 0.2.6+1

environment:
sdk: ^3.5.0
Expand Down

0 comments on commit 51dc7fe

Please sign in to comment.