diff --git a/backend/subscriptions.js b/backend/subscriptions.js index ee0ff7b..b957d68 100644 --- a/backend/subscriptions.js +++ b/backend/subscriptions.js @@ -139,17 +139,10 @@ async function unsubscribe(sub, deleteMode, user_uid = null) { const appendedBasePath = getAppendedBasePath(sub, basePath); if (deleteMode && (await fs.pathExists(appendedBasePath))) { - if (sub.archive && (await fs.pathExists(sub.archive))) { - const archive_file_path = path.join(sub.archive, 'archive.txt'); - // deletes archive if it exists - // TODO: Keep entries in blacklist_video.txt by moving them to a global blacklist - if (await fs.pathExists(archive_file_path)) { - await fs.unlink(archive_file_path); - } - await fs.rmdir(sub.archive); - } await fs.remove(appendedBasePath); } + + await db_api.removeAllRecords('archives', {sub_id: sub.id}); } async function deleteSubscriptionFile(sub, file, deleteForever, file_uid = null, user_uid = null) { diff --git a/backend/utils.js b/backend/utils.js index b5e460f..f634b41 100644 --- a/backend/utils.js +++ b/backend/utils.js @@ -220,51 +220,6 @@ function deleteJSONFile(file_path, type) { if (fs.existsSync(alternate_json_path)) fs.unlinkSync(alternate_json_path); } -// archive helper functions - -async function removeIDFromArchive(archive_path, type, id) { - const archive_file = path.join(archive_path, `archive_${type}.txt`); - const data = await fs.readFile(archive_file, {encoding: 'utf-8'}); - if (data === null || data === undefined) { - logger.error('Archive could not be found.'); - return; - } - - let dataArray = data.split('\n'); // convert file data in an array - const searchKeyword = id; // we are looking for a line, contains, key word id in the file - let foundLine = dataArray.find(line => line.includes(searchKeyword)); - - dataArray = dataArray.filter(line => !line.includes(searchKeyword)); - - if (!foundLine) return null; - else foundLine = foundLine.trim(); - - // UPDATE FILE WITH NEW DATA - const updatedData = dataArray.join('\n'); - await fs.writeFile(archive_file, updatedData); - if (foundLine) return Array.isArray(foundLine) && foundLine.length === 1 ? foundLine[0] : foundLine; -} - -async function writeToBlacklist(archive_folder, type, line) { - let blacklistPath = path.join(archive_folder, (type === 'audio') ? 'blacklist_audio.txt' : 'blacklist_video.txt'); - // adds newline to the beginning of the line - line.replace('\n', ''); - line.replace('\r', ''); - line = '\n' + line; - await fs.appendFile(blacklistPath, line); -} - -async function deleteFileFromArchive(uid, type, archive_path, id, blacklistMode) { - const archive_file = path.join(archive_path, `archive_${type}.txt`); - if (await fs.pathExists(archive_path)) { - const line = id ? await removeIDFromArchive(archive_path, type, id) : null; - if (blacklistMode && line) await writeToBlacklist(archive_path, type, line); - } else { - logger.info(`Could not find archive file for file ${uid}. Creating...`); - await fs.close(await fs.open(archive_file, 'w')); - } -} - function durationStringToNumber(dur_str) { if (typeof dur_str === 'number') return dur_str; let num_sum = 0; @@ -564,9 +519,6 @@ module.exports = { getExpectedFileSize: getExpectedFileSize, fixVideoMetadataPerms: fixVideoMetadataPerms, deleteJSONFile: deleteJSONFile, - removeIDFromArchive: removeIDFromArchive, - writeToBlacklist: writeToBlacklist, - deleteFileFromArchive: deleteFileFromArchive, getDownloadedFilesByType: getDownloadedFilesByType, createContainerZipFile: createContainerZipFile, durationStringToNumber: durationStringToNumber,