@@ -4,6 +4,7 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
import '../entities/photo.dart';
|
||||
import '../page_result.dart';
|
||||
|
||||
class PhotoRepository {
|
||||
final String basePath;
|
||||
@@ -12,7 +13,30 @@ class PhotoRepository {
|
||||
|
||||
PhotoRepository(this.basePath);
|
||||
|
||||
/// 获取相册中所有照片(不分页,保留兼容)
|
||||
Future<List<Photo>> getPhotosByAlbumId(int id) async {
|
||||
final all = await _loadPhotosForAlbum(id);
|
||||
return all;
|
||||
}
|
||||
|
||||
/// 获取相册中的照片(分页)
|
||||
Future<PageResult<Photo>> getPhotosByAlbumIdPaged(
|
||||
int id, {
|
||||
int page = 1,
|
||||
int size = 20,
|
||||
}) async {
|
||||
final all = await _loadPhotosForAlbum(id);
|
||||
final total = all.length;
|
||||
final startIndex = (page - 1) * size;
|
||||
final endIndex = startIndex + size;
|
||||
final items = startIndex < total
|
||||
? all.sublist(startIndex, endIndex > total ? total : endIndex)
|
||||
: <Photo>[];
|
||||
return PageResult(items: items, total: total, page: page, size: size);
|
||||
}
|
||||
|
||||
/// 内部方法:加载相册照片(带缓存)
|
||||
Future<List<Photo>> _loadPhotosForAlbum(int id) async {
|
||||
if (_updatedMap.containsKey(id) &&
|
||||
DateTime.now().difference(_updatedMap[id]!).inSeconds <= 60) {
|
||||
return _map[id]!;
|
||||
|
||||
Reference in New Issue
Block a user