From 7da9fb80951fe3d3d5c78f9c6061adfe77eecbd8 Mon Sep 17 00:00:00 2001 From: an-lee Date: Thu, 15 Aug 2024 15:12:52 +0800 Subject: [PATCH] Improve audio video page (#975) * remember tab value * fix locale * tips for no source file resources * add alert for no source file * improve code * clean up resources --- enjoy/src/i18n/en.json | 8 ++- enjoy/src/i18n/zh-CN.json | 6 +- enjoy/src/main/db/handlers/audios-handler.ts | 11 ++++ enjoy/src/main/db/handlers/videos-handler.ts | 11 ++++ enjoy/src/main/db/models/audio.ts | 26 ++++++--- enjoy/src/main/db/models/video.ts | 26 ++++++--- enjoy/src/preload.ts | 12 +++- .../renderer/components/audios/audio-card.tsx | 12 +++- .../components/audios/audios-component.tsx | 58 ++++++++++++++++--- .../components/audios/audios-table.tsx | 21 +++++-- .../components/medias/media-loading-modal.tsx | 25 ++++++-- .../renderer/components/videos/video-card.tsx | 18 +++++- .../components/videos/videos-component.tsx | 57 +++++++++++++++--- .../components/videos/videos-table.tsx | 15 ++++- enjoy/src/types/enjoy-app.d.ts | 2 + 15 files changed, 261 insertions(+), 47 deletions(-) diff --git a/enjoy/src/i18n/en.json b/enjoy/src/i18n/en.json index a0bd9357..b3523f1c 100644 --- a/enjoy/src/i18n/en.json +++ b/enjoy/src/i18n/en.json @@ -667,7 +667,7 @@ "scoreDesc": "Score desc", "scoreAsc": "Score asc", "recordingsDurationDesc": "Recordings duration", - "recordingsCountDesc": "Recordings duration", + "recordingsCountDesc": "Recordings count", "all": "All", "allLanguages": "All languages", "search": "Search", @@ -719,5 +719,9 @@ "textInput": "Text input", "increasePlaybackRate": "Increase playback rate", "descreasePlaybackRate": "Descrease playback rate", - "usage": "Usage" + "usage": "Usage", + "cannotFindSourceFile": "Cannot find source file", + "cleanUp": "Clean up", + "cleanUpConfirmation": "Are you sure to remove resources without source file?", + "cleanedUpSuccessfully": "Cleaned up successfully" } diff --git a/enjoy/src/i18n/zh-CN.json b/enjoy/src/i18n/zh-CN.json index 80f9166b..ccfc2bd4 100644 --- a/enjoy/src/i18n/zh-CN.json +++ b/enjoy/src/i18n/zh-CN.json @@ -719,5 +719,9 @@ "textInput": "文字输入", "increasePlaybackRate": "加快播放速度", "decreasePlaybackRate": "减慢播放速度", - "usage": "使用情况" + "usage": "使用情况", + "cannotFindSourceFile": "无法找到源文件,可能已经被删除", + "cleanUp": "清理", + "cleanUpConfirmation": "您确定要移除所有找不到源文件的资源吗?", + "cleanedUpSuccessfully": "清理成功" } diff --git a/enjoy/src/main/db/handlers/audios-handler.ts b/enjoy/src/main/db/handlers/audios-handler.ts index cfa5969b..6bab5d86 100644 --- a/enjoy/src/main/db/handlers/audios-handler.ts +++ b/enjoy/src/main/db/handlers/audios-handler.ts @@ -168,6 +168,16 @@ class AudiosHandler { return pathToEnjoyUrl(output); } + private async cleanUp() { + const audios = await Audio.findAll(); + + for (const audio of audios) { + if (!audio.src) { + audio.destroy(); + } + } + } + register() { ipcMain.handle("audios-find-all", this.findAll); ipcMain.handle("audios-find-one", this.findOne); @@ -176,6 +186,7 @@ class AudiosHandler { ipcMain.handle("audios-destroy", this.destroy); ipcMain.handle("audios-upload", this.upload); ipcMain.handle("audios-crop", this.crop); + ipcMain.handle("audios-clean-up", this.cleanUp); } } diff --git a/enjoy/src/main/db/handlers/videos-handler.ts b/enjoy/src/main/db/handlers/videos-handler.ts index f32e97df..e66105ad 100644 --- a/enjoy/src/main/db/handlers/videos-handler.ts +++ b/enjoy/src/main/db/handlers/videos-handler.ts @@ -158,6 +158,16 @@ class VideosHandler { return pathToEnjoyUrl(output); } + private async cleanUp() { + const videos = await Video.findAll(); + + for (const video of videos) { + if (!video.src) { + video.destroy(); + } + } + } + register() { ipcMain.handle("videos-find-all", this.findAll); ipcMain.handle("videos-find-one", this.findOne); @@ -166,6 +176,7 @@ class VideosHandler { ipcMain.handle("videos-destroy", this.destroy); ipcMain.handle("videos-upload", this.upload); ipcMain.handle("videos-crop", this.crop); + ipcMain.handle("videos-clean-up", this.cleanUp); } } diff --git a/enjoy/src/main/db/models/audio.ts b/enjoy/src/main/db/models/audio.ts index 27357217..3c769401 100644 --- a/enjoy/src/main/db/models/audio.ts +++ b/enjoy/src/main/db/models/audio.ts @@ -121,11 +121,15 @@ export class Audio extends Model