Skip to content

Commit

Permalink
video: Show size of current temporary video storage
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Feb 21, 2024
1 parent ffb9084 commit 7a84773
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/stores/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ export const useVideoStore = defineStore('video', () => {
}
}

const temporaryVideoDBSize = async (): Promise<number> => {
let totalSizeBytes = 0
await videoStoringDB.iterate((chunk) => {
totalSizeBytes += (chunk as Blob).size
})
return totalSizeBytes
}

// 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,
Expand Down Expand Up @@ -413,6 +421,7 @@ export const useVideoStore = defineStore('video', () => {
discardFilesFromVideoDB,
downloadFilesFromVideoDB,
clearTemporaryVideoDB,
temporaryVideoDBSize,
getMediaStream,
getStreamData,
isRecording,
Expand Down
12 changes: 7 additions & 5 deletions src/views/ConfigurationVideoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@
</fwb-table-row>
</fwb-table-body>
</fwb-table>
<span
<div
v-if="temporaryDbSize > 0"
v-tooltip.bottom="'Remove video files used during the recording. This will not affect already saved videos.'"
class="p-4 m-4 transition-all rounded-md cursor-pointer bg-slate-600 text-slate-50 hover:bg-slate-500/80"
class="flex flex-col items-center justify-center p-4 m-4 transition-all rounded-md cursor-pointer bg-slate-600 text-slate-50 hover:bg-slate-500/80"
@click="clearTemporaryVideoFiles()"
>
Clear temporary video storage
</span>
<span class="text-lg font-medium">Clear temporary video storage</span>
<span class="text-sm text-slate-300/90">Current size: {{ formatBytes(temporaryDbSize) }}</span>
</div>
</template>
</BaseConfigurationView>
</template>
Expand All @@ -103,6 +104,7 @@ import { storeToRefs } from 'pinia'
import { ref } from 'vue'
import { onMounted } from 'vue'
import { formatBytes } from '@/libs/utils'
import { useVideoStore } from '@/stores/video'
import BaseConfigurationView from './BaseConfigurationView.vue'
Expand Down Expand Up @@ -131,7 +133,7 @@ const fetchVideoAndLogsData = async (): Promise<void> => {
// Fetch temporary video data from the storage
const fetchTemporaryDbSize = async (): Promise<void> => {
const size = await videoStore.tempVideoChunksDB.length()
const size = await videoStore.temporaryVideoDBSize()
temporaryDbSize.value = size
}
Expand Down

0 comments on commit 7a84773

Please sign in to comment.