like a comic

This commit is contained in:
nyne
2024-10-05 08:56:06 +08:00
parent 07dbf6e6af
commit 771feeeaa8
4 changed files with 65 additions and 14 deletions

View File

@@ -136,6 +136,7 @@ class ComicSourceParser {
final favoriteData = _loadFavoriteData();
final commentsLoader = _parseCommentsLoader();
final sendCommentFunc = _parseSendCommentFunc();
final likeFunc = _parseLikeFunc();
var source = ComicSource(
_name!,
@@ -158,6 +159,7 @@ class ComicSourceParser {
version ?? "1.0.0",
commentsLoader,
sendCommentFunc,
likeFunc,
);
await source.loadData();
@@ -654,4 +656,21 @@ class ComicSourceParser {
}
};
}
LikeOrUnlikeComicFunc? _parseLikeFunc() {
if (!_checkExists("comic.likeOrUnlikeComic")) {
return null;
}
return (id, isLiking) async {
try {
await JsEngine().runCode("""
ComicSource.sources.$_key.comic.likeOrUnlikeComic(${jsonEncode(id)}, ${jsonEncode(isLiking)})
""");
return const Res(true);
} catch (e, s) {
Log.error("Network", "$e\n$s");
return Res.error(e.toString());
}
};
}
}