486CHD commited on
Commit
c581231
·
verified ·
1 Parent(s): 717431c

Upload 13 files

Browse files
Files changed (1) hide show
  1. index.html +63 -43
index.html CHANGED
@@ -1666,21 +1666,19 @@
1666
  }
1667
  return;
1668
  }
1669
- if (Device.isMobile && item.image && item.image.startsWith('data:image') && item.image.length > 900000) {
1670
- const reduced = await ImageHandler.reduceImageForMobile(item.image);
1671
- if (reduced && reduced !== item.image) {
1672
- ImageHandler.revokeDisplayUrl(item);
1673
- item.image = reduced;
1674
- Database.update(item.id, { image: reduced }).catch(() => {});
1675
- }
1676
- }
1677
-
1678
- const source = item.image || item.imageUrl;
1679
- const thumb = await ImageHandler.createThumbnail(source, maxWidth, quality);
1680
- if (thumb && thumb !== source) {
1681
- item.thumb = thumb;
1682
- Database.update(item.id, { thumb }).catch(() => {});
1683
- }
1684
 
1685
  if ('requestIdleCallback' in window) {
1686
  requestIdleCallback(processNext);
@@ -1797,15 +1795,38 @@
1797
  }
1798
  };
1799
 
1800
- if (item.image && item.image.startsWith('data:image') && item.image.length > 1200000) {
1801
- ImageHandler.dataUrlToObjectUrlAsync(item.image).then((url) => {
1802
- if (!url) return;
1803
- item.displayUrl = url;
1804
- if (AppState.currentModalItem === item) {
1805
- this.imgEl.src = url;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1806
  }
1807
- });
1808
- } else if (fullUrl && initialSrc !== fullUrl) {
 
 
1809
  const preloader = new Image();
1810
  preloader.onload = () => {
1811
  if (AppState.currentModalItem === item) {
@@ -2382,19 +2403,18 @@
2382
  }
2383
  return;
2384
  }
2385
- if (item.image && item.image.startsWith('data:image') && item.image.length > 900000) {
2386
- const reduced = await ImageHandler.reduceImageForMobile(item.image);
2387
- if (reduced && reduced !== item.image) {
2388
- ImageHandler.revokeDisplayUrl(item);
2389
- item.image = reduced;
2390
- }
2391
- }
2392
-
2393
- const source = item.image || item.imageUrl;
2394
- const thumb = await ImageHandler.createThumbnail(source, maxWidth, quality);
2395
- if (thumb && thumb !== source) {
2396
- item.thumb = thumb;
2397
- }
2398
 
2399
  if ('requestIdleCallback' in window) {
2400
  requestIdleCallback(processNext);
@@ -3005,19 +3025,19 @@
3005
  if (Device.isMobile && previewImage.startsWith('data:image') && previewImage.length > 900000) {
3006
  const reduceTask = async () => {
3007
  try {
3008
- const reduced = await ImageHandler.reduceImageForMobile(previewImage);
3009
- if (reduced && reduced !== newItem.image) {
3010
- ImageHandler.revokeDisplayUrl(newItem);
3011
- newItem.image = reduced;
3012
  }
3013
  if (!newItem.thumb) {
3014
- const newThumb = await ImageHandler.createThumbnail(newItem.image, 360, 0.6);
3015
- if (newThumb && newThumb !== newItem.image) {
3016
  newItem.thumb = newThumb;
3017
  }
3018
  }
3019
  if (AppState.db && newItem.id && !String(newItem.id).startsWith('temp-')) {
3020
- Database.update(newItem.id, { image: newItem.image, thumb: newItem.thumb }).catch(() => {});
3021
  }
3022
  GalleryManager.render();
3023
  } catch (error) {
 
1666
  }
1667
  return;
1668
  }
1669
+ const source = item.image || item.imageUrl;
1670
+ let sourceForThumb = source;
1671
+ if (Device.isMobile && sourceForThumb && sourceForThumb.startsWith('data:image') && sourceForThumb.length > 900000) {
1672
+ const reduced = await ImageHandler.reduceImageForMobile(sourceForThumb);
1673
+ if (reduced) {
1674
+ sourceForThumb = reduced;
1675
+ }
1676
+ }
1677
+ const thumb = await ImageHandler.createThumbnail(sourceForThumb, maxWidth, quality);
1678
+ if (thumb && thumb !== source) {
1679
+ item.thumb = thumb;
1680
+ Database.update(item.id, { thumb }).catch(() => {});
1681
+ }
 
 
1682
 
1683
  if ('requestIdleCallback' in window) {
1684
  requestIdleCallback(processNext);
 
1795
  }
1796
  };
1797
 
1798
+ const setFullFromBase64 = () => {
1799
+ if (AppState.currentModalItem === item) {
1800
+ this.imgEl.src = item.image;
1801
+ }
1802
+ };
1803
+
1804
+ if (item.image && item.image.startsWith('data:image') && !fullUrl) {
1805
+ if (item.image.length > 1200000) {
1806
+ ImageHandler.dataUrlToObjectUrlAsync(item.image).then((url) => {
1807
+ if (url) {
1808
+ item.displayUrl = url;
1809
+ if (AppState.currentModalItem === item) {
1810
+ this.imgEl.src = url;
1811
+ }
1812
+ return;
1813
+ }
1814
+ if ('requestIdleCallback' in window) {
1815
+ requestIdleCallback(setFullFromBase64);
1816
+ } else {
1817
+ setTimeout(setFullFromBase64, 0);
1818
+ }
1819
+ });
1820
+ } else if (initialSrc !== item.image) {
1821
+ if ('requestIdleCallback' in window) {
1822
+ requestIdleCallback(setFullFromBase64);
1823
+ } else {
1824
+ setTimeout(setFullFromBase64, 0);
1825
  }
1826
+ }
1827
+ }
1828
+
1829
+ if (fullUrl && initialSrc !== fullUrl) {
1830
  const preloader = new Image();
1831
  preloader.onload = () => {
1832
  if (AppState.currentModalItem === item) {
 
2403
  }
2404
  return;
2405
  }
2406
+ const source = item.image || item.imageUrl;
2407
+ let sourceForThumb = source;
2408
+ if (sourceForThumb && sourceForThumb.startsWith('data:image') && sourceForThumb.length > 900000) {
2409
+ const reduced = await ImageHandler.reduceImageForMobile(sourceForThumb);
2410
+ if (reduced) {
2411
+ sourceForThumb = reduced;
2412
+ }
2413
+ }
2414
+ const thumb = await ImageHandler.createThumbnail(sourceForThumb, maxWidth, quality);
2415
+ if (thumb && thumb !== source) {
2416
+ item.thumb = thumb;
2417
+ }
 
2418
 
2419
  if ('requestIdleCallback' in window) {
2420
  requestIdleCallback(processNext);
 
3025
  if (Device.isMobile && previewImage.startsWith('data:image') && previewImage.length > 900000) {
3026
  const reduceTask = async () => {
3027
  try {
3028
+ let sourceForThumb = previewImage;
3029
+ const reduced = await ImageHandler.reduceImageForMobile(sourceForThumb);
3030
+ if (reduced) {
3031
+ sourceForThumb = reduced;
3032
  }
3033
  if (!newItem.thumb) {
3034
+ const newThumb = await ImageHandler.createThumbnail(sourceForThumb, 360, 0.6);
3035
+ if (newThumb && newThumb !== sourceForThumb) {
3036
  newItem.thumb = newThumb;
3037
  }
3038
  }
3039
  if (AppState.db && newItem.id && !String(newItem.id).startsWith('temp-')) {
3040
+ Database.update(newItem.id, { thumb: newItem.thumb }).catch(() => {});
3041
  }
3042
  GalleryManager.render();
3043
  } catch (error) {