Skip to content

Commit

Permalink
v8.0.6+274
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangtian616 committed Jan 3, 2025
1 parent 13671b7 commit b851321
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 4 deletions.
9 changes: 9 additions & 0 deletions changelog/v8.0.6+274.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- 内置屏蔽用户名单
- 优化内置ip
- 修复里站无法快速屏蔽评论区用户的bug

--------------------

- Built-in block user list
- Optimize built-in IP
- Fix bug that can't block users from comments in EX site
1 change: 1 addition & 0 deletions lib/src/enum/config_enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum ConfigEnum {
oldGalleryHistory('history'),
searchHistory('searchHistory'),
myTagsSetting('MyTagsSetting'),
builtInBlockedUser('builtInBlockedUser'),

/// page config
downloadPageBodyType('downloadPageGalleryType'),
Expand Down
2 changes: 2 additions & 0 deletions lib/src/l18n/en_US.dart
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ class en_US {
'removeBlockRuleFailed': 'Remove block rule failed',
'inputNumberHint': 'Please input a correct number',
'inputRegexHint': 'Please input a correct regex',
'useBuiltInBlockedUsers': 'Enable Built-in User Blocklist',
'useBuiltInBlockedUsersHint': 'Filter out gallery comments from users on the blocklist',
'blockingRules': 'Block Rules',
'blockingRulesHint': 'Additional blocking rules for gallerys and comments',
'blockingTarget': 'Blocking Target',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/l18n/ko_KR.dart
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ class ko_KR {
'removeBlockRuleFailed': 'Remove block rule failed',
'inputNumberHint': 'Please input a correct number',
'inputRegexHint': 'Please input a correct regex',
'useBuiltInBlockedUsers': 'Enable Built-in User Blocklist',
'useBuiltInBlockedUsersHint': 'Filter out gallery comments from users on the blocklist',
'blockingRules': 'Block Rules',
'blockingRulesHint': 'Additional blocking rules for gallerys and comments',
'blockingTarget': 'Blocking Target',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/l18n/pt_BR.dart
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,8 @@ class pt_BR {
'removeBlockRuleFailed': 'Remove block rule failed',
'inputNumberHint': 'Please input a correct number',
'inputRegexHint': 'Please input a correct regex',
'useBuiltInBlockedUsers': 'Enable Built-in User Blocklist',
'useBuiltInBlockedUsersHint': 'Filter out gallery comments from users on the blocklist',
'blockingRules': 'Block Rules',
'blockingRulesHint': 'Additional blocking rules for gallerys and comments',
'blockingTarget': 'Blocking Target',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/l18n/zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ favnote:匹配收藏备注
'removeBlockRuleFailed': '删除屏蔽规则失败',
'inputNumberHint': '请输入正确的数字',
'inputRegexHint': '请输入合法的正则表达式',
'useBuiltInBlockedUsers': '使用内置用户屏蔽名单',
'useBuiltInBlockedUsersHint': '过滤掉在名单中的用户评论',
'blockingRules': '屏蔽规则',
'blockingRulesHint': '针对画廊和评论设置额外的屏蔽规则',
'blockingTarget': '屏蔽目标',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/l18n/zh_TW.dart
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ favnote:配對收藏備註
'removeBlockRuleFailed': '刪除隱藏規則失敗',
'inputNumberHint': '請輸入正確的數字',
'inputRegexHint': '請輸入合法的正規表示式',
'useBuiltInBlockedUsers': '使用內置用戶屏蔽名單',
'useBuiltInBlockedUsersHint': '過濾掉在名單中的用戶評論',
'blockingRules': '隱藏規則',
'blockingRulesHint': '針對畫廊和評論設定額外的隱藏規則',
'blockingTarget': '隱藏目標',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:jhentai/src/network/eh_request.dart';
import 'package:jhentai/src/network/jh_request.dart';
import 'package:jhentai/src/service/app_update_service.dart';
import 'package:jhentai/src/service/archive_download_service.dart';
import 'package:jhentai/src/service/built_in_blocked_user_service.dart';
import 'package:jhentai/src/service/cloud_service.dart';
import 'package:jhentai/src/service/frame_rate_service.dart';
import 'package:jhentai/src/service/gallery_download_service.dart';
Expand Down Expand Up @@ -89,6 +90,7 @@ List<JHLifeCircleBean> lifeCircleBeans = [
styleSetting,
superResolutionSetting,
userSetting,
builtInBlockedUserService,
];

void main(List<String> args) async {
Expand Down
27 changes: 26 additions & 1 deletion lib/src/pages/setting/preference/setting_preference_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:get/get.dart';
import 'package:jhentai/src/extension/widget_extension.dart';
import 'package:jhentai/src/model/tab_bar_icon.dart';
import 'package:jhentai/src/service/tag_search_order_service.dart';
import 'package:url_launcher/url_launcher_string.dart';

import '../../../consts/locale_consts.dart';
import '../../../l18n/locale_text.dart';
Expand Down Expand Up @@ -51,6 +52,7 @@ class SettingPreferencePage extends StatelessWidget {
_buildShowUtcTime(),
_buildShowDawnInfo(),
_buildShowEncounterMonster(),
_buildUseBuiltInBlockedUsers(),
_buildBlockRules(),
],
).withListTileTheme(context),
Expand Down Expand Up @@ -427,12 +429,35 @@ class SettingPreferencePage extends StatelessWidget {
onChanged: preferenceSetting.saveShowDawnInfo,
);
}

Widget _buildShowEncounterMonster() {
return SwitchListTile(
title: Text('showEncounterMonster'.tr),
value: preferenceSetting.showHVInfo.value,
onChanged: preferenceSetting.saveShowHVInfo,
);
}

Widget _buildUseBuiltInBlockedUsers() {
return ListTile(
title: Text('useBuiltInBlockedUsers'.tr),
subtitle: Text('useBuiltInBlockedUsersHint'.tr),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.help),
onPressed: () => launchUrlString(
'https://raw.githubusercontent.com/jiangtian616/JHenTai/refs/heads/master/built_in_blocked_user.json',
mode: LaunchMode.externalApplication,
),
),
Switch(
value: preferenceSetting.useBuiltInBlockedUsers.value,
onChanged: preferenceSetting.saveUseBuiltInBlockedUsers,
)
],
),
);
}
}
107 changes: 107 additions & 0 deletions lib/src/service/built_in_blocked_user_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:get/get.dart';
import 'package:jhentai/src/enum/config_enum.dart';
import 'package:jhentai/src/setting/preference_setting.dart';
import 'package:jhentai/src/utils/eh_spider_parser.dart';
import 'package:retry/retry.dart';

