增强预览机制

This commit is contained in:
2026-03-13 23:58:52 +08:00
parent 33d2231bed
commit e76a1dff71
2 changed files with 81 additions and 16 deletions

View File

@@ -179,7 +179,15 @@ Future<Response> _getPhotoPreviewHandler(Request req) async {
return Response.notFound('Photo not found');
}
final file = await vips.generatePreview(photo.filePath);
// 从查询参数获取宽度和高度
final w = int.tryParse(req.url.queryParameters['w'] ?? '');
final h = int.tryParse(req.url.queryParameters['h'] ?? '');
final file = await vips.generatePreview(
photo.filePath,
w: w,
h: h,
);
if (!await file.exists()) {
return Response.notFound('File not found');
@@ -206,7 +214,7 @@ Future<Response> _getPhotoPreviewHandler(Request req) async {
return Response.ok(
streamController.stream,
headers: {
'Content-Type': photo.mimeType,
'Content-Type': 'image/webp',
'Content-Length': file.statSync().size.toString(),
},
);