From 99481bddbd9553f546274bda2776354f08ff0782 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Fri, 2 Feb 2024 18:22:11 -0300 Subject: [PATCH] video: Allow clearing the temporary video storage --- src/stores/video.ts | 8 ++++++++ src/views/ConfigurationVideoView.vue | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/stores/video.ts b/src/stores/video.ts index 9a9fa0587..cc2574114 100644 --- a/src/stores/video.ts +++ b/src/stores/video.ts @@ -228,6 +228,13 @@ export const useVideoStore = defineStore('video', () => { saveAs(file as Blob, fileName) } + // Used to clear the temporary video database + const clearTemporaryVideoDB = async (): Promise => { + await tempVideoChunksDB.iterate((_, chunkName) => { + tempVideoChunksDB.removeItem(chunkName) + }) + } + // Used to store chunks of an ongoing recording, that will be merged into a video file when the recording is stopped const tempVideoChunksDB = localforage.createInstance({ driver: localforage.INDEXEDDB, @@ -330,6 +337,7 @@ export const useVideoStore = defineStore('video', () => { tempVideoChunksDB, discardFileFromVideoDB, downloadFileFromVideoDB, + clearTemporaryVideoDB, getMediaStream, getStreamData, isRecording, diff --git a/src/views/ConfigurationVideoView.vue b/src/views/ConfigurationVideoView.vue index 273ea52fd..096518677 100644 --- a/src/views/ConfigurationVideoView.vue +++ b/src/views/ConfigurationVideoView.vue @@ -62,6 +62,14 @@ + + Clear temporary video storage + @@ -81,9 +89,11 @@ const { allowedIceIps, availableIceIps } = storeToRefs(videoStore) // List available videos and telemetry logs to be downloaded const namesAvailableVideosAndLogs = ref([]) +const temporaryDbSize = ref(0) onMounted(async () => { await fetchVideoAndLogsData() + await fetchTemporaryDbSize() }) // Fetch available videos and telemetry logs from the storage @@ -95,6 +105,12 @@ const fetchVideoAndLogsData = async (): Promise => { namesAvailableVideosAndLogs.value = availableData } +// Fetch temporary video data from the storage +const fetchTemporaryDbSize = async (): Promise => { + const size = await videoStore.tempVideoChunksDB.length() + temporaryDbSize.value = size +} + const discardAndUpdateDB = async (filename: string): Promise => { await videoStore.discardFileFromVideoDB(filename) await fetchVideoAndLogsData() @@ -104,4 +120,9 @@ const downloadAndUpdateDB = async (filename: string): Promise => { await videoStore.downloadFileFromVideoDB(filename) await fetchVideoAndLogsData() } + +const clearTemporaryVideoFiles = async (): Promise => { + videoStore.clearTemporaryVideoDB() + await fetchTemporaryDbSize() +}