Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(timelapse): renaming a .zip file caused extension to become .mp4 #992

Merged
merged 8 commits into from
Aug 1, 2022
Prev Previous commit
Next Next commit
refactor: return early if file-extension is not mp4
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
  • Loading branch information
dw-0 committed Aug 1, 2022
commit 4bd9a4fdda1fff2bf52fca6b80c7be0da6ae5c7d
12 changes: 9 additions & 3 deletions src/components/panels/Timelapse/TimelapseFilesPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ export default class TimelapseFilesPanel extends Mixins(BaseMixin) {
const posLastPoint = this.dialogRenameFile.item.filename.lastIndexOf('.')
const oldNameWithoutExtension = this.dialogRenameFile.item.filename.slice(0, posLastPoint)
const fileExtension = this.dialogRenameFile.item.filename.split('.').pop()
const fileJpg = this.files.find((file) => file.filename === `${oldNameWithoutExtension}.jpg`)

this.dialogRenameFile.show = false

Expand All @@ -654,10 +653,14 @@ export default class TimelapseFilesPanel extends Mixins(BaseMixin) {
{ action: 'files/getMove' }
)

if (fileExtension !== 'mp4') return

/**
* mp4 and jpg always require to have the same name as the
* jpg is used as a mp4-thumbnail in the timelapse file-browser
*/
const fileJpg = this.files.find((file) => file.filename === `${oldNameWithoutExtension}.jpg`)

if (fileJpg && fileExtension === 'mp4') {
this.$socket.emit('server.files.move', {
source: `${this.currentPath}/${oldNameWithoutExtension}.jpg`,
Expand Down Expand Up @@ -691,8 +694,6 @@ export default class TimelapseFilesPanel extends Mixins(BaseMixin) {
removeFile() {
const filename = this.contextMenu.item.filename.slice(0, this.contextMenu.item.filename.lastIndexOf('.'))
const fileExtension = this.contextMenu.item.filename.split('.').pop()
const previewFilename = filename + '.jpg'
const previewExists = this.files.findIndex((file) => file.filename === previewFilename) !== -1

/**
* delete the file regardless of its file-extension
Expand All @@ -703,9 +704,14 @@ export default class TimelapseFilesPanel extends Mixins(BaseMixin) {
{ action: 'files/getDeleteFile' }
)

if (fileExtension !== 'mp4') return

/**
* if file-extension is mp4, also delete its corresponding thumbnail jpg
*/
const previewFilename = filename + '.jpg'
const previewExists = this.files.findIndex((file) => file.filename === previewFilename) !== -1

if (previewExists && fileExtension === 'mp4')
this.$socket.emit(
'server.files.delete_file',
Expand Down