Lil fixes
All checks were successful
ci / Image build (push) Successful in 2m8s
ci / Deployment (push) Successful in 21s

This commit is contained in:
Joris Bertomeu
2025-08-25 14:40:05 +02:00
parent 02486aa6f6
commit aba85207e7
2 changed files with 186 additions and 16 deletions

View File

@@ -186,30 +186,72 @@ const processUpdate = async (data) => {
try {
let downloadURL = data.binType === 'downloader' ? data.details.remoteInfos.browser_download_url : data.details.remoteInfos.downloadUrl;
let filename = data.binType === 'downloader' ? data.details.remoteInfos.name : data.details.remoteInfos.filename;
fs.mkdirSync(tmpUpdatePath);
fs.mkdirSync(tmpUpdatePath, { recursive: true });
const zipDest = `${tmpUpdatePath}/${filename}`;
console.log('Will download file from ' + downloadURL);
await downloadFile(downloadURL, zipDest);
console.log('File downloaded to ' + zipDest)
console.log('Will decompress downloaded file');
const unzippedFolderDest = `${tmpUpdatePath}/${data.binType}_tmp`
fs.mkdirSync(unzippedFolderDest);
fs.mkdirSync(unzippedFolderDest, { recursive: true });
await extractFile(zipDest, unzippedFolderDest);
console.log('Unzipped !');
const uncompressedFoldersS = fs.readdirSync(unzippedFolderDest);
console.log(uncompressedFoldersS)
if (uncompressedFoldersS.length !== 1)
throw new Error('Unable to retrieve decompressed folder');
const uncompressedFolders = fs.readdirSync(`${unzippedFolderDest}/${uncompressedFoldersS[0]}`);
if (uncompressedFolders.length === 0)
throw new Error('Unable to retrieve archive content');
if (data.binType === 'downloader')
fs.renameSync(`${unzippedFolderDest}/${uncompressedFoldersS[0]}/${uncompressedFolders[0]}`, data.details.localInfos.path);
else if (data.binType === 'mp4decrypt')
fs.renameSync(`${unzippedFolderDest}/${uncompressedFoldersS[0]}/bin/mp4decrypt`, data.details.localInfos.path);
const extractedItems = fs.readdirSync(unzippedFolderDest);
console.log('Extracted items:', extractedItems);
if (extractedItems.length === 0) {
throw new Error('No files found after extraction');
}
if (data.binType === 'downloader') {
let binaryPath = null;
for (const item of extractedItems) {
const itemPath = `${unzippedFolderDest}/${item}`;
const stat = fs.statSync(itemPath);
if (stat.isFile() && (item === 'N_m3u8DL-RE' || item.includes('N_m3u8DL-RE'))) {
binaryPath = itemPath;
break;
} else if (stat.isDirectory()) {
const subItems = fs.readdirSync(itemPath);
const binary = subItems.find(subItem =>
subItem === 'N_m3u8DL-RE' || subItem.includes('N_m3u8DL-RE')
);
if (binary) {
binaryPath = `${itemPath}/${binary}`;
break;
}
}
}
if (!binaryPath) {
throw new Error('N_m3u8DL-RE binary not found in archive');
}
fs.renameSync(binaryPath, data.details.localInfos.path);
} else if (data.binType === 'mp4decrypt') {
if (extractedItems.length !== 1) {
throw new Error('Unable to retrieve decompressed folder for mp4decrypt');
}
const mainFolder = `${unzippedFolderDest}/${extractedItems[0]}`;
const mp4decryptPath = `${mainFolder}/bin/mp4decrypt`;
if (!fs.existsSync(mp4decryptPath)) {
throw new Error('mp4decrypt binary not found at expected path: bin/mp4decrypt');
}
fs.renameSync(mp4decryptPath, data.details.localInfos.path);
}
fs.chmodSync(data.details.localInfos.path, 0o755);
writeBinVersion(`${BIN_PATH}/.${data.binType}.version`, data.details.remoteInfos[data.binType === 'downloader' ? 'id' : 'version'])
} catch(e) {
console.error('Error during update process:', e);
throw e;
} finally {
fs.rmSync(tmpUpdatePath, { recursive: true, force: true });