mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: reply request
This commit is contained in:
@@ -129,7 +129,7 @@ class Api {
|
|||||||
|
|
||||||
// 评论列表
|
// 评论列表
|
||||||
// https://api.bilibili.com/x/v2/reply/main?csrf=6e22efc1a47225ea25f901f922b5cfdd&mode=3&oid=254175381&pagination_str=%7B%22offset%22:%22%22%7D&plat=1&seek_rpid=0&type=11
|
// https://api.bilibili.com/x/v2/reply/main?csrf=6e22efc1a47225ea25f901f922b5cfdd&mode=3&oid=254175381&pagination_str=%7B%22offset%22:%22%22%7D&plat=1&seek_rpid=0&type=11
|
||||||
static const String replyList = '/x/v2/reply/main';
|
static const String replyList = '/x/v2/reply';
|
||||||
|
|
||||||
// 楼中楼
|
// 楼中楼
|
||||||
static const String replyReplyList = '/x/v2/reply/reply';
|
static const String replyReplyList = '/x/v2/reply/reply';
|
||||||
|
|||||||
@@ -12,25 +12,40 @@ import 'init.dart';
|
|||||||
|
|
||||||
class ReplyHttp {
|
class ReplyHttp {
|
||||||
static Future<LoadingState> replyList({
|
static Future<LoadingState> replyList({
|
||||||
|
required bool isLogin,
|
||||||
required int oid,
|
required int oid,
|
||||||
required String nextOffset,
|
required String nextOffset,
|
||||||
required int type,
|
required int type,
|
||||||
|
required int page,
|
||||||
int sort = 1,
|
int sort = 1,
|
||||||
}) async {
|
}) async {
|
||||||
Options? options = GStorage.userInfo.get('userInfoCache') == null
|
Options? options = !isLogin
|
||||||
? Options(
|
? Options(
|
||||||
headers: {HttpHeaders.cookieHeader: "buvid3= ; b_nut= ; sid= "})
|
headers: {HttpHeaders.cookieHeader: "buvid3= ; b_nut= ; sid= "})
|
||||||
: null;
|
: null;
|
||||||
var res = await Request().get(
|
var res = !isLogin
|
||||||
'${HttpString.apiBaseUrl}${Api.replyList}',
|
? await Request().get(
|
||||||
data: {
|
'${HttpString.apiBaseUrl}${Api.replyList}/main',
|
||||||
'oid': oid,
|
data: {
|
||||||
'type': type,
|
'oid': oid,
|
||||||
'pagination_str': '{"offset":"${nextOffset.replaceAll('"', '\\"')}"}',
|
'type': type,
|
||||||
'mode': sort + 2, //2:按时间排序;3:按热度排序
|
'pagination_str':
|
||||||
},
|
'{"offset":"${nextOffset.replaceAll('"', '\\"')}"}',
|
||||||
options: options,
|
'mode': sort + 2, //2:按时间排序;3:按热度排序
|
||||||
);
|
},
|
||||||
|
options: options,
|
||||||
|
)
|
||||||
|
: await Request().get(
|
||||||
|
'${HttpString.apiBaseUrl}${Api.replyList}',
|
||||||
|
data: {
|
||||||
|
'oid': oid,
|
||||||
|
'type': type,
|
||||||
|
'sort': sort,
|
||||||
|
'pn': page,
|
||||||
|
'ps': 20,
|
||||||
|
},
|
||||||
|
options: options,
|
||||||
|
);
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
return LoadingState.success(ReplyData.fromJson(res.data['data']));
|
return LoadingState.success(ReplyData.fromJson(res.data['data']));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'upper.dart';
|
|||||||
|
|
||||||
class ReplyData {
|
class ReplyData {
|
||||||
ReplyData({
|
ReplyData({
|
||||||
|
this.page,
|
||||||
this.cursor,
|
this.cursor,
|
||||||
this.config,
|
this.config,
|
||||||
this.replies,
|
this.replies,
|
||||||
@@ -13,6 +14,7 @@ class ReplyData {
|
|||||||
this.upper,
|
this.upper,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ReplyPage? page;
|
||||||
ReplyCursor? cursor;
|
ReplyCursor? cursor;
|
||||||
ReplyConfig? config;
|
ReplyConfig? config;
|
||||||
late List<ReplyItemModel>? replies;
|
late List<ReplyItemModel>? replies;
|
||||||
@@ -20,20 +22,21 @@ class ReplyData {
|
|||||||
ReplyUpper? upper;
|
ReplyUpper? upper;
|
||||||
|
|
||||||
ReplyData.fromJson(Map<String, dynamic> json) {
|
ReplyData.fromJson(Map<String, dynamic> json) {
|
||||||
cursor = ReplyCursor.fromJson(json['cursor']);
|
page = json['page'] == null ? null : ReplyPage.fromJson(json['page']);
|
||||||
config = ReplyConfig.fromJson(json['config']);
|
cursor =
|
||||||
|
json['cursor'] == null ? null : ReplyCursor.fromJson(json['cursor']);
|
||||||
|
config =
|
||||||
|
json['config'] == null ? null : ReplyConfig.fromJson(json['config']);
|
||||||
replies = json['replies'] != null
|
replies = json['replies'] != null
|
||||||
? List<ReplyItemModel>.from(json['replies']
|
? List<ReplyItemModel>.from(json['replies'].map<ReplyItemModel>(
|
||||||
.map<ReplyItemModel>(
|
(item) => ReplyItemModel.fromJson(item, json['upper']['mid'])))
|
||||||
(item) => ReplyItemModel.fromJson(item, json['upper']['mid'])))
|
|
||||||
: <ReplyItemModel>[];
|
: <ReplyItemModel>[];
|
||||||
topReplies = json['top_replies'] != null
|
topReplies = json['top_replies'] != null
|
||||||
? List<ReplyItemModel>.from(json['top_replies']
|
? List<ReplyItemModel>.from(json['top_replies'].map<ReplyItemModel>(
|
||||||
.map<ReplyItemModel>((item) => ReplyItemModel.fromJson(
|
(item) => ReplyItemModel.fromJson(item, json['upper']['mid'],
|
||||||
item, json['upper']['mid'],
|
|
||||||
isTopStatus: true)))
|
isTopStatus: true)))
|
||||||
: <ReplyItemModel>[];
|
: <ReplyItemModel>[];
|
||||||
upper = ReplyUpper.fromJson(json['upper']);
|
upper = json['upper'] == null ? null : ReplyUpper.fromJson(json['upper']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,15 +61,13 @@ class ReplyReplyData {
|
|||||||
page = ReplyPage.fromJson(json['page']);
|
page = ReplyPage.fromJson(json['page']);
|
||||||
config = ReplyConfig.fromJson(json['config']);
|
config = ReplyConfig.fromJson(json['config']);
|
||||||
replies = json['replies'] != null
|
replies = json['replies'] != null
|
||||||
? List<ReplyItemModel>.from(json['replies']
|
? List<ReplyItemModel>.from(json['replies'].map<ReplyItemModel>(
|
||||||
.map<ReplyItemModel>(
|
|
||||||
(item) => ReplyItemModel.fromJson(item, json['upper']['mid'])))
|
(item) => ReplyItemModel.fromJson(item, json['upper']['mid'])))
|
||||||
: <ReplyItemModel>[];
|
: <ReplyItemModel>[];
|
||||||
topReplies = json['top_replies'] != null
|
topReplies = json['top_replies'] != null
|
||||||
? List<ReplyItemModel>.from(json['top_replies']
|
? List<ReplyItemModel>.from(json['top_replies'].map<ReplyItemModel>(
|
||||||
.map<ReplyItemModel>((item) => ReplyItemModel.fromJson(
|
(item) => ReplyItemModel.fromJson(item, json['upper']['mid'],
|
||||||
item, json['upper']['mid'],
|
isTopStatus: true)))
|
||||||
isTopStatus: true)))
|
|
||||||
: <ReplyItemModel>[];
|
: <ReplyItemModel>[];
|
||||||
upper = ReplyUpper.fromJson(json['upper']);
|
upper = ReplyUpper.fromJson(json['upper']);
|
||||||
root = ReplyItemModel.fromJson(json['root'], json['upper']['mid']);
|
root = ReplyItemModel.fromJson(json['root'], json['upper']['mid']);
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ abstract class ReplyController extends CommonController {
|
|||||||
|
|
||||||
late final savedReplies = {};
|
late final savedReplies = {};
|
||||||
|
|
||||||
|
bool isLogin = GStorage.userInfo.get('userInfoCache') != null;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
@@ -55,7 +57,9 @@ abstract class ReplyController extends CommonController {
|
|||||||
@override
|
@override
|
||||||
bool customHandleResponse(Success response) {
|
bool customHandleResponse(Success response) {
|
||||||
List<ReplyItemModel> replies = response.response.replies;
|
List<ReplyItemModel> replies = response.response.replies;
|
||||||
nextOffset = response.response.cursor.paginationReply.nextOffset ?? "";
|
if (!isLogin) {
|
||||||
|
nextOffset = response.response.cursor.paginationReply.nextOffset ?? "";
|
||||||
|
}
|
||||||
if (replies.isNotEmpty) {
|
if (replies.isNotEmpty) {
|
||||||
noMore.value = '加载中...';
|
noMore.value = '加载中...';
|
||||||
|
|
||||||
@@ -78,7 +82,9 @@ abstract class ReplyController extends CommonController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
replies.insertAll(0, response.response.topReplies);
|
replies.insertAll(0, response.response.topReplies);
|
||||||
count.value = response.response.cursor.allCount ?? 0;
|
count.value = !isLogin
|
||||||
|
? response.response.cursor.allCount
|
||||||
|
: response.response.page.count ?? 0;
|
||||||
} else {
|
} else {
|
||||||
replies.insertAll(
|
replies.insertAll(
|
||||||
0,
|
0,
|
||||||
|
|||||||
@@ -34,9 +34,11 @@ class DynamicDetailController extends ReplyController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<LoadingState> customGetData() => ReplyHttp.replyList(
|
Future<LoadingState> customGetData() => ReplyHttp.replyList(
|
||||||
|
isLogin: isLogin,
|
||||||
oid: oid!,
|
oid: oid!,
|
||||||
nextOffset: nextOffset,
|
nextOffset: nextOffset,
|
||||||
type: type!,
|
type: type!,
|
||||||
sort: sortType.index,
|
sort: sortType.index,
|
||||||
|
page: currentPage,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,9 +42,11 @@ class HtmlRenderController extends ReplyController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<LoadingState> customGetData() => ReplyHttp.replyList(
|
Future<LoadingState> customGetData() => ReplyHttp.replyList(
|
||||||
|
isLogin: isLogin,
|
||||||
oid: oid.value,
|
oid: oid.value,
|
||||||
nextOffset: nextOffset,
|
nextOffset: nextOffset,
|
||||||
type: type,
|
type: type,
|
||||||
sort: sortType.index,
|
sort: sortType.index,
|
||||||
|
page: currentPage,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,11 @@ class VideoReplyController extends ReplyController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<LoadingState> customGetData() => ReplyHttp.replyList(
|
Future<LoadingState> customGetData() => ReplyHttp.replyList(
|
||||||
|
isLogin: isLogin,
|
||||||
oid: aid!,
|
oid: aid!,
|
||||||
nextOffset: nextOffset,
|
nextOffset: nextOffset,
|
||||||
type: ReplyType.video.index,
|
type: ReplyType.video.index,
|
||||||
sort: sortType.index,
|
sort: sortType.index,
|
||||||
|
page: currentPage,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user