feat: fav article page

Closes #402

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-03-29 14:38:13 +08:00
parent 72fa9c51f0
commit 5dc8b8e54f
9 changed files with 373 additions and 9 deletions

View File

@@ -735,4 +735,13 @@ class Api {
static const String delPublishNote = '/x/note/publish/del';
static const String archiveNote = '/x/note/list/archive';
static const String favArticle = '/x/polymer/web-dynamic/v1/opus/feed/fav';
static const String communityAction =
'/x/community/cosmo/interface/simple_action';
static const String delFavArticle = '/x/article/favorites/del';
static const String addFavArticle = '/x/article/favorites/add';
}

View File

@@ -468,6 +468,84 @@ class UserHttp {
}
}
static Future<LoadingState> favArticle({
required int page,
}) async {
var res = await Request().get(Api.favArticle, queryParameters: {
'page_size': 20,
'page': page,
});
if (res.data['code'] == 0) {
return LoadingState.success(res.data['data']?['items']);
} else {
return LoadingState.error(res.data['message']);
}
}
static Future addFavArticle({
required int id,
}) async {
var res = await Request().post(
Api.addFavArticle,
data: {
'id': id,
'csrf': await Request.getCsrf(),
},
options: Options(
contentType: Headers.formUrlEncodedContentType,
),
);
if (res.data['code'] == 0) {
return {'status': true};
} else {
return {'status': false, 'msg': res.data['message']};
}
}
static Future delFavArticle({
required int id,
}) async {
var res = await Request().post(
Api.delFavArticle,
data: {
'id': id,
'csrf': await Request.getCsrf(),
},
options: Options(
contentType: Headers.formUrlEncodedContentType,
),
);
if (res.data['code'] == 0) {
return {'status': true};
} else {
return {'status': false, 'msg': res.data['message']};
}
}
static Future communityAction({
required dynamic opusId,
required dynamic action,
}) async {
var res = await Request().post(
Api.communityAction,
queryParameters: {
'csrf': await Request.getCsrf(),
},
data: {
"entity": {
"object_id_str": opusId,
"type": {"biz": 2}
},
"action": action, // 3 fav, 4 unfav
},
);
if (res.data['code'] == 0) {
return {'status': true};
} else {
return {'status': false, 'msg': res.data['message']};
}
}
static Future favResourceList({
required int id,
required int pn,