Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

feat(storage): clear converted JPEGs for HEIC photos

Timothy Yin8a0dc2a970ad
diff --git a/server/api/photos/[photoId]/index.delete.ts b/server/api/photos/[photoId]/index.delete.ts
index ae0c85ca..c4859d42 100644
--- a/server/api/photos/[photoId]/index.delete.ts
+++ b/server/api/photos/[photoId]/index.delete.ts
@@ -1,3 +1,5 @@
+const HEIC_EXTENSIONS = ['.heic', '.heif', '.hif']
+
export default eventHandler(async (event) => {
await requireUserSession(event)
const { storageProvider } = useStorageProvider(event)
@@ -29,9 +31,34 @@ export default eventHandler(async (event) => {
logger.image.info(`Deleting photo files for ${photoId} from storage`)
try {
await storageProvider.delete(photo.storageKey)
- await storageProvider.delete(
- photo.thumbnailUrl?.replace(storageProvider.getPublicUrl(''), '') || '',
+ const lowerStorageKey = photo.storageKey.toLowerCase()
+ const heicExtension = HEIC_EXTENSIONS.find((ext) =>
+ lowerStorageKey.endsWith(ext),
)
+ if (heicExtension) {
+ const jpegKey =
+ photo.storageKey.slice(
+ 0,
+ photo.storageKey.length - heicExtension.length,
+ ) + '.jpeg'
+
+ if (jpegKey !== photo.storageKey) {
+ logger.image.info(
+ `Deleting converted JPEG for HEIC photo ${photoId}: ${jpegKey}`,
+ )
+ try {
+ await storageProvider.delete(jpegKey)
+ } catch {
+ // ignore error when deleting converted JPEG
+ }
+ }
+ }
+ if (photo.thumbnailKey) {
+ await storageProvider.delete(photo.thumbnailKey)
+ }
+ if (photo.livePhotoVideoKey) {
+ await storageProvider.delete(photo.livePhotoVideoKey)
+ }
} catch {
// ignore error
}