diff --git a/lib/http/reply.dart b/lib/http/reply.dart index 4aa34eabd..6ebbadb7f 100644 --- a/lib/http/reply.dart +++ b/lib/http/reply.dart @@ -1,5 +1,7 @@ +import 'dart:io'; + import 'package:PiliPalaX/http/loading_state.dart'; -import 'package:PiliPalaX/utils/extension.dart'; +import 'package:PiliPalaX/utils/storage.dart'; import 'package:dio/dio.dart'; import '../models/video/reply/data.dart'; @@ -9,28 +11,30 @@ import 'constants.dart'; import 'init.dart'; class ReplyHttp { - static final _dio = Dio(); static Future replyList({ required int oid, required String nextOffset, required int type, int sort = 1, }) async { - try { - var res = await _dio - .get('${HttpString.apiBaseUrl}${Api.replyList}', queryParameters: { + Options? options = GStorage.userInfo.get('userInfoCache') == null + ? Options( + headers: {HttpHeaders.cookieHeader: "buvid3= ; b_nut= ; sid= "}) + : null; + var res = await Request().get( + '${HttpString.apiBaseUrl}${Api.replyList}', + data: { 'oid': oid, 'type': type, 'pagination_str': '{"offset":"${nextOffset.replaceAll('"', '\\"')}"}', 'mode': sort + 2, //2:按时间排序;3:按热度排序 - }); - if (res.data['code'] == 0) { - return LoadingState.success(ReplyData.fromJson(res.data['data'])); - } else { - return LoadingState.error(res.data['message']); - } - } catch (e) { - return LoadingState.error(e.toString()); + }, + options: options, + ); + if (res.data['code'] == 0) { + return LoadingState.success(ReplyData.fromJson(res.data['data'])); + } else { + return LoadingState.error(res.data['message']); } } @@ -41,23 +45,26 @@ class ReplyHttp { required int type, int sort = 1, }) async { - try { - var res = await _dio.get('${HttpString.apiBaseUrl}${Api.replyReplyList}', - queryParameters: { - 'oid': oid, - 'root': root, - 'pn': pageNum, - 'type': type, - 'sort': 1, - 'csrf': await Request.getCsrf(), - }); - if (res.data['code'] == 0) { - return LoadingState.success(ReplyReplyData.fromJson(res.data['data'])); - } else { - return LoadingState.error(res.data['message']); - } - } catch (e) { - return LoadingState.error(e.toString()); + Options? options = GStorage.userInfo.get('userInfoCache') == null + ? Options( + headers: {HttpHeaders.cookieHeader: "buvid3= ; b_nut= ; sid= "}) + : null; + var res = await Request().get( + '${HttpString.apiBaseUrl}${Api.replyReplyList}', + data: { + 'oid': oid, + 'root': root, + 'pn': pageNum, + 'type': type, + 'sort': 1, + 'csrf': await Request.getCsrf(), + }, + options: options, + ); + if (res.data['code'] == 0) { + return LoadingState.success(ReplyReplyData.fromJson(res.data['data'])); + } else { + return LoadingState.error(res.data['message']); } }