格式化代码
All checks were successful
Dart CI / build (push) Successful in 31s

This commit is contained in:
2026-04-05 19:46:02 +08:00
parent 2bb8a83bbc
commit a0bc231c3c
2 changed files with 43 additions and 35 deletions

View File

@@ -13,7 +13,6 @@ class PhotoRepository {
PhotoRepository(this.basePath); PhotoRepository(this.basePath);
/// 获取相册中的照片(分页) /// 获取相册中的照片(分页)
Future<PageResult<Photo>> getPhotosByAlbumIdPaged( Future<PageResult<Photo>> getPhotosByAlbumIdPaged(
int id, { int id, {
@@ -93,10 +92,7 @@ class PhotoRepository {
} }
/// 创建排序比较器 /// 创建排序比较器
int Function(Photo, Photo) _createComparator( int Function(Photo, Photo) _createComparator(String sortBy, String order) {
String sortBy,
String order,
) {
final ascending = order == 'asc'; final ascending = order == 'asc';
int compare(Photo a, Photo b) { int compare(Photo a, Photo b) {
@@ -105,9 +101,7 @@ class PhotoRepository {
if (valueA == null && valueB == null) return 0; if (valueA == null && valueB == null) return 0;
if (valueA == null) return 1; if (valueA == null) return 1;
if (valueB == null) return -1; if (valueB == null) return -1;
return ascending return ascending ? valueA.compareTo(valueB) : valueB.compareTo(valueA);
? valueA.compareTo(valueB)
: valueB.compareTo(valueA);
} }
switch (sortBy) { switch (sortBy) {

View File

@@ -274,7 +274,8 @@ void main() {
'should return empty list when base directory does not exist', 'should return empty list when base directory does not exist',
() async { () async {
final repo = PhotoRepository('/nonexistent/path'); final repo = PhotoRepository('/nonexistent/path');
final photos = (await repo.getPhotosByAlbumIdPaged(123)).items; expect(photos, isEmpty); final photos = (await repo.getPhotosByAlbumIdPaged(123)).items;
expect(photos, isEmpty);
}, },
); );
@@ -283,7 +284,8 @@ void main() {
() async { () async {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'nonexistent').hashCode, p.join(tempDir.path, 'nonexistent').hashCode,
)).items; expect(photos, isEmpty); )).items;
expect(photos, isEmpty);
}, },
); );
@@ -436,7 +438,8 @@ void main() {
final allPhotos = (await repository.getPhotosByAlbumIdPaged( final allPhotos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'find_album').hashCode, p.join(tempDir.path, 'find_album').hashCode,
)).items; final targetId = allPhotos.first.id; )).items;
final targetId = allPhotos.first.id;
final photo = await repository.getPhotoById(targetId); final photo = await repository.getPhotoById(targetId);
@@ -454,7 +457,8 @@ void main() {
final allPhotos = (await repository.getPhotosByAlbumIdPaged( final allPhotos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'dims_album').hashCode, p.join(tempDir.path, 'dims_album').hashCode,
)).items; final targetId = allPhotos.first.id; )).items;
final targetId = allPhotos.first.id;
final photo = await repository.getPhotoById(targetId); final photo = await repository.getPhotoById(targetId);
@@ -474,7 +478,8 @@ void main() {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'mime_jpg').hashCode, p.join(tempDir.path, 'mime_jpg').hashCode,
)).items; expect(photos.length, 2); )).items;
expect(photos.length, 2);
expect(photos.every((p) => p.mimeType == 'image/jpeg'), isTrue); expect(photos.every((p) => p.mimeType == 'image/jpeg'), isTrue);
}); });
@@ -488,7 +493,8 @@ void main() {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'mime_png').hashCode, p.join(tempDir.path, 'mime_png').hashCode,
)).items; expect(photos.first.mimeType, 'image/png'); )).items;
expect(photos.first.mimeType, 'image/png');
}); });
test('should detect webp as image/webp', () async { test('should detect webp as image/webp', () async {
@@ -501,7 +507,8 @@ void main() {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'mime_webp').hashCode, p.join(tempDir.path, 'mime_webp').hashCode,
)).items; expect(photos.first.mimeType, 'image/webp'); )).items;
expect(photos.first.mimeType, 'image/webp');
}); });
test('should detect mp4 as video/mp4', () async { test('should detect mp4 as video/mp4', () async {
@@ -514,7 +521,8 @@ void main() {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'mime_mp4').hashCode, p.join(tempDir.path, 'mime_mp4').hashCode,
)).items; expect(photos.first.mimeType, 'video/mp4'); )).items;
expect(photos.first.mimeType, 'video/mp4');
}); });
test('should detect avi as video/avi', () async { test('should detect avi as video/avi', () async {
@@ -527,7 +535,8 @@ void main() {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'mime_avi').hashCode, p.join(tempDir.path, 'mime_avi').hashCode,
)).items; expect(photos.first.mimeType, 'video/avi'); )).items;
expect(photos.first.mimeType, 'video/avi');
}); });
test('should detect mov as video/quicktime', () async { test('should detect mov as video/quicktime', () async {
@@ -540,7 +549,8 @@ void main() {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'mime_mov').hashCode, p.join(tempDir.path, 'mime_mov').hashCode,
)).items; expect(photos.first.mimeType, 'video/quicktime'); )).items;
expect(photos.first.mimeType, 'video/quicktime');
}); });
test('should detect mkv as video/x-matroska', () async { test('should detect mkv as video/x-matroska', () async {
@@ -553,7 +563,8 @@ void main() {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'mime_mkv').hashCode, p.join(tempDir.path, 'mime_mkv').hashCode,
)).items; expect(photos.first.mimeType, 'video/x-matroska'); )).items;
expect(photos.first.mimeType, 'video/x-matroska');
}); });
}); });
@@ -572,7 +583,8 @@ void main() {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'ext_test').hashCode, p.join(tempDir.path, 'ext_test').hashCode,
)).items; expect(photos.length, extensions.length); )).items;
expect(photos.length, extensions.length);
}); });
test('should recognize all video extensions', () async { test('should recognize all video extensions', () async {
@@ -589,7 +601,8 @@ void main() {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'ext_video').hashCode, p.join(tempDir.path, 'ext_video').hashCode,
)).items; expect(photos.length, extensions.length); )).items;
expect(photos.length, extensions.length);
}); });
test('should ignore unsupported extensions', () async { test('should ignore unsupported extensions', () async {
@@ -603,7 +616,8 @@ void main() {
final photos = (await repository.getPhotosByAlbumIdPaged( final photos = (await repository.getPhotosByAlbumIdPaged(
p.join(tempDir.path, 'ext_ignore').hashCode, p.join(tempDir.path, 'ext_ignore').hashCode,
)).items; expect(photos.length, 1); )).items;
expect(photos.length, 1);
expect(photos.first.fileName, 'valid.png'); expect(photos.first.fileName, 'valid.png');
}); });
}); });