mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix electron script
This commit is contained in:
+33
-4
@@ -43,6 +43,7 @@ const downloadWithProgress = (url) =>
|
|||||||
incomplete: ' ',
|
incomplete: ' ',
|
||||||
width: 20,
|
width: 20,
|
||||||
total: len,
|
total: len,
|
||||||
|
stream: process.stdout,
|
||||||
});
|
});
|
||||||
res.on('data', (chunk) => {
|
res.on('data', (chunk) => {
|
||||||
chunks.push(chunk);
|
chunks.push(chunk);
|
||||||
@@ -85,24 +86,52 @@ const downloadAndExtract = async (url, destinationPath) => {
|
|||||||
if (fs.pathExistsSync(binPath)) {
|
if (fs.pathExistsSync(binPath)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log(`Downloading IPFS client from ${url} to ${destinationPath}`);
|
||||||
const split = url.split('/');
|
const split = url.split('/');
|
||||||
const fileName = split[split.length - 1];
|
const fileName = split[split.length - 1];
|
||||||
const dowloadPath = path.join(destinationPath, fileName);
|
const dowloadPath = path.join(destinationPath, fileName);
|
||||||
const file = await downloadWithProgress(url);
|
const file = await downloadWithProgress(url);
|
||||||
fs.ensureDirSync(destinationPath);
|
fs.ensureDirSync(destinationPath);
|
||||||
await fs.writeFile(dowloadPath, file);
|
await fs.writeFile(dowloadPath, file);
|
||||||
await decompress(dowloadPath, destinationPath);
|
console.log(`Downloaded archive to ${dowloadPath}`);
|
||||||
|
console.log(`Extracting ${dowloadPath} to ${destinationPath}`);
|
||||||
|
try {
|
||||||
|
await decompress(dowloadPath, destinationPath);
|
||||||
|
console.log('Decompression complete');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error during decompression:', err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
const extractedPath = path.join(destinationPath, 'kubo');
|
const extractedPath = path.join(destinationPath, 'kubo');
|
||||||
const extractedBinPath = path.join(extractedPath, binName);
|
const extractedBinPath = path.join(extractedPath, binName);
|
||||||
|
console.log(`Moving binary from ${extractedBinPath} to ${binPath}`);
|
||||||
fs.moveSync(extractedBinPath, binPath);
|
fs.moveSync(extractedBinPath, binPath);
|
||||||
|
console.log('Binary moved');
|
||||||
|
console.log('Cleaning up temporary files');
|
||||||
fs.removeSync(extractedPath);
|
fs.removeSync(extractedPath);
|
||||||
fs.removeSync(dowloadPath);
|
fs.removeSync(dowloadPath);
|
||||||
|
console.log('Cleanup complete');
|
||||||
};
|
};
|
||||||
|
|
||||||
export const downloadIpfsClients = async () => {
|
export const downloadIpfsClients = async () => {
|
||||||
await downloadAndExtract(ipfsClientWindowsUrl, ipfsClientWindowsPath);
|
const platform = process.platform;
|
||||||
await downloadAndExtract(ipfsClientMacUrl, ipfsClientMacPath);
|
console.log(`Starting IPFS client download for platform: ${platform}`);
|
||||||
await downloadAndExtract(ipfsClientLinuxUrl, ipfsClientLinuxPath);
|
switch (platform) {
|
||||||
|
case 'win32':
|
||||||
|
await downloadAndExtract(ipfsClientWindowsUrl, ipfsClientWindowsPath);
|
||||||
|
break;
|
||||||
|
case 'darwin':
|
||||||
|
await downloadAndExtract(ipfsClientMacUrl, ipfsClientMacPath);
|
||||||
|
break;
|
||||||
|
case 'linux':
|
||||||
|
await downloadAndExtract(ipfsClientLinuxUrl, ipfsClientLinuxPath);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.warn(`Unknown platform: ${platform}, downloading all IPFS clients`);
|
||||||
|
await downloadAndExtract(ipfsClientWindowsUrl, ipfsClientWindowsPath);
|
||||||
|
await downloadAndExtract(ipfsClientMacUrl, ipfsClientMacPath);
|
||||||
|
await downloadAndExtract(ipfsClientLinuxUrl, ipfsClientLinuxPath);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async (context) => {
|
export default async (context) => {
|
||||||
|
|||||||
@@ -1,2 +1,13 @@
|
|||||||
import { downloadIpfsClients } from './before-pack.js';
|
import { downloadIpfsClients } from './before-pack.js';
|
||||||
downloadIpfsClients();
|
|
||||||
|
// Wrap the download in an async IIFE and exit when done
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
await downloadIpfsClients();
|
||||||
|
console.log('IPFS clients downloaded successfully.');
|
||||||
|
process.exit(0);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('IPFS clients download error:', err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user