mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 21:28:06 +00:00
chore: format codes
This commit is contained in:
parent
6922c716e2
commit
9351f6bc89
73 changed files with 2321 additions and 2321 deletions
|
|
@ -1,15 +1,15 @@
|
|||
// node module
|
||||
const fs = require("fs");
|
||||
const https = require("https");
|
||||
const resolve = require("path").resolve;
|
||||
const join = require("path").resolve;
|
||||
const extract = require("extract-zip");
|
||||
const fs = require('fs');
|
||||
const https = require('https');
|
||||
const resolve = require('path').resolve;
|
||||
const join = require('path').resolve;
|
||||
const extract = require('extract-zip');
|
||||
|
||||
// 函数参数
|
||||
const dest = resolve(__dirname, "../");
|
||||
const fileName = "NeteaseCloudMusicApi-master.zip";
|
||||
const dest = resolve(__dirname, '../');
|
||||
const fileName = 'NeteaseCloudMusicApi-master.zip';
|
||||
const options = {
|
||||
hostname: "github.91chifun.workers.dev",
|
||||
hostname: 'github.91chifun.workers.dev',
|
||||
path: `//https://github.com/Binaryify/NeteaseCloudMusicApi/archive/master.zip`,
|
||||
};
|
||||
|
||||
|
|
@ -27,13 +27,13 @@ function fix2(number) {
|
|||
|
||||
async function download(options, fileName, callback) {
|
||||
return await new Promise((resolve, reject) => {
|
||||
const destPath = join(__dirname, "../" + fileName);
|
||||
const destPath = join(__dirname, '../' + fileName);
|
||||
// Check if exist
|
||||
if (fs.existsSync(destPath)) return resolve(destPath);
|
||||
|
||||
const file = fs.createWriteStream(destPath);
|
||||
const request = https.get(options, (res) => {
|
||||
let len = res.headers && parseInt(res.headers["content-length"], 10);
|
||||
const request = https.get(options, res => {
|
||||
let len = res.headers && parseInt(res.headers['content-length'], 10);
|
||||
let cur = 0;
|
||||
// 1048576 - bytes in 1Megabyte
|
||||
const MEGA = 1048576;
|
||||
|
|
@ -43,10 +43,10 @@ async function download(options, fileName, callback) {
|
|||
}
|
||||
if (!len) {
|
||||
console.log(
|
||||
"Downloading, but can not get content-length, please be patient."
|
||||
'Downloading, but can not get content-length, please be patient.'
|
||||
);
|
||||
}
|
||||
res.on("data", (chunk) => {
|
||||
res.on('data', chunk => {
|
||||
if (len) {
|
||||
cur += chunk.length;
|
||||
console.log(
|
||||
|
|
@ -56,22 +56,22 @@ async function download(options, fileName, callback) {
|
|||
);
|
||||
}
|
||||
});
|
||||
res.on("end", () => {
|
||||
callback("Downloading complete!");
|
||||
res.on('end', () => {
|
||||
callback('Downloading complete!');
|
||||
});
|
||||
res.pipe(file);
|
||||
file.on("finish", () => {
|
||||
file.on('finish', () => {
|
||||
file.close(() => {
|
||||
callback("File wrote complete!");
|
||||
callback('File wrote complete!');
|
||||
resolve(destPath);
|
||||
});
|
||||
});
|
||||
file.on("error", (err) => {
|
||||
file.on('error', err => {
|
||||
fs.unlink(destPath);
|
||||
reject(err);
|
||||
});
|
||||
request.on("error", (err) => {
|
||||
console.log("Error: " + err.message);
|
||||
request.on('error', err => {
|
||||
console.log('Error: ' + err.message);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -82,21 +82,21 @@ async function unzip(source, target) {
|
|||
await extract(source, {
|
||||
dir: target,
|
||||
});
|
||||
console.log("Extraction complete");
|
||||
console.log('Extraction complete');
|
||||
return true;
|
||||
} catch (err) {
|
||||
// handle any errors
|
||||
if (err.message === "end of central directory record signature not found") {
|
||||
console.log("Not a full_downloaded zip file, removed!");
|
||||
if (err.message === 'end of central directory record signature not found') {
|
||||
console.log('Not a full_downloaded zip file, removed!');
|
||||
fs.unlinkSync(source);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Download process
|
||||
download(options, fileName, (text) => {
|
||||
download(options, fileName, text => {
|
||||
console.log(text);
|
||||
}).then((path) => {
|
||||
}).then(path => {
|
||||
console.log(path);
|
||||
// Unzip process
|
||||
return unzip(path, dest);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue