From 92d656ce29d24dbc4f5702dddd5e1fbe46c96759 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Tue, 21 Nov 2023 17:22:05 -0300 Subject: [PATCH] Offer download of video recording backups if they are available Remove them, independently if they were downloaded or not. --- src/stores/video.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/stores/video.ts b/src/stores/video.ts index 3e9718275..5243fd643 100644 --- a/src/stores/video.ts +++ b/src/stores/video.ts @@ -1,4 +1,6 @@ import { useStorage } from '@vueuse/core' +import { saveAs } from 'file-saver' +import localforage from 'localforage' import { defineStore } from 'pinia' import { reactive } from 'vue' @@ -6,5 +8,22 @@ export const useVideoStore = defineStore('video', () => { const availableIceIps = reactive([]) const allowedIceIps = useStorage('cockpit-allowed-stream-ips', []) + // Offer download of backuped videos + const cockpitVideoDB = localforage.createInstance({ + driver: localforage.INDEXEDDB, + name: 'CockpitVideoDB', + storeName: 'cockpit-video-db', + version: 1.0, + description: 'Local backups of Cockpit video recordings to be retrieved in case of failure.', + }) + + cockpitVideoDB.iterate((videoFile, videoName) => { + const blob = (videoFile as Blob[]).reduce((a, b) => new Blob([a, b], { type: 'video/webm' })) + saveAs(blob, videoName) + }) + cockpitVideoDB.iterate((_, videoName) => { + cockpitVideoDB.removeItem(videoName) + }) + return { availableIceIps, allowedIceIps } })