Skip to content

Commit

Permalink
video: Only zip unprocessed chunks, otherwise download files separately
Browse files Browse the repository at this point in the history
This makes the download process instantaneous, which is specially important on longer videos.
  • Loading branch information
rafaellehmkuhl committed Jul 11, 2024
1 parent c122c05 commit c1d14be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/VideoLibraryModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ const downloadVideoAndTelemetryFiles = async (): Promise<void> => {
if (tempProcessedVideos.length > 0) {
const dataLogFilesAdded = addLogDataToFileList(tempProcessedVideos)
await videoStore.downloadFilesFromVideoDB(dataLogFilesAdded, fillProgressData)
await videoStore.downloadFilesFromVideoDB(dataLogFilesAdded)
}
if (tempUnprocessedVideos.length > 0) {
await videoStore.downloadTempVideo(tempUnprocessedVideos, fillProgressData)
Expand Down
24 changes: 9 additions & 15 deletions src/stores/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ export const useVideoStore = defineStore('video', () => {
const downloadFiles = async (
db: StorageDB,
keys: string[],
zipFilenamePrefix: string,
shouldZip = false,
zipFilenamePrefix = 'Cockpit-Files',
progressCallback?: DownloadProgressCallback
): Promise<void> => {
const maybeFiles = await Promise.all(
Expand All @@ -388,32 +389,25 @@ export const useVideoStore = defineStore('video', () => {
return
}

if (files.length === 1) {
saveAs(files[0].blob, files[0].filename)
} else {
if (shouldZip) {
await createZipAndDownload(files, `${zipFilenamePrefix}.zip`, progressCallback)
} else {
files.forEach(({ blob, filename }) => saveAs(blob, filename))
}
}

const downloadFilesFromVideoDB = async (
fileNames: string[],
progressCallback?: DownloadProgressCallback
): Promise<void> => {
const downloadFilesFromVideoDB = async (fileNames: string[]): Promise<void> => {
console.debug(`Downloading files from the video recovery database: ${fileNames.join(', ')}`)
await downloadFiles(
videoStoringDB,
fileNames,
fileNames.length > 1 ? 'Cockpit-Video-Recordings' : 'Cockpit-Video-Recording',
progressCallback
)
await downloadFiles(videoStoringDB, fileNames)
}

const downloadTempVideo = async (hashes: string[], progressCallback?: DownloadProgressCallback): Promise<void> => {
console.debug(`Downloading ${hashes.length} video chunks from the temporary database.`)

for (const hash of hashes) {
const fileNames = (await tempVideoChunksDB.keys()).filter((filename) => filename.includes(hash))
await downloadFiles(tempVideoChunksDB, fileNames, `Cockpit-Unprocessed-Video-Chunks-${hash}`, progressCallback)
const zipFilenamePrefix = `Cockpit-Unprocessed-Video-Chunks-${hash}`
await downloadFiles(tempVideoChunksDB, fileNames, true, zipFilenamePrefix, progressCallback)
}
}

Expand Down

0 comments on commit c1d14be

Please sign in to comment.