Add functionality to move tagged files to extra/commentary folders

This commit is contained in:
Jarian Cottingham 2026-02-21 15:47:48 -06:00
parent 3f837ccf94
commit c795c39d94
2 changed files with 70 additions and 3 deletions

51
main.js
View File

@ -102,9 +102,11 @@ ipcMain.handle('rename-file', async (event, { oldPath, newName }) => {
return { success: false, error: 'Original file does not exist' }; return { success: false, error: 'Original file does not exist' };
} }
// Check if new name is different // Check if file is writable
if (oldPath === newPath) { try {
return { success: true, message: 'File name unchanged' }; fs.accessSync(oldPath, fs.constants.W_OK);
} catch (err) {
return { success: false, error: 'File is not writable' };
} }
// Rename the file // 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 // IPC handler for searching TVDB
ipcMain.handle('search-tvdb', async (event, query) => { ipcMain.handle('search-tvdb', async (event, query) => {
try { try {

View File

@ -260,6 +260,28 @@ function addTagToEpisode(filePath, tagType) {
console.log(`File ${filePath} tagged as ${tagType} - would be saved in real implementation`); 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 to handle untagging
function untagFile(filePath, tagType) { function untagFile(filePath, tagType) {
console.log(`Untagging file ${filePath} from ${tagType}`); console.log(`Untagging file ${filePath} from ${tagType}`);