Skip to content

Commit

Permalink
update gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangtian616 committed Nov 6, 2024
1 parent efc2630 commit 7e451e9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
42 changes: 40 additions & 2 deletions lib/src/service/gallery_download_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,15 @@ class GalleryDownloadService extends GetxController with GridBasePageServiceMixi

GalleryDownloadInfo galleryDownloadInfo = galleryDownloadInfos[gallery.gid]!;

/// If this is a update from old gallery, try to copy from existing old image first
if (gallery.oldVersionGalleryUrl != null) {
await _tryCopyImageInfoFromHref(gallery.oldVersionGalleryUrl!, gallery, serialNo);

if (galleryDownloadInfo.images[serialNo] != null) {
return;
}
}

GalleryImage image;
try {
image = await retry(
Expand Down Expand Up @@ -1080,7 +1089,7 @@ class GalleryDownloadService extends GetxController with GridBasePageServiceMixi

/// If this is a update from old gallery, try to copy from existing old image first
if (gallery.oldVersionGalleryUrl != null) {
await _tryCopyImageInfo(gallery.oldVersionGalleryUrl!, gallery, serialNo);
await _tryCopyImageInfoFromImage(gallery.oldVersionGalleryUrl!, gallery, serialNo);

if (image.downloadStatus == DownloadStatus.downloaded) {
return;
Expand Down Expand Up @@ -1196,8 +1205,37 @@ class GalleryDownloadService extends GetxController with GridBasePageServiceMixi
);
}

Future<void> _tryCopyImageInfoFromHref(String oldVersionGalleryUrl, GalleryDownloadedData newGallery, int newImageSerialNo) async {
GalleryDownloadedData? oldGallery = gallerys.firstWhereOrNull((e) => e.galleryUrl == oldVersionGalleryUrl);
if (oldGallery == null) {
return;
}

String? newImageHash = galleryDownloadInfos[newGallery.gid]!.imageHrefs[newImageSerialNo]!.originImageHash;
if (newImageHash == null) {
return;
}

int? oldImageSerialNo = galleryDownloadInfos[oldGallery.gid]?.images.firstIndexWhereOrNull((e) => e?.imageHash == newImageHash);
if (oldImageSerialNo == null) {
return;
}

GalleryImage oldImage = galleryDownloadInfos[oldGallery.gid]!.images[oldImageSerialNo]!;
GalleryImage newImage = oldImage.copyWith(
path: _computeImageDownloadRelativePath(newGallery.title, newGallery.gid, oldImage.url, newImageSerialNo),
downloadStatus: DownloadStatus.downloading,
);

await _saveNewImageInfoInDatabase(newImage, newImageSerialNo, newGallery.gid);
galleryDownloadInfos[newGallery.gid]!.images[newImageSerialNo] = newImage;

await _copyImageInfo(oldImage, newGallery, newImageSerialNo);
await superResolutionService.copyImageInfo(oldGallery, newGallery, oldImageSerialNo, newImageSerialNo);
}

/// If two images' [imageHash] is equal, they are the same image.
Future<void> _tryCopyImageInfo(String oldVersionGalleryUrl, GalleryDownloadedData newGallery, int newImageSerialNo) async {
Future<void> _tryCopyImageInfoFromImage(String oldVersionGalleryUrl, GalleryDownloadedData newGallery, int newImageSerialNo) async {
GalleryDownloadedData? oldGallery = gallerys.firstWhereOrNull((e) => e.galleryUrl == oldVersionGalleryUrl);
if (oldGallery == null) {
return;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/service/schedule_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ScheduleService with JHLifeCircleBeanErrorCatch implements JHLifeCircleBea

try {
latestVersion = (await retry(
() => ehRequest.get(url: url, parser: EHSpiderParser.githubReleasePage2LatestVersion),
() => ehRequest.get(url: url, parser: EHSpiderParser.githubReleasePage2LatestVersion),
maxAttempts: 3,
))
.trim()
Expand All @@ -88,7 +88,7 @@ class ScheduleService with JHLifeCircleBeanErrorCatch implements JHLifeCircleBea
Get.dialog(UpdateDialog(currentVersion: currentVersion, latestVersion: latestVersion));
});
}

Future<void> refreshGalleryTags() async {
int pageNo = 1;
List<GalleryDownloadedData> gallerys = await GalleryDao.selectGallerysForTagRefresh(pageNo, 25);
Expand Down Expand Up @@ -143,7 +143,7 @@ class ScheduleService with JHLifeCircleBeanErrorCatch implements JHLifeCircleBea
);
log.trace('refreshArchiveTags success, pageNo: $pageNo, archives: ${archives.map((a) => a.gid).toList()}');
} catch (e) {
log.warning('refreshArchiveTags error, archives: $archives', e);
log.warning('refreshArchiveTags error, archives: ${archives.map((a) => a.gid).toList()}', e);
}

pageNo++;
Expand Down

0 comments on commit 7e451e9

Please sign in to comment.