import '../network/eh_request.dart';
import 'jh_service.dart';
import 'local_block_rule_service.dart';
import 'log.dart';

BuiltInBlockedUserService builtInBlockedUserService = BuiltInBlockedUserService();

typedef EHUser = ({int userId, String name});

class BuiltInBlockedUserService with JHLifeCircleBeanWithConfigStorage implements JHLifeCircleBean, ExtraBlockRuleProvider {
final RxList<EHUser> _blockedUsers = RxList();

List<EHUser> get blockedUsers => _blockedUsers.toList();

@override
ConfigEnum get configEnum => ConfigEnum.builtInBlockedUser;

@override
List<JHLifeCircleBean> get initDependencies => super.initDependencies..addAll([localBlockRuleService]);

@override
void applyBeanConfig(String configString) {
List list = jsonDecode(configString);
if (list.isNotEmpty) {
_blockedUsers.value = list.map((map) => (userId: map['userId'] as int, name: map['name'] as String)).toList();
}
}

@override
String toConfigString() {
return jsonEncode(_blockedUsers.map((user) => {'userId': user.userId, 'name': user.name}).toList());
}

@override
Future<void> doInitBean() async {
localBlockRuleService.registerExtraBlockRuleProvider(this);
}

@override
Future<void> doAfterBeanReady() async {
String json;
try {
json = await retry(
() => ehRequest.get(
url: 'https://raw.githubusercontent.com/jiangtian616/JHenTai/refs/heads/master/built_in_blocked_user.json',
parser: simpleParser,
),
maxAttempts: 5,
onRetry: (error) => log.warning('Get built-in blocked user data failed, retrying', error),
);
} on DioException catch (e) {
log.error('Get built-in blocked user data failed after 5 times', e);
return;
}

Map map = jsonDecode(json);
if (map.isEmpty) {
log.warning('Built-in blocked user data is empty');
return;
}

int version = map['version'] as int;
int formatVersion = map['formatVersion'] as int;
String updateTime = map['updateTime'] as String;
List<EHUser> users = (map['blockedUsers'] as List).map((map) => (userId: map['userId'] as int, name: map['name'] as String)).toList();

log.info('Built-in blocked user data loaded, version: $version, formatVersion: $formatVersion, updateTime: $updateTime, user count: ${users.length}');

_blockedUsers.value = users;

saveBeanConfig();
}

@override
LocalBlockTargetEnum get target => LocalBlockTargetEnum.comment;

@override
Map<String, List<LocalBlockRule>> get extraGroupedRules => preferenceSetting.useBuiltInBlockedUsers.isTrue
? {
'userIdGroup': _blockedUsers
.map((user) => LocalBlockRule(
target: LocalBlockTargetEnum.comment,
attribute: LocalBlockAttributeEnum.userId,
pattern: LocalBlockPatternEnum.equal,
expression: user.userId.toString(),
))
.toList(),
'nameGroup': _blockedUsers
.map((user) => LocalBlockRule(
target: LocalBlockTargetEnum.comment,
attribute: LocalBlockAttributeEnum.userName,
pattern: LocalBlockPatternEnum.equal,
expression: user.name,
))
.toList(),
}
: {};
}
34 changes: 33 additions & 1 deletion lib/src/service/local_block_rule_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ import 'log.dart';

