diff --git a/lib/http/black.dart b/lib/http/black.dart index 2b47673ea..eb02c8d80 100644 --- a/lib/http/black.dart +++ b/lib/http/black.dart @@ -1,4 +1,5 @@ import 'package:PiliPlus/http/loading_state.dart'; +import 'package:PiliPlus/utils/storage.dart'; import '../models/user/black.dart'; import 'index.dart'; @@ -11,7 +12,7 @@ class BlackHttp { 'ps': ps ?? 50, 're_version': 0, 'jsonp': 'jsonp', - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }); if (res.data['code'] == 0) { BlackListDataModel data = BlackListDataModel.fromJson(res.data['data']); diff --git a/lib/http/danmaku.dart b/lib/http/danmaku.dart index 5c2c46023..2727abd55 100644 --- a/lib/http/danmaku.dart +++ b/lib/http/danmaku.dart @@ -1,5 +1,6 @@ import 'package:PiliPlus/grpc/dm/v1/dm.pb.dart'; import 'package:PiliPlus/grpc/grpc_repo.dart'; +import 'package:PiliPlus/utils/storage.dart'; import 'package:dio/dio.dart'; import 'index.dart'; @@ -83,7 +84,7 @@ class DanmakuHttp { 'rnd': DateTime.now().microsecondsSinceEpoch, 'colorful': colorful == true ? 60001 : null, 'checkbox_type': checkbox_type, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, // 'access_key': access_key, }..removeWhere((key, value) => value == null); diff --git a/lib/http/danmaku_block.dart b/lib/http/danmaku_block.dart index c638c835d..65d5bd469 100644 --- a/lib/http/danmaku_block.dart +++ b/lib/http/danmaku_block.dart @@ -1,4 +1,5 @@ import '../models/user/danmaku_block.dart'; +import '../utils/storage.dart'; import 'index.dart'; class DanmakuFilterHttp { @@ -22,7 +23,7 @@ class DanmakuFilterHttp { Api.danmakuFilterDel, queryParameters: { 'ids': ids, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, ); if (res.data['code'] == 0) { @@ -45,7 +46,7 @@ class DanmakuFilterHttp { queryParameters: { 'type': type, 'filter': filter, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, ); if (res.data['code'] == 0) { diff --git a/lib/http/dynamics.dart b/lib/http/dynamics.dart index af6352a0e..0c561f1b9 100644 --- a/lib/http/dynamics.dart +++ b/lib/http/dynamics.dart @@ -67,7 +67,7 @@ class DynamicsHttp { queryParameters: { 'dynamic_id': dynamicId, 'up': up, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, ); if (res.data['code'] == 0) { @@ -125,7 +125,7 @@ class DynamicsHttp { var res = await Request().post( Api.setTopDyn, queryParameters: { - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, data: { 'dyn_str': dynamicId, diff --git a/lib/http/init.dart b/lib/http/init.dart index ca4004f64..c61a771dd 100644 --- a/lib/http/init.dart +++ b/lib/http/init.dart @@ -61,11 +61,6 @@ class Request { } } - // 从cookie中获取 csrf token - static Future getCsrf() async { - return Accounts.main.csrf; - } - // static Future buvidActive(Account account) async { // // 这样线程不安全, 但仍按预期进行 // if (account.activited) return; diff --git a/lib/http/live.dart b/lib/http/live.dart index 43728776f..37326fcf5 100644 --- a/lib/http/live.dart +++ b/lib/http/live.dart @@ -4,6 +4,7 @@ import 'package:PiliPlus/models/live/danmu_info.dart'; import 'package:PiliPlus/models/live/follow.dart'; import 'package:PiliPlus/models/live/live_emoticons/data.dart'; import 'package:PiliPlus/models/live/live_emoticons/datum.dart'; +import 'package:PiliPlus/utils/storage.dart'; import 'package:PiliPlus/utils/wbi_sign.dart'; import 'package:dio/dio.dart'; import '../models/live/item.dart'; @@ -42,7 +43,7 @@ class LiveHttp { } static Future sendLiveMsg({roomId, msg, dmType, emoticonOptions}) async { - dynamic csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; var res = await Request().post( Api.sendLiveMsg, data: FormData.fromMap({ diff --git a/lib/http/member.dart b/lib/http/member.dart index 2b57967e4..27730e85a 100644 --- a/lib/http/member.dart +++ b/lib/http/member.dart @@ -42,7 +42,7 @@ class MemberHttp { 'mid': mid, 'reason': reason, if (reasonV2 != null) 'reason_v2': reasonV2, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, ), ); @@ -476,7 +476,7 @@ class MemberHttp { isAdd ? Api.addSpecial : Api.delSpecial, data: { 'fid': fid, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, options: Options( contentType: Headers.formUrlEncodedContentType, @@ -499,7 +499,7 @@ class MemberHttp { data: { 'fids': fids, 'tagids': tagids ?? '0', - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, // 'cross_domain': true }, options: Options( diff --git a/lib/http/msg.dart b/lib/http/msg.dart index d436da8cd..bb0647ca2 100644 --- a/lib/http/msg.dart +++ b/lib/http/msg.dart @@ -6,6 +6,7 @@ import 'package:PiliPlus/models/msg/msgfeed_like_me.dart'; import 'package:PiliPlus/models/msg/msgfeed_reply_me.dart'; import 'package:PiliPlus/models/msg/msgfeed_sys_msg.dart'; import 'package:PiliPlus/pages/dynamics/view.dart' show ReplyOption; +import 'package:PiliPlus/utils/storage.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:uuid/uuid.dart'; @@ -85,7 +86,7 @@ class MsgHttp { } static Future msgSysUpdateCursor(int cursor) async { - String csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; var res = await Request().get(Api.msgSysUpdateCursor, queryParameters: { 'csrf': csrf, 'cursor': cursor, @@ -125,7 +126,7 @@ class MsgHttp { ReplyOption? replyOption, int? privatePub, }) async { - String csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; var res = await Request().post( Api.createDynamic, queryParameters: { @@ -204,7 +205,7 @@ class MsgHttp { 'bucket': bucket, 'file': await MultipartFile.fromFile(path), 'dir': dir, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }), ); if (res.data['code'] == 0) { @@ -231,7 +232,7 @@ class MsgHttp { 'file_up': file, if (category != null) 'category': category, if (biz != null) 'biz': biz, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }; var res = await Request().post( Api.uploadBfs, @@ -254,7 +255,7 @@ class MsgHttp { static Future createTextDynamic( dynamic content, ) async { - String csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; Map data = await WbiSign.makSign({ 'dynamic_id': 0, 'type': 4, @@ -280,7 +281,7 @@ class MsgHttp { static Future removeDynamic( dynamic dynamicId, ) async { - String csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; Map data = await WbiSign.makSign({ 'dynamic_id': dynamicId, 'csrf_token': csrf, @@ -303,7 +304,7 @@ class MsgHttp { static Future removeMsg( dynamic talkerId, ) async { - String csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; Map data = await WbiSign.makSign({ 'talker_id': talkerId, 'session_type': 1, @@ -327,7 +328,7 @@ class MsgHttp { int tp, dynamic id, ) async { - String csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; var res = await Request().post( Api.delMsgfeed, data: { @@ -355,7 +356,7 @@ class MsgHttp { static Future delSysMsg( dynamic id, ) async { - String csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; var res = await Request().post( HttpString.messageBaseUrl + Api.delSysMsg, queryParameters: { @@ -384,7 +385,7 @@ class MsgHttp { required dynamic talkerId, required int opType, }) async { - String csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; Map data = await WbiSign.makSign({ 'talker_id': talkerId, 'session_type': 1, @@ -485,7 +486,7 @@ class MsgHttp { int? talkerId, int? ackSeqno, }) async { - String csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; Map params = await WbiSign.makSign({ 'talker_id': talkerId, 'session_type': 1, @@ -519,7 +520,7 @@ class MsgHttp { int? msgType, dynamic content, }) async { - String csrf = await Request.getCsrf(); + String csrf = Accounts.main.csrf; Map base = { 'msg[sender_uid]': senderUid, 'msg[receiver_id]': receiverId, diff --git a/lib/http/reply.dart b/lib/http/reply.dart index e21d4efec..c5a24ff5d 100644 --- a/lib/http/reply.dart +++ b/lib/http/reply.dart @@ -234,7 +234,7 @@ class ReplyHttp { 'pn': pageNum, 'type': type, 'sort': 1, - if (isLogin) 'csrf': await Request.getCsrf(), + if (isLogin) 'csrf': Accounts.main.csrf, }, options: isLogin.not ? _options : null, ); @@ -342,7 +342,7 @@ class ReplyHttp { 'oid': oid, 'rpid': rpid, 'action': action, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, options: Options( contentType: Headers.formUrlEncodedContentType, @@ -369,7 +369,7 @@ class ReplyHttp { 'oid': oid, 'rpid': rpid, 'action': action, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, ); if (res.data['code'] == 0) { @@ -406,7 +406,7 @@ class ReplyHttp { 'type': type, 'rpid': rpid, 'action': isUpTop ? 0 : 1, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, options: Options( contentType: Headers.formUrlEncodedContentType, diff --git a/lib/http/user.dart b/lib/http/user.dart index 71c067d8c..e3a20da03 100644 --- a/lib/http/user.dart +++ b/lib/http/user.dart @@ -1,6 +1,7 @@ import 'package:PiliPlus/http/loading_state.dart'; import 'package:PiliPlus/models/video/later.dart'; import 'package:PiliPlus/utils/global_data.dart'; +import 'package:PiliPlus/utils/storage.dart'; import 'package:PiliPlus/utils/utils.dart'; import 'package:PiliPlus/utils/wbi_sign.dart'; import 'package:dio/dio.dart'; @@ -71,7 +72,7 @@ class UserHttp { }) async { Map data = { 'sort': sort.join(','), - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }; Utils.appSign(data); var res = await Request().post( @@ -95,7 +96,7 @@ class UserHttp { Map data = { 'media_id': mediaId, 'sort': sort.join(','), - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }; Utils.appSign(data); var res = await Request().post( @@ -120,7 +121,7 @@ class UserHttp { data: { 'media_id': mediaId, 'platform': 'web', - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, options: Options( contentType: Headers.formUrlEncodedContentType, @@ -140,7 +141,7 @@ class UserHttp { data: { 'media_ids': mediaIds.join(','), 'platform': 'web', - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, options: Options( contentType: Headers.formUrlEncodedContentType, @@ -166,7 +167,7 @@ class UserHttp { 'intro': intro, 'privacy': privacy, 'cover': cover.isNotEmpty ? Uri.encodeFull(cover) : cover, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, if (mediaId != null) 'media_id': mediaId, }, options: Options( @@ -284,7 +285,7 @@ class UserHttp { queryParameters: { 'switch': switchStatus, 'jsonp': 'jsonp', - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, ); return res; @@ -306,7 +307,7 @@ class UserHttp { Api.clearHistory, queryParameters: { 'jsonp': 'jsonp', - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, ); return res; @@ -314,7 +315,7 @@ class UserHttp { // 稍后再看 static Future toViewLater({String? bvid, dynamic aid}) async { - var data = {'csrf': await Request.getCsrf()}; + var data = {'csrf': Accounts.main.csrf}; if (bvid != null) { data['bvid'] = bvid; } else if (aid != null) { @@ -334,7 +335,7 @@ class UserHttp { // 移除已观看 static Future toViewDel({required List aids}) async { final Map params = { - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, 'resources': aids.join(',') }; dynamic res = await Request().post( @@ -374,7 +375,7 @@ class UserHttp { Api.toViewClear, queryParameters: { if (cleanType != null) 'clean_type': cleanType, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, ); if (res.data['code'] == 0) { @@ -391,7 +392,7 @@ class UserHttp { data: { 'kid': kidList.join(','), 'jsonp': 'jsonp', - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, options: Options( contentType: Headers.formUrlEncodedContentType, @@ -524,7 +525,7 @@ class UserHttp { Api.addFavArticle, data: { 'id': id, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, options: Options( contentType: Headers.formUrlEncodedContentType, @@ -544,7 +545,7 @@ class UserHttp { Api.delFavArticle, data: { 'id': id, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, options: Options( contentType: Headers.formUrlEncodedContentType, @@ -564,7 +565,7 @@ class UserHttp { var res = await Request().post( Api.communityAction, queryParameters: { - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, data: { "entity": { @@ -609,7 +610,7 @@ class UserHttp { Api.unfavFolder, queryParameters: { 'media_id': id, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, ); } else { @@ -618,7 +619,7 @@ class UserHttp { queryParameters: { 'platform': 'web', 'season_id': id, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, ); } diff --git a/lib/http/video.dart b/lib/http/video.dart index 999b4a2df..b45d8de2b 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -823,7 +823,7 @@ class VideoHttp { await Request().post( Api.roomEntryAction, queryParameters: { - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, data: { 'room_id': roomId, diff --git a/lib/pages/dynamics/widgets/author_panel.dart b/lib/pages/dynamics/widgets/author_panel.dart index c7abac6aa..40699cf80 100644 --- a/lib/pages/dynamics/widgets/author_panel.dart +++ b/lib/pages/dynamics/widgets/author_panel.dart @@ -437,7 +437,7 @@ class AuthorPanel extends StatelessWidget { final res = await Request().post( '/x/dynamic/feed/dynamic_report/add', queryParameters: { - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, data: { "accused_uid": item.modules.moduleAuthor.mid, diff --git a/lib/pages/member/widget/edit_profile_page.dart b/lib/pages/member/widget/edit_profile_page.dart index d1e300d2b..0d1aed821 100644 --- a/lib/pages/member/widget/edit_profile_page.dart +++ b/lib/pages/member/widget/edit_profile_page.dart @@ -470,7 +470,7 @@ class _EditProfilePageState extends State { .post( '/x/member/web/face/update', queryParameters: { - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, }, data: FormData.fromMap({ 'dopost': 'save', diff --git a/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart b/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart index 49c67e419..a30ac40b0 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart @@ -1104,7 +1104,7 @@ class ReplyItemGrpc extends StatelessWidget { '/x/v2/reply/report', data: { 'add_blacklist': banUid, - 'csrf': await Request.getCsrf(), + 'csrf': Accounts.main.csrf, 'gaia_source': 'main_h5', 'oid': item.oid, 'platform': 'android',