From c795c39d947862071b50468eccc60068f7916344 Mon Sep 17 00:00:00 2001 From: Jarian Cottingham Date: Sat, 21 Feb 2026 15:47:48 -0600 Subject: [PATCH] Add functionality to move tagged files to extra/commentary folders --- main.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- renderer.js | 22 ++++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index d628da0..86405c9 100644 --- a/main.js +++ b/main.js @@ -102,9 +102,11 @@ ipcMain.handle('rename-file', async (event, { oldPath, newName }) => { return { success: false, error: 'Original file does not exist' }; } - // Check if new name is different - if (oldPath === newPath) { - return { success: true, message: 'File name unchanged' }; + // Check if file is writable + try { + fs.accessSync(oldPath, fs.constants.W_OK); + } catch (err) { + return { success: false, error: 'File is not writable' }; } // Rename the file @@ -116,6 +118,49 @@ ipcMain.handle('rename-file', async (event, { oldPath, newName }) => { } }); +// IPC handler for moving file to folder +ipcMain.handle('move-file-to-folder', async (event, { filePath, folderName }) => { + try { + const fs = require('fs'); + const path = require('path'); + + // Check if file exists + if (!fs.existsSync(filePath)) { + return { success: false, error: 'File does not exist' }; + } + + // Validate folder name + if (folderName !== 'extra' && folderName !== 'commentary') { + return { success: false, error: 'Invalid folder name. Must be "extra" or "commentary"' }; + } + + // Get directory containing the file + const fileDir = path.dirname(filePath); + const targetFolder = path.join(fileDir, folderName); + + // Create the target folder if it doesn't exist + if (!fs.existsSync(targetFolder)) { + fs.mkdirSync(targetFolder, { recursive: true }); + } + + // Generate new file path + const fileName = path.basename(filePath); + const newFilePath = path.join(targetFolder, fileName); + + // Check if file with same name already exists in target folder + if (fs.existsSync(newFilePath)) { + return { success: false, error: 'File with same name already exists in target folder' }; + } + + // Move the file + fs.renameSync(filePath, newFilePath); + + return { success: true, message: `File moved to ${folderName} folder successfully` }; + } catch (error) { + return { success: false, error: error.message }; + } +}); + // IPC handler for searching TVDB ipcMain.handle('search-tvdb', async (event, query) => { try { diff --git a/renderer.js b/renderer.js index 867ee48..1950aa0 100644 --- a/renderer.js +++ b/renderer.js @@ -260,6 +260,28 @@ function addTagToEpisode(filePath, tagType) { console.log(`File ${filePath} tagged as ${tagType} - would be saved in real implementation`); } +// Function to move tagged files to appropriate folders +function moveTaggedFile(filePath, tagType) { + console.log(`Moving file ${filePath} to ${tagType} folder`); + + // Send request to main process to move the file + ipcRenderer.invoke('move-file-to-folder', { + filePath: filePath, + folderName: tagType + }).then(result => { + if (result.success) { + console.log(`File moved successfully to ${tagType} folder`); + // Optional: Update UI to reflect that the file has been moved + } else { + console.error(`Failed to move file: ${result.error}`); + alert(`Failed to move file: ${result.error}`); + } + }).catch(error => { + console.error('Error moving file:', error); + alert(`Error moving file: ${error.message}`); + }); +} + // Function to handle untagging function untagFile(filePath, tagType) { console.log(`Untagging file ${filePath} from ${tagType}`);