|
|
|
@ -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,
|
|
|
|
|