mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix: thumbnail image url
Closes #360 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -52,8 +52,11 @@ extension ListExt<T> on List<T>? {
|
||||
bool ne(List<T>? other) => !eq(other);
|
||||
}
|
||||
|
||||
extension StringExt on String {
|
||||
String get http2https => replaceFirst(RegExp("^http://"), "https://");
|
||||
final _regExp = RegExp("^(http:)?//", caseSensitive: false);
|
||||
|
||||
extension StringExt on String? {
|
||||
String get http2https =>
|
||||
this == null ? '' : this!.replaceFirst(_regExp, "https://");
|
||||
}
|
||||
|
||||
extension StringNullExt on String? {
|
||||
|
||||
@@ -26,6 +26,7 @@ import 'package:PiliPlus/pages/video/detail/introduction/widgets/group_panel.dar
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/url_utils.dart';
|
||||
@@ -49,6 +50,30 @@ class Utils {
|
||||
|
||||
static const channel = MethodChannel("PiliPlus");
|
||||
|
||||
static final regExp =
|
||||
RegExp(r'(@(\d+[a-z]_?)*)(\..*)?$', caseSensitive: false);
|
||||
|
||||
static String thumbnailImgUrl(String? src, [int? quality]) {
|
||||
if (src != null) {
|
||||
bool hasMatch = false;
|
||||
src = src.splitMapJoin(
|
||||
regExp,
|
||||
onMatch: (Match match) {
|
||||
hasMatch = true;
|
||||
String suffix = match.group(3) ?? '.webp';
|
||||
return '${match.group(1)}_${quality ?? GlobalData().imgQuality}q$suffix';
|
||||
},
|
||||
onNonMatch: (String str) {
|
||||
return str;
|
||||
},
|
||||
);
|
||||
if (hasMatch.not) {
|
||||
src += '@${quality ?? GlobalData().imgQuality}q.webp';
|
||||
}
|
||||
}
|
||||
return src.http2https;
|
||||
}
|
||||
|
||||
static bool? _isIpad;
|
||||
|
||||
static Future<bool> isIpad() async {
|
||||
|
||||
Reference in New Issue
Block a user