修改id生成机制
This commit is contained in:
@@ -22,7 +22,7 @@ class AlbumRepository {
|
|||||||
.map((dir) {
|
.map((dir) {
|
||||||
final name = p.basename(dir.path);
|
final name = p.basename(dir.path);
|
||||||
return Album(
|
return Album(
|
||||||
id: name.hashCode,
|
id: dir.path.hashCode,
|
||||||
name: name,
|
name: name,
|
||||||
createdAt: dir.statSync().changed,
|
createdAt: dir.statSync().changed,
|
||||||
updatedAt: dir.statSync().changed,
|
updatedAt: dir.statSync().changed,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class PhotoRepository {
|
|||||||
await dir
|
await dir
|
||||||
.list()
|
.list()
|
||||||
.where((f) => f is Directory)
|
.where((f) => f is Directory)
|
||||||
.where((d) => p.basename(d.path).hashCode == id)
|
.where((d) => d.path.hashCode == id)
|
||||||
.first
|
.first
|
||||||
as Directory;
|
as Directory;
|
||||||
} on StateError {
|
} on StateError {
|
||||||
@@ -45,7 +45,7 @@ class PhotoRepository {
|
|||||||
final dimensions = _getImageDimensions(file, mimeType);
|
final dimensions = _getImageDimensions(file, mimeType);
|
||||||
|
|
||||||
return Photo(
|
return Photo(
|
||||||
id: fileName.hashCode,
|
id: file.path.hashCode,
|
||||||
albumId: id,
|
albumId: id,
|
||||||
filePath: file.path,
|
filePath: file.path,
|
||||||
fileName: fileName,
|
fileName: fileName,
|
||||||
@@ -73,7 +73,7 @@ class PhotoRepository {
|
|||||||
.list(recursive: true)
|
.list(recursive: true)
|
||||||
.where((f) => f is File)
|
.where((f) => f is File)
|
||||||
.map((f) => f as File)
|
.map((f) => f as File)
|
||||||
.firstWhere((f) => p.basename(f.path).hashCode == id);
|
.firstWhere((f) => f.path.hashCode == id);
|
||||||
} on StateError {
|
} on StateError {
|
||||||
// firstWhere throws StateError when no element is found
|
// firstWhere throws StateError when no element is found
|
||||||
return null;
|
return null;
|
||||||
@@ -84,8 +84,8 @@ class PhotoRepository {
|
|||||||
final dimensions = _getImageDimensions(file, mimeType);
|
final dimensions = _getImageDimensions(file, mimeType);
|
||||||
|
|
||||||
return Photo(
|
return Photo(
|
||||||
id: p.basename(file.path).hashCode,
|
id: file.path.hashCode,
|
||||||
albumId: p.basename(file.parent.path).hashCode,
|
albumId: file.parent.path.hashCode,
|
||||||
filePath: file.path,
|
filePath: file.path,
|
||||||
fileName: p.basename(file.path),
|
fileName: p.basename(file.path),
|
||||||
fileSize: stat.size,
|
fileSize: stat.size,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class Vips {
|
|||||||
/// 如果同时指定 [w] 和 [h],图片将按比例缩放以适应指定尺寸
|
/// 如果同时指定 [w] 和 [h],图片将按比例缩放以适应指定尺寸
|
||||||
Future<File> generatePreview(String imgPath, {int? w, int? h}) async {
|
Future<File> generatePreview(String imgPath, {int? w, int? h}) async {
|
||||||
// 生成缓存文件名:包含原图 hash 和尺寸信息
|
// 生成缓存文件名:包含原图 hash 和尺寸信息
|
||||||
final baseName = basename(imgPath).hashCode.toString();
|
final baseName = imgPath.hashCode.toString();
|
||||||
final sizeSuffix = _buildSizeSuffix(w, h);
|
final sizeSuffix = _buildSizeSuffix(w, h);
|
||||||
final imgOut = "$cacheDir/preview/$baseName$sizeSuffix.webp";
|
final imgOut = "$cacheDir/preview/$baseName$sizeSuffix.webp";
|
||||||
final outFile = File(imgOut);
|
final outFile = File(imgOut);
|
||||||
|
|||||||
Reference in New Issue
Block a user