forked from MeoProject/lx-music-api-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webui.py
1656 lines (1589 loc) · 71.1 KB
/
webui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import flet
import ujson as json
import os
import ast
# from ChatGPT
def update_nested_json(json_obj, updates):
for key, value in updates.items():
if key in json_obj:
if isinstance(value, dict) and isinstance(json_obj[key], dict):
update_nested_json(json_obj[key], value)
elif isinstance(value, list) and isinstance(json_obj[key], list):
if len(value) == len(json_obj[key]):
for i in range(len(value)):
if isinstance(value[i], dict) and isinstance(
json_obj[key][i], dict
):
update_nested_json(json_obj[key][i], value[i])
else:
json_obj[key][i] = value[i]
else:
json_obj[key] = value
else:
json_obj[key] = value
else:
json_obj[key] = value
return json_obj
def toint(page: flet.Page, arg):
# def closeFailedDialog(e):
# failedDialog.open = False
# page.update()
# failedDialog = flet.AlertDialog(
# modal=True,
# title=flet.Text('Update failed', color='FF0000'),
# content=flet.Text('Please Check You Input\n\n'+str(arg)),
# actions=[flet.TextButton("OK", on_click=closeFailedDialog)],
# actions_alignment=flet.MainAxisAlignment.END,
# )
# def openFailedDialog():
# page.dialog = failedDialog
# failedDialog.open = True
# page.update()
try:
return int(arg)
except:
# openFailedDialog()
return None
def _Save(page: flet.Page, args):
def closeSuccessDialog(e):
successDialog.open = False
page.update()
successDialog = flet.AlertDialog(
modal=True,
title=flet.Text("Update success"),
content=flet.Text(
"Update Content: "
+ str(args)
+ "\n\nYour original config.json file have been rename configN.bak"
),
actions=[flet.TextButton("OK", on_click=closeSuccessDialog)],
actions_alignment=flet.MainAxisAlignment.END,
)
def openSuccessDialog():
page.dialog = successDialog
successDialog.open = True
page.update()
def closeFailedDialog(e):
failedDialog.open = False
page.update()
failedDialog = flet.AlertDialog(
modal=True,
title=flet.Text("Update failed", color="FF0000"),
content=flet.Text("Please Check You Input\n\n" + str(args)),
actions=[flet.TextButton("OK", on_click=closeFailedDialog)],
actions_alignment=flet.MainAxisAlignment.END,
)
def openFailedDialog():
page.dialog = failedDialog
failedDialog.open = True
page.update()
# print(args)
try:
with open("./config/config.json", "r+", encoding="utf-8") as f:
config = json.loads(f.read())
config = update_nested_json(config, args)
i = 1
while 1:
try:
os.rename("./config/config.json", f"./config/config{i}.bak")
break
except:
i += 1
with open("./config/config.json", "w+", encoding="utf-8") as f:
f.write(
json.dumps(
config, indent=4, ensure_ascii=False, escape_forward_slashes=False
)
)
openSuccessDialog()
except:
openFailedDialog()
def _404(page: flet.Page):
return [
flet.Container(
content=flet.Text(value="404", size=50), alignment=flet.alignment.center
),
flet.Container(
content=flet.ElevatedButton("返回主页", on_click=lambda _: page.go("/")),
alignment=flet.alignment.center,
),
]
# def _Save_Cookiepool(page: flet.Page, p, v):
# return []
def CommonPage(page: flet.Page):
common = config["common"]
common_host_label = flet.TextField(
label="服务器启动时所使用的HOST地址", value=common["host"]
)
common_ports_label = flet.TextField(
label="服务器启动时所使用的端口,使用list格式", value=common["ports"]
)
common_ssl_info_label = flet.ElevatedButton(
"服务器https配置", on_click=lambda _: page.go("/common/ssl_info")
)
common_reverse_proxy_label = flet.ElevatedButton(
"针对类似于nginx一类的反代的配置",
on_click=lambda _: page.go("/common/reverse_proxy"),
)
common_debug_mode_label = flet.Checkbox(
label="是否开启调试模式", value=common["debug_mode"]
)
common_log_length_limit_label = flet.TextField(
label="单条日志长度限制", value=common["log_length_limit"]
)
common_fakeip_label = flet.TextField(
label="服务器在海外时的IP伪装值", value=common["fakeip"]
)
common_proxy_label = flet.ElevatedButton(
"代理配置,HTTP与HTTPS协议需分开配置",
on_click=lambda _: page.go("/common/proxy"),
)
common_log_file_label = flet.Checkbox(
label="是否开启日志文件", value=bool(common["log_file"])
)
common_cookiepool_label = flet.Checkbox(
label="是否开启cookie池", value=bool(config["common"]["cookiepool"])
)
common_download_config_label = flet.ElevatedButton(
"下载脚本配置", on_click=lambda _: page.go("/common/download_config")
)
return [
common_host_label,
common_ports_label,
common_ssl_info_label,
common_reverse_proxy_label,
common_debug_mode_label,
common_log_length_limit_label,
common_fakeip_label,
common_proxy_label,
common_log_file_label,
common_cookiepool_label,
flet.Text("这将允许用户配置多个cookie并在请求时随机使用一个"),
flet.Text(
"启用后请在module.cookiepool中配置cookie,在user处配置的cookie会被忽略"
),
flet.Text("cookiepool中格式统一为列表嵌套user处的cookie的字典"),
common_download_config_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"common": {
"host": str(common_host_label.value),
"ports": json.loads(
str(common_ports_label.value).replace("'", '"')
),
"debug_mode": bool(common_debug_mode_label.value),
"log_length_limit": toint(
page, common_log_length_limit_label.value
),
"fakeip": str(common_fakeip_label.value),
"log_file": bool(common_log_file_label.value),
"cookiepool": bool(common_cookiepool_label.value),
}
},
),
),
]
def CommonPageExpand(page: flet.Page):
if page.route.split("/")[2] == "ssl_info":
ssl_info = config["common"]["ssl_info"]
common_is_https_label = flet.Checkbox(
label="是否开启HTTPS", value=bool(ssl_info["is_https"])
)
common_enable_label = flet.Checkbox(
label="启用", value=bool(ssl_info["enable"])
)
common_ssl_ports_label = flet.TextField(
label="SSL端口,使用list格式", value=ssl_info["ssl_ports"]
)
common_path_cert_label = flet.TextField(
label="ssl证书的cert文件地址", value=ssl_info["path"]["cert"]
)
common_path_privkey_label = flet.TextField(
label="ssl证书的private key文件地址", value=ssl_info["path"]["privkey"]
)
return [
flet.Container(
content=flet.Text(value="SSL Info", size=30),
alignment=flet.alignment.center,
),
flet.Text(
'服务器https配置,"是否开启HTTPS"是这个服务器是否是https服务器,如果你使用了反向代理来转发这个服务器,如果它使用了https,也请将它设置为true'
),
common_is_https_label,
common_enable_label,
common_ssl_ports_label,
common_path_cert_label,
common_path_privkey_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/common")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"common": {
"ssl_info": {
"is_https": bool(common_is_https_label.value),
"enable": bool(common_enable_label.value),
"ssl_ports": json.loads(
str(common_ssl_ports_label.value).replace("'", '"')
),
"path": {
"cert": str(common_path_cert_label.value),
"privkey": str(common_path_privkey_label.value),
},
}
}
},
),
),
]
elif page.route.split("/")[2] == "reverse_proxy":
reverse_proxy = config["common"]["reverse_proxy"]
common_allow_proxy_label = flet.Checkbox(
label="是否允许反代", value=bool(reverse_proxy["allow_proxy"])
)
common_proxy_whitelist_remote_label = flet.TextField(
label="反代时允许的ip来源列表,通常为127.0.0.1",
value=reverse_proxy["proxy_whitelist_remote"],
)
common_real_ip_header_label = flet.TextField(
label="反代来源ip的来源头,不懂请保持默认",
value=reverse_proxy["real_ip_header"],
)
return [
flet.Container(
content=flet.Text(value="Reverse Proxy", size=30),
alignment=flet.alignment.center,
),
common_allow_proxy_label,
common_proxy_whitelist_remote_label,
common_real_ip_header_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/common")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"common": {
"reverse_proxy": {
"allow_proxy": bool(common_allow_proxy_label.value),
"proxy_whitelist_remote": json.loads(
str(
common_proxy_whitelist_remote_label.value
).replace("'", '"')
),
"real_ip_header": str(
common_real_ip_header_label.value
),
}
}
},
),
),
]
elif page.route.split("/")[2] == "proxy":
proxy = config["common"]["proxy"]
common_proxy_enable_label = flet.Checkbox(
label="是否开启代理", value=bool(proxy["enable"])
)
common_http_value_label = flet.TextField(
label="HTTP协议配置", value=proxy["http_value"]
)
common_https_value_label = flet.TextField(
label="HTTPS协议配置", value=proxy["https_value"]
)
return [
flet.Container(
content=flet.Text(value="Proxy", size=30),
alignment=flet.alignment.center,
),
# flet.AppBar(title=flet.Text('proxy'), bgcolor=flet.colors.SURFACE_VARIANT),
common_proxy_enable_label,
common_http_value_label,
common_https_value_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/common")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"common": {
"proxy": {
"enable": bool(common_proxy_enable_label.value),
"http_value": str(common_http_value_label.value),
"https_value": str(common_https_value_label.value),
}
}
},
),
),
]
elif page.route.split("/")[2] == "download_config":
download_config = config["common"]["download_config"]
common_allow_download_script_label = flet.Checkbox(
label="是否允许直接从服务端下载脚本,开启后可以直接访问 /script?key=你的请求key 下载脚本",
value=bool(config["common"]["allow_download_script"]),
)
common_name_label = flet.TextField(
label="修改为你的源脚本名称", value=download_config["name"]
)
common_intro_label = flet.TextField(
label="修改为你的源脚本描述", value=download_config["intro"]
)
common_author_label = flet.TextField(
label="修改为你的源脚本作者", value=download_config["author"]
)
common_version_label = flet.TextField(
label="修改为你的源版本", value=download_config["version"]
)
common_filename_label = flet.TextField(
label="客户端保存脚本时的文件名(可能因浏览器不同出现不一样的情况)",
value=download_config["filename"],
)
common_dev_label = flet.Checkbox(
label="是否启用开发模式", value=bool(download_config["dev"])
)
# common_quality_label = flet.Tabs(
# selected_index=0,
# animation_duration=300,
# tabs=[
# flet.Tab(
# text='kw',
# content=flet.Row(
# [
# flet.Checkbox(label="128k", value=True),
# flet.Checkbox(label="320k", value=False),
# flet.Checkbox(label="flac", value=False),
# flet.Checkbox(label="flac24bit", value=False),
# ]
# ),
# ),
# flet.Tab(
# text='kg',
# content=flet.Row(
# [
# flet.Checkbox(label="128k", value=True),
# flet.Checkbox(label="320k", value=False),
# flet.Checkbox(label="flac", value=False),
# flet.Checkbox(label="flac24bit", value=False),
# ]
# ),
# ),
# flet.Tab(
# text='tx',
# content=flet.Row(
# [
# flet.Checkbox(label="128k", value=True),
# flet.Checkbox(label="320k", value=False),
# flet.Checkbox(label="flac", value=False),
# flet.Checkbox(label="flac24bit", value=False),
# ]
# ),
# ),
# flet.Tab(
# text='wy',
# content=flet.Row(
# [
# flet.Checkbox(label="128k", value=True),
# flet.Checkbox(label="320k", value=False),
# flet.Checkbox(label="flac", value=False),
# flet.Checkbox(label="flac24bit", value=False),
# ]
# ),
# ),
# flet.Tab(
# text='mg',
# content=flet.Row(
# [
# flet.Checkbox(label="128k", value=True),
# flet.Checkbox(label="320k", value=False),
# flet.Checkbox(label="flac", value=False),
# flet.Checkbox(label="flac24bit", value=False),
# ]
# ),
# ),
# ],
# expand=1,
# )
common_quality_label = flet.TextField(
label="支持的音质", value=download_config["quality"]
)
return [
flet.Container(
content=flet.Text(value="源脚本的相关配置", size=30),
alignment=flet.alignment.center,
),
# flet.AppBar(title=flet.Text('源脚本的相关配置'), bgcolor=flet.colors.SURFACE_VARIANT),
common_allow_download_script_label,
common_name_label,
common_intro_label,
common_author_label,
common_version_label,
common_filename_label,
common_dev_label,
# flet.Text(value='支持的音质'),
common_quality_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/common")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"common": {
"allow_download_script": bool(
common_allow_download_script_label.value
),
"download_config": json.loads(
str(common_quality_label.value).replace("'", '"')
),
}
},
),
),
]
else:
return _404(page)
def SecurityPage(page: flet.Page):
security = config["security"]
security_rate_limit_label = flet.ElevatedButton(
"请求速率限制", on_click=lambda _: page.go("/security/rate_limit")
)
security_key_label = flet.ElevatedButton(
"请求key", on_click=lambda _: page.go("/security/key")
)
security_whitelist_host_label = flet.TextField(
label="强制白名单HOST", value=security["whitelist_host"]
)
security_check_lxm_label = flet.Checkbox(
label='是否检查lxm请求头(正常的LX Music以"测试接口"的方式请求时都会携带这个请求头)',
value=bool(security["check_lxm"]),
)
security_lxm_ban_label = flet.Checkbox(
label="lxm请求头不存在或不匹配时是否将用户IP加入黑名单",
value=bool(security["lxm_ban"]),
)
security_allowed_host_label = flet.ElevatedButton(
"HOST允许列表", on_click=lambda _: page.go("/security/allowed_host")
)
security_banlist_label = flet.ElevatedButton(
"黑名单", on_click=lambda _: page.go("/security/banlist")
)
return [
security_rate_limit_label,
security_key_label,
security_whitelist_host_label,
security_lxm_ban_label,
security_check_lxm_label,
security_allowed_host_label,
security_banlist_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"security": {
"whitelist_host": json.loads(
str(security_whitelist_host_label.value).replace("'", '"')
),
"check_lxm": bool(security_check_lxm_label.value),
"lxm_ban": bool(security_lxm_ban_label.value),
}
},
),
),
]
def SecurityPageExpand(page: flet.Page):
if page.route.split("/")[2] == "rate_limit":
rate_limit = config["security"]["rate_limit"]
security_global_label = flet.TextField(
label="全局请求速率限制", value=rate_limit["global"]
)
security_ip_label = flet.TextField(
label="单个ip请求速率限制", value=rate_limit["ip"]
)
return [
flet.Container(
content=flet.Text(value="Rate Limit", size=30),
alignment=flet.alignment.center,
),
# flet.AppBar(title=flet.Text('ssl_info'), bgcolor=flet.colors.SURFACE_VARIANT),
flet.Text(
"请求速率限制,填入的值为至少间隔多久才能进行一次请求,单位:秒,不限制请填为0"
),
security_global_label,
security_ip_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/security")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"security": {
"rate_limit": {
"global": toint(page, security_global_label.value),
"ip": toint(page, security_ip_label.value),
}
}
},
),
),
]
elif page.route.split("/")[2] == "key":
key = config["security"]["key"]
security_key_enable_label = flet.Checkbox(
label="是否开启请求key,开启后只有请求头中包含key,且值一样时可以访问API",
value=bool(key["enable"]),
)
security_ban_label = flet.Checkbox(label="ban", value=bool(key["ban"]))
security_values_label = flet.TextField(
label="key(使用列表格式)", value=key["values"]
)
return [
flet.Container(
content=flet.Text(value="Key", size=30), alignment=flet.alignment.center
),
# flet.AppBar(title=flet.Text('ssl_info'), bgcolor=flet.colors.SURFACE_VARIANT),
security_key_enable_label,
security_ban_label,
security_values_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/security")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"security": {
"key": {
"enable": bool(security_key_enable_label.value),
"ban": bool(security_ban_label.value),
"value": json.loads(
str(security_values_label.value).replace("'", '"')
),
}
}
},
),
),
]
elif page.route.split("/")[2] == "allowed_host":
allowed_host = config["security"]["allowed_host"]
security_allowed_host_enable_label = flet.Checkbox(
label="启用", value=bool(allowed_host["enable"])
)
security_list_label = flet.TextField(label="列表", value=allowed_host["list"])
security_blacklist_enable_label = flet.Checkbox(
label="启用", value=bool(allowed_host["blacklist"]["enable"])
)
security_blacklist_length_label = flet.TextField(
label="长度", value=allowed_host["blacklist"]["length"]
)
return [
flet.Container(
content=flet.Text(value="Allowd Host", size=30),
alignment=flet.alignment.center,
),
# flet.AppBar(title=flet.Text('ssl_info'), bgcolor=flet.colors.SURFACE_VARIANT),
flet.Text(
"HOST允许列表,启用后只允许列表内的HOST访问服务器,不需要加端口号"
),
security_allowed_host_enable_label,
security_list_label,
flet.Text(
"当用户访问的HOST并不在允许列表中时是否将请求IP加入黑名单,长度单位:秒"
),
security_blacklist_enable_label,
security_blacklist_length_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/security")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"security": {
"allowed_host": {
"enable": bool(
security_allowed_host_enable_label.value
),
"blacklist": {
"enable": bool(
security_blacklist_enable_label.value
),
"length": toint(
page, security_blacklist_length_label.value
),
},
"list": json.loads(
str(security_list_label.value).replace("'", '"')
),
}
}
},
),
),
]
elif page.route.split("/")[2] == "banlist":
banlist = config["security"]["banlist"]
security_banlist_enable_label = flet.Checkbox(
label="启用", value=bool(banlist["enable"])
)
security_expire_enable_label = flet.Checkbox(
label="启用", value=bool(banlist["expire"]["enable"])
)
security_expire_length_label = flet.TextField(
label="长度", value=banlist["expire"]["length"]
)
return [
flet.Container(
content=flet.Text(value="Ban List", size=30),
alignment=flet.alignment.center,
),
# flet.AppBar(title=flet.Text('ssl_info'), bgcolor=flet.colors.SURFACE_VARIANT),
flet.Text(
"是否启用黑名单(全局设置,关闭后已存储的值并不受影响,但不会再检查"
),
security_banlist_enable_label,
flet.Text("是否启用黑名单IP过期(关闭后其他地方的配置会失效)"),
security_expire_enable_label,
security_expire_length_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/security")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"security": {
"banlist": {
"enable": bool(security_banlist_enable_label.value),
"expire": {
"enable": bool(security_expire_enable_label),
"length": toint(
page, security_expire_length_label.value
),
},
}
}
},
),
),
]
return [flet.ElevatedButton("返回", on_click=lambda _: page.go("/security"))]
def ModulePage(page: flet.Page):
kg_label = flet.ElevatedButton("kg", on_click=lambda _: page.go("/module/kg"))
tx_label = flet.ElevatedButton("tx", on_click=lambda _: page.go("/module/tx"))
wy_label = flet.ElevatedButton("wy", on_click=lambda _: page.go("/module/wy"))
mg_label = flet.ElevatedButton("mg", on_click=lambda _: page.go("/module/mg"))
kw_label = flet.ElevatedButton("kw", on_click=lambda _: page.go("/module/kw"))
cookiepool_label = flet.ElevatedButton(
"cookiepool", on_click=lambda _: page.go("/module/cookiepool")
)
return [
kg_label,
tx_label,
wy_label,
mg_label,
kw_label,
cookiepool_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/")),
]
def ModulePageExpand(page: flet.Page):
if page.route.split("/")[2] == "kg":
if page.route.split("/")[-1] == "kg":
return [
flet.Container(
content=flet.Text(value="酷狗音乐相关配置", size=30),
alignment=flet.alignment.center,
),
flet.ElevatedButton(
"client", on_click=lambda _: page.go("/module/kg/client")
),
flet.ElevatedButton(
"tracker", on_click=lambda _: page.go("/module/kg/tracker")
),
flet.ElevatedButton(
"user", on_click=lambda _: page.go("/module/kg/user")
),
flet.ElevatedButton("返回", on_click=lambda _: page.go("/module")),
]
else:
if page.route.split("/")[3] == "client":
kg_client = config["module"]["kg"]["client"]
module_kg_client_appid_label = flet.TextField(
label="酷狗音乐的appid,官方安卓为1005,官方PC为1001",
value=kg_client["appid"],
)
module_kg_client_signatureKey_label = flet.TextField(
label="客户端signature采用的key值,需要与appid对应",
value=kg_client["signatureKey"],
)
module_kg_client_clientver_label = flet.TextField(
label="客户端versioncode,pidversionsecret可能随此值而变化",
value=kg_client["clientver"],
)
module_kg_client_pidversionsecret_label = flet.TextField(
label="获取URL时所用的key值计算验证值",
value=kg_client["pidversionsecret"],
)
module_kg_client_pid_label = flet.TextField(
label="pid", value=kg_client["pid"]
)
return [
flet.Container(
content=flet.Text(
value="客户端请求配置,不懂请保持默认", size=30
),
alignment=flet.alignment.center,
),
module_kg_client_appid_label,
module_kg_client_signatureKey_label,
module_kg_client_clientver_label,
module_kg_client_pidversionsecret_label,
module_kg_client_pid_label,
flet.ElevatedButton(
"返回", on_click=lambda _: page.go("/module/kg")
),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"module": {
"kg": {
"client": {
"appid": str(
module_kg_client_appid_label.value
),
"signatureKey": str(
module_kg_client_signatureKey_label.value
),
"clientver": str(
module_kg_client_clientver_label.value
),
"pidversionsecret": str(
module_kg_client_pidversionsecret_label.value
),
"pid": str(
module_kg_client_pid_label.value
),
}
}
}
},
),
),
]
elif page.route.split("/")[3] == "tracker":
kg_tracker = config["module"]["kg"]["tracker"]
module_kg_tracker_host_label = flet.TextField(
label="host", value=kg_tracker["host"]
)
module_kg_tracker_path_label = flet.TextField(
label="path", value=kg_tracker["path"]
)
module_kg_tracker_version_label = flet.TextField(
label="客户端versioncode,pidversionsecret可能随此值而变化",
value=kg_tracker["version"],
)
module_kg_tracker_xrouter_enable_label = flet.Checkbox(
label="启用", value=bool(kg_tracker["x-router"]["enable"])
)
module_kg_tracker_xrouter_value_label = flet.TextField(
label="x-router", value=kg_tracker["x-router"]["value"]
)
module_kg_tracker_extra_params_label = flet.TextField(
label="自定义添加的param,优先级大于默认,填写类型为普通的JSON数据,会自动转换为请求param",
value=kg_tracker["extra_params"],
)
return [
flet.Container(
content=flet.Text(
value="trackerapi请求配置,不懂请保持默认", size=30
),
alignment=flet.alignment.center,
),
module_kg_tracker_host_label,
module_kg_tracker_path_label,
module_kg_tracker_version_label,
flet.Text(
"当host为gateway.kugou.com时需要追加此头,为tracker类地址时则不需要"
),
module_kg_tracker_xrouter_enable_label,
module_kg_tracker_xrouter_value_label,
module_kg_tracker_extra_params_label,
flet.ElevatedButton(
"返回", on_click=lambda _: page.go("/module/kg")
),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"module": {
"kg": {
"tracker": {
"host": str(
module_kg_tracker_host_label.value
),
"path": str(
module_kg_tracker_path_label.value
),
"version": str(
module_kg_tracker_version_label.value
),
"x-router": {
"enable": bool(
module_kg_tracker_xrouter_enable_label.value
),
"value": str(
module_kg_tracker_xrouter_value_label.value
),
},
"extra_params": json.loads(
str(
module_kg_tracker_extra_params_label.value
).replace("'", '"')
),
}
}
}
},
),
),
]
elif page.route.split("/")[3] == "user":
kg_user = config["module"]["kg"]["user"]
module_kg_user_token_label = flet.TextField(
label="token", value=kg_user["token"]
)
module_kg_user_userid_label = flet.TextField(
label="userid", value=kg_user["userid"]
)
module_kg_user_mid_label = flet.TextField(
label="mid", value=kg_user["mid"]
)
module_kg_user_lite_sign_in_enable_label = flet.Checkbox(
label="启用", value=bool(kg_user["lite_sign_in"]["enable"])
)
module_kg_user_lite_sign_in_interval_label = flet.TextField(
label="interval", value=kg_user["lite_sign_in"]["interval"]
)
module_kg_user_lite_sign_in_mixsongmid_label = flet.TextField(
label="mix_songmid的获取方式, 默认auto, 可以改成一个数字手动",
value=kg_user["lite_sign_in"]["mixsongmid"]["value"],
)
return [
flet.Container(
content=flet.Text(
value="此处内容请统一抓包获取,需要vip账号来获取会员歌曲,如果没有请留为空值,mid必填,可以瞎填一段数字",
size=30,
),
alignment=flet.alignment.center,
),
module_kg_user_token_label,
module_kg_user_userid_label,
module_kg_user_mid_label,
flet.Text("是否启用概念版自动签到,仅在appid=3116时运行"),
module_kg_user_lite_sign_in_enable_label,
module_kg_user_lite_sign_in_interval_label,
module_kg_user_lite_sign_in_mixsongmid_label,
flet.ElevatedButton(
"返回", on_click=lambda _: page.go("/module/kg")
),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{
"module": {
"kg": {
"user": {
"token": str(
module_kg_user_token_label.value
),
"userid": str(
module_kg_user_userid_label.value
),
"mid": str(module_kg_user_mid_label.value),
"lite_sign_in": {
"enable": bool(
module_kg_user_lite_sign_in_enable_label.value
),
"interval": toint(
page,
module_kg_user_lite_sign_in_interval_label.value,
),
"mixsongmid": {
"value": str(
module_kg_user_lite_sign_in_mixsongmid_label.value
)
},
},
}
}
}
},
),
),
]
else:
return _404(page)
elif page.route.split("/")[2] == "tx":
if page.route.split("/")[-1] == "tx":
module_tx_cdnaddr_label = flet.TextField(
label="CDN地址", value=config["module"]["tx"]["cdnaddr"]
)
return [
flet.Container(
content=flet.Text(value="QQ音乐相关配置", size=30),
alignment=flet.alignment.center,
),
flet.ElevatedButton(
"vkeyserver", on_click=lambda _: page.go("/module/tx/vkeyserver")
),
flet.ElevatedButton(
"user", on_click=lambda _: page.go("/module/tx/user")
),
module_tx_cdnaddr_label,
flet.ElevatedButton("返回", on_click=lambda _: page.go("/module")),
flet.ElevatedButton(
"保存",
on_click=lambda _: _Save(
page,
{