Skip to content

Commit

Permalink
settings: Add search message api option
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-dev committed Sep 25, 2021
1 parent c192cb0 commit 265a062
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
52 changes: 52 additions & 0 deletions lib/pages/settings/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,58 @@ class _SettingsPageState extends State<SettingsPage>
},
),
_buildDivider(),
ListTile(
leading: Icon(
MdiIcons.commentSearch,
color: Settings.majorColor,
),
title: Text('대사 검색기 API'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () async {
TextEditingController text =
TextEditingController(text: Settings.searchMessageAPI);
Widget okButton = TextButton(
style: TextButton.styleFrom(primary: Settings.majorColor),
child: Text(Translations.of(context).trans('ok')),
onPressed: () {
Navigator.pop(context, true);
},
);
Widget cancelButton = TextButton(
style: TextButton.styleFrom(primary: Settings.majorColor),
child: Text(Translations.of(context).trans('cancel')),
onPressed: () {
Navigator.pop(context, false);
},
);
Widget defaultButton = TextButton(
style: TextButton.styleFrom(primary: Settings.majorColor),
child: Text(Translations.of(context).trans('default')),
onPressed: () {
setState(
() => text.text = 'https://koromo.xyz/api/search/msg');
},
);
var dialog = await showDialog(
useRootNavigator: false,
context: context,
builder: (BuildContext context) => AlertDialog(
contentPadding: EdgeInsets.fromLTRB(12, 0, 12, 0),
title: Text('대사 검색기 API'),
content: TextField(
controller: text,
autofocus: true,
maxLines: 3,
),
actions: [defaultButton, okButton, cancelButton],
),
);
if (dialog != null && dialog == true) {
await Settings.setSearchMessageAPI(text.text);
}
},
),
_buildDivider(),
InkWell(
customBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
Expand Down
14 changes: 8 additions & 6 deletions lib/server/violet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:violet/network/wrapper.dart' as http;
import 'package:violet/pages/viewer/viewer_report.dart';
import 'package:violet/server/salt.dart';
import 'package:violet/server/wsalt.dart' as wsalt;
import 'package:violet/settings/settings.dart';

class VioletServer {
static const protocol = 'https';
Expand Down Expand Up @@ -418,12 +419,13 @@ class VioletServer {
var vToken = DateTime.now().toUtc().millisecondsSinceEpoch;
var vValid = wsalt.getValid(vToken.toString());

var gg = await http
.get('$api/search/msg/$type/' + Uri.encodeFull(what), headers: {
'v-token': vToken.toString(),
'v-valid': vValid,
"Content-Type": "application/json"
});
var gg = await http.get(
'${Settings.searchMessageAPI}/$type/' + Uri.encodeFull(what),
headers: {
'v-token': vToken.toString(),
'v-valid': vValid,
"Content-Type": "application/json"
});

if (gg.statusCode != 200) {
return gg.statusCode;
Expand Down
15 changes: 15 additions & 0 deletions lib/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Settings {
static String downloadBasePath;
static String downloadRule;

static String searchMessageAPI;
static bool useVioletServer;

static bool useDrawer;
Expand Down Expand Up @@ -386,6 +387,14 @@ class Settings {
.setString('downloadrule', downloadRule);
}

searchMessageAPI =
(await SharedPreferences.getInstance()).getString('searchmessageapi');
if (searchMessageAPI == null) {
searchMessageAPI = "https://koromo.xyz/api/search/msg";
await (await SharedPreferences.getInstance())
.setString('searchmessageapi', downloadRule);
}

useVioletServer = await _getBool('usevioletserver');
useDrawer = await _getBool('usedrawer');
showArticleProgress = await _getBool('showarticleprogress');
Expand Down Expand Up @@ -594,6 +603,12 @@ class Settings {
await (await SharedPreferences.getInstance()).setString('downloadrule', nn);
}

static Future<void> setSearchMessageAPI(String nn) async {
searchMessageAPI = nn;
await (await SharedPreferences.getInstance())
.setString('searchmessageapi', nn);
}

static Future<void> setUserInnerStorage(bool nn) async {
useInnerStorage = nn;
await (await SharedPreferences.getInstance())
Expand Down

0 comments on commit 265a062

Please sign in to comment.