mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix: check reply
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -14,7 +14,6 @@ import '../utils/utils.dart';
|
||||
import 'api.dart';
|
||||
import 'constants.dart';
|
||||
import 'interceptor.dart';
|
||||
import 'interceptor_anonymity.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart' as web;
|
||||
|
||||
class Request {
|
||||
@@ -37,7 +36,7 @@ class Request {
|
||||
);
|
||||
cookieManager = CookieManager(cookieJar);
|
||||
dio.interceptors.add(cookieManager);
|
||||
dio.interceptors.add(AnonymityInterceptor());
|
||||
dio.interceptors.add(ApiInterceptor());
|
||||
final List<Cookie> cookies = await cookieManager.cookieJar
|
||||
.loadForRequest(Uri.parse(HttpString.baseUrl));
|
||||
for (Cookie item in cookies) {
|
||||
@@ -175,15 +174,12 @@ class Request {
|
||||
);
|
||||
}
|
||||
|
||||
//添加拦截器
|
||||
dio.interceptors.add(ApiInterceptor());
|
||||
|
||||
// 日志拦截器 输出请求、响应内容
|
||||
dio.interceptors.add(LogInterceptor(
|
||||
request: false,
|
||||
requestHeader: false,
|
||||
responseHeader: false,
|
||||
));
|
||||
// dio.interceptors.add(LogInterceptor(
|
||||
// request: false,
|
||||
// requestHeader: false,
|
||||
// responseHeader: false,
|
||||
// ));
|
||||
|
||||
dio.transformer = BackgroundTransformer();
|
||||
dio.options.validateStatus = (int? status) {
|
||||
|
||||
@@ -1,17 +1,63 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/http/api.dart';
|
||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
|
||||
class ApiInterceptor extends Interceptor {
|
||||
// @override
|
||||
// void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
// debugPrint("请求之前");
|
||||
// // 在请求之前添加头部或认证信息
|
||||
// options.headers['Authorization'] = 'Bearer token';
|
||||
// options.headers['Content-Type'] = 'application/json';
|
||||
// handler.next(options);
|
||||
// }
|
||||
static const List<String> anonymityList = [
|
||||
Api.videoUrl,
|
||||
Api.videoIntro,
|
||||
Api.relatedList,
|
||||
Api.replyList,
|
||||
Api.replyReplyList,
|
||||
Api.searchSuggest,
|
||||
Api.searchByType,
|
||||
Api.heartBeat,
|
||||
Api.ab2c,
|
||||
Api.bangumiInfo,
|
||||
Api.liveRoomInfo,
|
||||
Api.onlineTotal,
|
||||
Api.webDanmaku,
|
||||
Api.dynamicDetail,
|
||||
Api.aiConclusion,
|
||||
Api.getSeasonDetailApi,
|
||||
Api.liveRoomDmToken,
|
||||
Api.liveRoomDmPrefetch,
|
||||
];
|
||||
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
if (MineController.anonymity.value) {
|
||||
String uri = options.uri.toString();
|
||||
for (var i in anonymityList) {
|
||||
// 如果请求的url包含无痕列表中的url,则清空cookie
|
||||
// 但需要保证匹配到url的后半部分不再出现/符号,否则会误伤
|
||||
int index = uri.indexOf(i);
|
||||
if (index == -1) continue;
|
||||
if (uri.lastIndexOf('/') >= index + i.length) continue;
|
||||
//SmartDialog.showToast('触发无痕模式\n\n$i\n\n${options.uri}');
|
||||
options.headers[HttpHeaders.cookieHeader] = "";
|
||||
if (options.data != null && options.data.csrf != null) {
|
||||
options.data.csrf = "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (options.extra['clearCookie'] == true) {
|
||||
options.headers['x-bili-mid'] = '';
|
||||
options.headers['x-bili-aurora-eid'] = '';
|
||||
options.headers['x-bili-aurora-zone'] = '';
|
||||
options.headers[HttpHeaders.cookieHeader] = '';
|
||||
if (options.data != null && options.data.csrf != null) {
|
||||
options.data.csrf = '';
|
||||
}
|
||||
}
|
||||
handler.next(options);
|
||||
}
|
||||
|
||||
// @override
|
||||
// void onResponse(Response response, ResponseInterceptorHandler handler) {
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
// ignore_for_file: avoid_print
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
// import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import '../pages/mine/controller.dart';
|
||||
import 'api.dart';
|
||||
|
||||
class AnonymityInterceptor extends Interceptor {
|
||||
static const List<String> anonymityList = [
|
||||
Api.videoUrl,
|
||||
Api.videoIntro,
|
||||
Api.relatedList,
|
||||
Api.replyList,
|
||||
Api.replyReplyList,
|
||||
Api.searchSuggest,
|
||||
Api.searchByType,
|
||||
Api.heartBeat,
|
||||
Api.ab2c,
|
||||
Api.bangumiInfo,
|
||||
Api.liveRoomInfo,
|
||||
Api.onlineTotal,
|
||||
Api.webDanmaku,
|
||||
Api.dynamicDetail,
|
||||
Api.aiConclusion,
|
||||
Api.getSeasonDetailApi,
|
||||
Api.liveRoomDmToken,
|
||||
Api.liveRoomDmPrefetch,
|
||||
];
|
||||
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
if (MineController.anonymity.value) {
|
||||
String uri = options.uri.toString();
|
||||
for (var i in anonymityList) {
|
||||
// 如果请求的url包含无痕列表中的url,则清空cookie
|
||||
// 但需要保证匹配到url的后半部分不再出现/符号,否则会误伤
|
||||
int index = uri.indexOf(i);
|
||||
if (index == -1) continue;
|
||||
if (uri.lastIndexOf('/') >= index + i.length) continue;
|
||||
//SmartDialog.showToast('触发无痕模式\n\n$i\n\n${options.uri}');
|
||||
options.headers[HttpHeaders.cookieHeader] = "";
|
||||
if (options.data != null && options.data.csrf != null) {
|
||||
options.data.csrf = "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
handler.next(options);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPlus/grpc/grpc_repo.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
@@ -12,6 +10,8 @@ import 'api.dart';
|
||||
import 'init.dart';
|
||||
|
||||
class ReplyHttp {
|
||||
static Options get _options => Options(extra: {'clearCookie': true});
|
||||
|
||||
static Future<LoadingState> replyList({
|
||||
required bool isLogin,
|
||||
required int oid,
|
||||
@@ -21,10 +21,6 @@ class ReplyHttp {
|
||||
int sort = 1,
|
||||
required String banWordForReply,
|
||||
}) async {
|
||||
Options? options = !isLogin
|
||||
? Options(
|
||||
headers: {HttpHeaders.cookieHeader: "buvid3= ; b_nut= ; sid= "})
|
||||
: null;
|
||||
var res = !isLogin
|
||||
? await Request().get(
|
||||
'${Api.replyList}/main',
|
||||
@@ -35,7 +31,7 @@ class ReplyHttp {
|
||||
'{"offset":"${nextOffset.replaceAll('"', '\\"')}"}',
|
||||
'mode': sort + 2, //2:按时间排序;3:按热度排序
|
||||
},
|
||||
options: options,
|
||||
options: isLogin.not ? _options : null,
|
||||
)
|
||||
: await Request().get(
|
||||
Api.replyList,
|
||||
@@ -46,7 +42,7 @@ class ReplyHttp {
|
||||
'pn': page,
|
||||
'ps': 20,
|
||||
},
|
||||
options: options,
|
||||
options: isLogin.not ? _options : null,
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
ReplyData replyData = ReplyData.fromJson(res.data['data']);
|
||||
@@ -140,10 +136,6 @@ class ReplyHttp {
|
||||
required String banWordForReply,
|
||||
bool? isCheck,
|
||||
}) async {
|
||||
Options? options = isLogin.not
|
||||
? Options(
|
||||
headers: {HttpHeaders.cookieHeader: "buvid3= ; b_nut= ; sid= "})
|
||||
: null;
|
||||
var res = await Request().get(
|
||||
Api.replyReplyList,
|
||||
queryParameters: {
|
||||
@@ -154,7 +146,7 @@ class ReplyHttp {
|
||||
'sort': 1,
|
||||
if (isLogin) 'csrf': await Request.getCsrf(),
|
||||
},
|
||||
options: options,
|
||||
options: isLogin.not ? _options : null,
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
ReplyReplyData replyData = ReplyReplyData.fromJson(res.data['data']);
|
||||
|
||||
@@ -345,7 +345,7 @@ abstract class ReplyController extends CommonController {
|
||||
dynamic res1 = await ReplyHttp.replyReplyList(
|
||||
isLogin: isLogin,
|
||||
oid: oid,
|
||||
root: rpid,
|
||||
root: rpid ?? replyId,
|
||||
pageNum: 1,
|
||||
type: replyType,
|
||||
banWordForReply: '',
|
||||
@@ -365,7 +365,7 @@ abstract class ReplyController extends CommonController {
|
||||
dynamic res2 = await ReplyHttp.replyReplyList(
|
||||
isLogin: false,
|
||||
oid: oid,
|
||||
root: rpid,
|
||||
root: rpid ?? replyId,
|
||||
pageNum: 1,
|
||||
type: replyType,
|
||||
banWordForReply: '',
|
||||
@@ -401,7 +401,7 @@ https://api.bilibili.com/x/v2/reply/reply?oid=$oid&pn=1&ps=20&root=$rpid&type=$r
|
||||
dynamic res3 = await ReplyHttp.replyReplyList(
|
||||
isLogin: false,
|
||||
oid: oid,
|
||||
root: rpid,
|
||||
root: rpid ?? replyId,
|
||||
pageNum: i,
|
||||
type: replyType,
|
||||
banWordForReply: '',
|
||||
@@ -435,7 +435,7 @@ https://api.bilibili.com/x/v2/reply/reply?oid=$oid&pn=1&ps=20&root=$rpid&type=$r
|
||||
dynamic res4 = await ReplyHttp.replyReplyList(
|
||||
isLogin: true,
|
||||
oid: oid,
|
||||
root: rpid,
|
||||
root: rpid ?? replyId,
|
||||
pageNum: i,
|
||||
type: replyType,
|
||||
banWordForReply: '',
|
||||
|
||||
@@ -66,17 +66,7 @@ class _SponsorBlockPageState extends State<SponsorBlockPage> {
|
||||
Request()
|
||||
.get(
|
||||
'$_blockServer/api/status/uptime',
|
||||
options: Options(
|
||||
headers: {
|
||||
'env': '',
|
||||
'app-key': '',
|
||||
'x-bili-mid': '',
|
||||
'x-bili-aurora-eid': '',
|
||||
'x-bili-aurora-zone': '',
|
||||
'cookie':
|
||||
'buvid3= ; SESSDATA= ; bili_jct= ; DedeUserID= ; DedeUserID__ckMd5= ; sid= ',
|
||||
},
|
||||
),
|
||||
options: Options(extra: {'clearCookie': true}),
|
||||
)
|
||||
.then((res) {
|
||||
setState(() {
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart'
|
||||
show kDragContainerExtentPercentage, displacement;
|
||||
import 'package:PiliPlus/http/interceptor_anonymity.dart';
|
||||
import 'package:PiliPlus/http/interceptor.dart';
|
||||
import 'package:PiliPlus/models/common/audio_normalization.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic_badge_mode.dart';
|
||||
import 'package:PiliPlus/models/common/dynamics_type.dart';
|
||||
@@ -1359,7 +1359,7 @@ List<SettingsModel> get privacySettings => [
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('查看详情'),
|
||||
content: Text(AnonymityInterceptor.anonymityList.join('\n')),
|
||||
content: Text(ApiInterceptor.anonymityList.join('\n')),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
|
||||
@@ -619,17 +619,7 @@ class VideoDetailController extends GetxController
|
||||
);
|
||||
}
|
||||
|
||||
Options get _options => Options(
|
||||
headers: {
|
||||
'env': '',
|
||||
'app-key': '',
|
||||
'x-bili-mid': '',
|
||||
'x-bili-aurora-eid': '',
|
||||
'x-bili-aurora-zone': '',
|
||||
HttpHeaders.cookieHeader:
|
||||
'buvid3= ; SESSDATA= ; bili_jct= ; DedeUserID= ; DedeUserID__ckMd5= ; sid= ',
|
||||
},
|
||||
);
|
||||
Options get _options => Options(extra: {'clearCookie': true});
|
||||
|
||||
Future _querySponsorBlock() async {
|
||||
positionSubscription?.cancel();
|
||||
|
||||
Reference in New Issue
Block a user