Skip to content

Commit

Permalink
Add proper alert with information about the recovered video files
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Nov 24, 2023
1 parent 7fc2d80 commit 46bed7f
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/stores/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useStorage } from '@vueuse/core'
import { saveAs } from 'file-saver'
import localforage from 'localforage'
import { defineStore } from 'pinia'
import Swal from 'sweetalert2'
import { reactive } from 'vue'

export const useVideoStore = defineStore('video', () => {
Expand All @@ -17,12 +18,34 @@ export const useVideoStore = defineStore('video', () => {
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)
cockpitVideoDB.length().then((len) => {
if (len === 0) return

Swal.fire({
title: 'Video recording recovery',
text: `Cockpit has pending backups for videos that you started recording but did not download.
Click 'Discard' to remove the backuped files.
Click 'Dismiss' to postpone this decision for the next boot.
Click 'Download' to download the files. If you decide to download them, they will be removed afterwards.
`,
icon: 'warning',
showDenyButton: true,
showCancelButton: true,
confirmButtonText: 'Download',
denyButtonText: 'Discard',
cancelButtonText: 'Dismiss',
}).then((decision) => {
if (decision.isDismissed) return
if (decision.isDenied) {
cockpitVideoDB.iterate((_, videoName) => cockpitVideoDB.removeItem(videoName))
} else if (decision.isConfirmed) {
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 }
Expand Down

0 comments on commit 46bed7f

Please sign in to comment.