LocalBlockRuleService localBlockRuleService = LocalBlockRuleService();

abstract interface class ExtraBlockRuleProvider {
LocalBlockTargetEnum get target;

Map<String, List<LocalBlockRule>> get extraGroupedRules;
}

class LocalBlockRuleService with JHLifeCircleBeanErrorCatch implements JHLifeCircleBean {
final List<LocalBlockRuleHandler> handlers = [];
final List<ExtraBlockRuleProvider> extraBlockRuleProviders = [];

@override
Future<void> doInitBean() async {
Expand Down Expand Up @@ -48,6 +55,14 @@ class LocalBlockRuleService with JHLifeCircleBeanErrorCatch implements JHLifeCir

LocalBlockRuleHandler getHandlerByRule(LocalBlockRule rule) => handlers.where((h) => h.matchRule(rule)).sorted((a, b) => a.order - b.order).first;

void registerExtraBlockRuleProvider(ExtraBlockRuleProvider provider) {
extraBlockRuleProviders.add(provider);
}

void unregisterExtraBlockRuleProvider(ExtraBlockRuleProvider provider) {
extraBlockRuleProviders.remove(provider);
}

Future<List<LocalBlockRule>> getBlockRules() async {
List<BlockRuleData> datas = await BlockRuleDao.selectBlockRules();
return datas
Expand Down Expand Up @@ -167,6 +182,22 @@ class LocalBlockRuleService with JHLifeCircleBeanErrorCatch implements JHLifeCir
return hit;
});
});

