This commit is contained in:
@@ -13,7 +13,6 @@ class PhotoRepository {
|
||||
|
||||
PhotoRepository(this.basePath);
|
||||
|
||||
|
||||
/// 获取相册中的照片(分页)
|
||||
Future<PageResult<Photo>> getPhotosByAlbumIdPaged(
|
||||
int id, {
|
||||
@@ -93,10 +92,7 @@ class PhotoRepository {
|
||||
}
|
||||
|
||||
/// 创建排序比较器
|
||||
int Function(Photo, Photo) _createComparator(
|
||||
String sortBy,
|
||||
String order,
|
||||
) {
|
||||
int Function(Photo, Photo) _createComparator(String sortBy, String order) {
|
||||
final ascending = order == 'asc';
|
||||
|
||||
int compare(Photo a, Photo b) {
|
||||
@@ -105,9 +101,7 @@ class PhotoRepository {
|
||||
if (valueA == null && valueB == null) return 0;
|
||||
if (valueA == null) return 1;
|
||||
if (valueB == null) return -1;
|
||||
return ascending
|
||||
? valueA.compareTo(valueB)
|
||||
: valueB.compareTo(valueA);
|
||||
return ascending ? valueA.compareTo(valueB) : valueB.compareTo(valueA);
|
||||
}
|
||||
|
||||
switch (sortBy) {
|
||||
|
||||
@@ -274,7 +274,8 @@ void main() {
|
||||
'should return empty list when base directory does not exist',
|
||||
() async {
|
||||
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 {
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(
|
||||
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(
|
||||
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);
|
||||
|
||||
@@ -454,7 +457,8 @@ void main() {
|
||||
|
||||
final allPhotos = (await repository.getPhotosByAlbumIdPaged(
|
||||
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);
|
||||
|
||||
@@ -474,7 +478,8 @@ void main() {
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(
|
||||
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);
|
||||
});
|
||||
|
||||
@@ -488,7 +493,8 @@ void main() {
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(
|
||||
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 {
|
||||
@@ -501,7 +507,8 @@ void main() {
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(
|
||||
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 {
|
||||
@@ -514,7 +521,8 @@ void main() {
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(
|
||||
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 {
|
||||
@@ -527,7 +535,8 @@ void main() {
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(
|
||||
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 {
|
||||
@@ -540,7 +549,8 @@ void main() {
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(
|
||||
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 {
|
||||
@@ -553,7 +563,8 @@ void main() {
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(
|
||||
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(
|
||||
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 {
|
||||
@@ -589,7 +601,8 @@ void main() {
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(
|
||||
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 {
|
||||
@@ -603,7 +616,8 @@ void main() {
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'ext_ignore').hashCode,
|
||||
)).items; expect(photos.length, 1);
|
||||
)).items;
|
||||
expect(photos.length, 1);
|
||||
expect(photos.first.fileName, 'valid.png');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user