From ad3084b59502b3359c52d407dff1092bbc9761b6 Mon Sep 17 00:00:00 2001 From: Marko Kajzer Date: Sun, 29 Nov 2020 21:59:32 +0100 Subject: [PATCH] fix: correctly rename file after modification --- src/commands/manage/ModifyCommand.ts | 16 ++++++++-------- src/commands/manage/modify/FileInfo.ts | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/commands/manage/ModifyCommand.ts b/src/commands/manage/ModifyCommand.ts index d18fc244..f23978e0 100644 --- a/src/commands/manage/ModifyCommand.ts +++ b/src/commands/manage/ModifyCommand.ts @@ -63,25 +63,25 @@ export class ModifyCommand extends Command { } } - private modifyVolume({ currentFile, newFile }: FileInfo, ...params: string[]): Promise { + private modifyVolume({ currentFile, tempFile }: FileInfo, ...params: string[]): Promise { const [value] = params; const ffmpegCommand = ffmpeg(currentFile) .audioFilters([{ filter: 'volume', options: value }]) - .output(newFile); + .output(tempFile); return new Promise((resolve, reject) => ffmpegCommand.on('end', resolve).on('error', reject).run() ); } - private clipSound({ currentFile, newFile }: FileInfo, ...params: string[]): Promise { + private clipSound({ currentFile, tempFile }: FileInfo, ...params: string[]): Promise { const [startTime, endTime] = params; // NOTE: We checked params already, so start is definitely here const start = getSecondsFromTime(startTime)!; const end = getSecondsFromTime(endTime); - let ffmpegCommand = ffmpeg(currentFile).output(newFile).setStartTime(start); + let ffmpegCommand = ffmpeg(currentFile).output(tempFile).setStartTime(start); if (end) ffmpegCommand = ffmpegCommand.setDuration(end - start); return new Promise((resolve, reject) => @@ -89,8 +89,8 @@ export class ModifyCommand extends Command { ); } - private replace({ currentFile, newFile }: FileInfo) { - return rename(currentFile, newFile); + private replace({ currentFile, tempFile }: FileInfo): Promise { + return rename(tempFile, currentFile); } private getFileNameFor(sound: string): FileInfo { @@ -98,9 +98,9 @@ export class ModifyCommand extends Command { const currentFile = `./sounds/${sound}.${extension}`; const timestamp = Date.now(); - const newFile = `./sounds/${sound}-${timestamp}.${extension}`; + const tempFile = `./sounds/${sound}-${timestamp}.${extension}`; - return { currentFile, newFile }; + return { currentFile, tempFile }; } private handleError(message: Message, error: Error, { modifier, sound }: ErrorParams) { diff --git a/src/commands/manage/modify/FileInfo.ts b/src/commands/manage/modify/FileInfo.ts index 213947ce..11ddfb4a 100644 --- a/src/commands/manage/modify/FileInfo.ts +++ b/src/commands/manage/modify/FileInfo.ts @@ -1,4 +1,4 @@ export default interface FileInfo { currentFile: string; - newFile: string; + tempFile: string; }