for (ExtraBlockRuleProvider provider in extraBlockRuleProviders) {
if (provider.target == targetEnum) {
Map<String, List<LocalBlockRule>> extraGroupedRules = provider.extraGroupedRules;
extraGroupedRules.forEach((groupId, rules) {
results.removeWhere((item) {
bool hit = true;
for (LocalBlockRule rule in rules) {
LocalBlockRuleHandler handler = getHandlerByRule(rule);
hit = hit && handler.executeRule(item, rule);
}
return hit;
});
});
}
}
} catch (e) {
log.error('executeRules failed, items:$items', e);
}
Expand Down Expand Up @@ -617,7 +648,8 @@ enum LocalBlockPatternEnum {

const LocalBlockPatternEnum(this.code, this.attributes, this.desc);

static List<LocalBlockPatternEnum> withAttribute(LocalBlockAttributeEnum? attribute) => LocalBlockPatternEnum.values.where((e) => e.attributes.contains(attribute)).toList();
static List<LocalBlockPatternEnum> withAttribute(LocalBlockAttributeEnum? attribute) =>
LocalBlockPatternEnum.values.where((e) => e.attributes.contains(attribute)).toList();

static LocalBlockPatternEnum fromCode(int code) {
return LocalBlockPatternEnum.values.where((e) => e.code == code).first;
Expand Down
11 changes: 10 additions & 1 deletion lib/src/setting/preference_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class PreferenceSetting with JHLifeCircleBeanWithConfigStorage implements JHLife
RxBool showUtcTime = false.obs;
RxBool showDawnInfo = false.obs;
RxBool showHVInfo = false.obs;

RxBool useBuiltInBlockedUsers = true.obs;

@override
ConfigEnum get configEnum => ConfigEnum.preferenceSetting;

Expand Down Expand Up @@ -70,6 +71,7 @@ class PreferenceSetting with JHLifeCircleBeanWithConfigStorage implements JHLife
showUtcTime.value = map['showUtcTime'] ?? showUtcTime.value;
showDawnInfo.value = map['showDawnInfo'] ?? showDawnInfo.value;
showHVInfo.value = map['showHVInfo'] ?? showHVInfo.value;
useBuiltInBlockedUsers.value = map['useBuiltInBlockedUsers'] ?? useBuiltInBlockedUsers.value;
}

@override
Expand Down Expand Up @@ -99,6 +101,7 @@ class PreferenceSetting with JHLifeCircleBeanWithConfigStorage implements JHLife
'showUtcTime': showUtcTime.value,
'showDawnInfo': showDawnInfo.value,
'showHVInfo': showHVInfo.value,
'useBuiltInBlockedUsers': useBuiltInBlockedUsers.value,
});
}

Expand Down Expand Up @@ -252,6 +255,12 @@ class PreferenceSetting with JHLifeCircleBeanWithConfigStorage implements JHLife
this.showHVInfo.value = showHVInfo;
await saveBeanConfig();
}

Future<void> saveUseBuiltInBlockedUsers(bool useBuiltInBlockedUsers) async {
log.debug('saveUseBuiltInBlockedUsers:$useBuiltInBlockedUsers');
this.useBuiltInBlockedUsers.value = useBuiltInBlockedUsers;
await saveBeanConfig();
}
}

enum Scroll2TopButtonModeEnum { scrollUp, scrollDown, never, always }
Expand Down
2 changes: 2 additions & 0 deletions lib/src/utils/eh_spider_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import '../service/log.dart';

typedef HtmlParser<T> = T Function(Headers headers, dynamic data);

HtmlParser<String> simpleParser = (headers, data) => data as String;

class EHSpiderParser {
static Map<String, dynamic> loginPage2UserInfoOrErrorMsg(Headers headers, dynamic data) {
Map<String, dynamic> map = {};
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: jhentai
description: A flutter app for E-Hentai/EXHentai

publish_to: 'none'
version: 8.0.6+273
version: 8.0.6+274

environment:
sdk: '>=3.0.0 <4.0.0'
Expand Down

0 comments on commit b851321

Please sign in to comment.