mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
like a comic
This commit is contained in:
@@ -3,7 +3,6 @@ library comic_source;
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
@@ -45,6 +44,8 @@ typedef GetThumbnailLoadingConfigFunc = Map<String, dynamic> Function(
|
||||
|
||||
typedef ComicThumbnailLoader = Future<Res<List<String>>> Function(String comicId, String? next);
|
||||
|
||||
typedef LikeOrUnlikeComicFunc = Future<Res<bool>> Function(String comicId, bool isLiking);
|
||||
|
||||
class ComicSource {
|
||||
static final List<ComicSource> _sources = [];
|
||||
|
||||
@@ -171,6 +172,8 @@ class ComicSource {
|
||||
|
||||
final RegExp? idMatcher;
|
||||
|
||||
final LikeOrUnlikeComicFunc? likeOrUnlikeComic;
|
||||
|
||||
Future<void> loadData() async {
|
||||
var file = File("${App.dataPath}/comic_source/$key.data");
|
||||
if (await file.exists()) {
|
||||
@@ -229,7 +232,8 @@ class ComicSource {
|
||||
this.url,
|
||||
this.version,
|
||||
this.commentsLoader,
|
||||
this.sendCommentFunc)
|
||||
this.sendCommentFunc,
|
||||
this.likeOrUnlikeComic)
|
||||
: idMatcher = null;
|
||||
|
||||
ComicSource.unknown(this.key)
|
||||
@@ -252,7 +256,8 @@ class ComicSource {
|
||||
version = "",
|
||||
commentsLoader = null,
|
||||
sendCommentFunc = null,
|
||||
idMatcher = null;
|
||||
idMatcher = null,
|
||||
likeOrUnlikeComic = null;
|
||||
}
|
||||
|
||||
class AccountConfig {
|
||||
|
@@ -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());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user