* tweak

* opt: image quality

* opt: VideoPlayerServiceHandler

* fixes

* update

Signed-off-by: dom <githubaccount56556@proton.me>

* fix get file name

Signed-off-by: dom <githubaccount56556@proton.me>

---------

Co-authored-by: dom <githubaccount56556@proton.me>
This commit is contained in:
My-Responsitories
2026-01-25 15:21:33 +08:00
committed by GitHub
parent 219228f8b5
commit 038f03a4e7
10 changed files with 64 additions and 49 deletions

View File

@@ -1,4 +1,5 @@
import 'dart:io';
import 'dart:math' as math;
import 'dart:typed_data';
import 'package:PiliPlus/common/constants.dart';
@@ -267,22 +268,23 @@ abstract final class ImageUtils {
r'(@(\d+[a-z]_?)*)(\..*)?$',
caseSensitive: false,
);
static String thumbnailUrl(String? src, [int? quality]) {
if (src != null && quality != 100) {
static String thumbnailUrl(String? src, [int maxQuality = 1]) {
if (src != null && maxQuality != 100) {
maxQuality = math.max(maxQuality, GlobalData().imgQuality);
bool hasMatch = false;
src = src.splitMapJoin(
_thumbRegex,
onMatch: (Match match) {
onMatch: (match) {
hasMatch = true;
String suffix = match.group(3) ?? '.webp';
return '${match.group(1)}_${quality ?? GlobalData().imgQuality}q$suffix';
return '${match.group(1)}_${maxQuality}q$suffix';
},
onNonMatch: (String str) {
return str;
},
);
if (!hasMatch) {
src += '@${quality ?? GlobalData().imgQuality}q.webp';
src += '@${maxQuality}q.webp';
}
}
return src.http2https;

View File

@@ -162,9 +162,14 @@ abstract final class Utils {
return randomBase64.substring(0, randomBase64.length - 2);
}
static int _getExt(String uri) {
final i = uri.indexOf('?');
return i == -1 ? uri.length : i;
}
static String getFileName(String uri, {bool fileExt = true}) {
final i0 = uri.lastIndexOf('/') + 1;
final i1 = fileExt ? uri.length : uri.lastIndexOf('.');
final i1 = fileExt ? _getExt(uri) : uri.lastIndexOf('.');
return uri.substring(i0, i1);
}