-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: startup works now with only a restore file, but no queue file feature: mega-nz download full filepaths by default, but have a switch to ignore them polish: have prettier use semicolon
- Loading branch information
1 parent
7eb7ebb
commit 20eed6b
Showing
23 changed files
with
590 additions
and
524 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
--- | ||
printWidth: 120 | ||
semi: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
#!/usr/bin/env node | ||
"use strict" | ||
"use strict"; | ||
|
||
const fs = require("fs") | ||
const { promisify } = require("util") | ||
const { versionText, usageText, parseArgs } = require("../src/args") | ||
const { queue } = require("../src/") | ||
const { versionText, usageText, parseArgs } = require("../src/args"); | ||
const { tryAccess } = require("../src/helper"); | ||
const { queue } = require("../src/"); | ||
|
||
const access = promisify(fs.access) | ||
|
||
;(async () => { | ||
let options | ||
(async () => { | ||
let options; | ||
try { | ||
options = await parseArgs(process.argv.slice(2)) | ||
options = await parseArgs(process.argv.slice(2)); | ||
} catch (err) { | ||
console.error("error:", err.message) | ||
return | ||
console.error("error:", err.message); | ||
return; | ||
} | ||
|
||
if (!options || options.help) { | ||
return console.info(usageText()) | ||
return console.info(usageText()); | ||
} | ||
|
||
if (options.version) { | ||
return console.info(versionText()) | ||
return console.info(versionText()); | ||
} | ||
|
||
try { | ||
await access(options.queueFile) | ||
} catch (err) { | ||
return console.error(`error: could not access ${options.queueFile}`) | ||
const queueFile = options.restoreFile || options.queueFile; | ||
if (!(await tryAccess(queueFile))) { | ||
return console.error(`error: could not access ${queueFile}`); | ||
} | ||
await queue(options) | ||
})() | ||
|
||
await queue(options); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
#!/usr/bin/env node | ||
"use strict" | ||
"use strict"; | ||
|
||
const fs = require("fs") | ||
const path = require("path") | ||
const { promisify } = require("util") | ||
const { spawn, execSync } = require("child_process") | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { promisify } = require("util"); | ||
const { spawn, execSync } = require("child_process"); | ||
|
||
const open = promisify(fs.open) | ||
const readFile = promisify(fs.readFile) | ||
const writeFile = promisify(fs.writeFile) | ||
const open = promisify(fs.open); | ||
const readFile = promisify(fs.readFile); | ||
const writeFile = promisify(fs.writeFile); | ||
|
||
const PID_FILE = "qget.pid" | ||
const LOG_FILE = "qget.txt" | ||
const SCRIPT = path.join(__dirname, "cli.js") | ||
const PID_FILE = "qget.pid"; | ||
const LOG_FILE = "qget.txt"; | ||
const SCRIPT = path.join(__dirname, "cli.js"); | ||
|
||
const _kill = (pid) => { | ||
if (Number.isFinite(pid)) { | ||
const killCommand = process.platform === "win32" ? `taskkill /f /pid ${pid}` : `kill ${pid}` | ||
execSync(killCommand, { stdio: "ignore" }) | ||
const killCommand = process.platform === "win32" ? `taskkill /f /pid ${pid}` : `kill ${pid}`; | ||
execSync(killCommand, { stdio: "ignore" }); | ||
} | ||
} | ||
}; | ||
|
||
;(async () => { | ||
const [command] = process.argv.slice(2) | ||
(async () => { | ||
const [command] = process.argv.slice(2); | ||
try { | ||
const pid = parseFloat((await readFile(PID_FILE)).toString()) | ||
_kill(pid) | ||
const pid = parseFloat((await readFile(PID_FILE)).toString()); | ||
_kill(pid); | ||
// eslint-disable-next-line no-empty | ||
} catch (err) {} | ||
if (/(?:stop|kill)/gi.test(command)) { | ||
console.log("stopping queueget") | ||
process.exit(0) | ||
console.log("stopping queueget"); | ||
process.exit(0); | ||
} | ||
|
||
const foutlog = await open(LOG_FILE, "w") | ||
const foutlog = await open(LOG_FILE, "w"); | ||
const child = spawn(process.execPath, [SCRIPT].concat(process.argv.slice(2)), { | ||
stdio: ["ignore", foutlog, foutlog], | ||
detached: true, | ||
}) | ||
await writeFile(PID_FILE, String(child.pid)) | ||
child.unref() | ||
})() | ||
}); | ||
await writeFile(PID_FILE, String(child.pid)); | ||
child.unref(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"use strict"; | ||
const TIME_UNITS = Object.freeze({ | ||
YEAR: "year", | ||
MONTH: "month", | ||
DAY: "day", | ||
HOUR: "hour", | ||
MINUTE: "minute", | ||
SECOND: "second", | ||
}); | ||
|
||
const TIME_UNIT_LIMITS = { | ||
[TIME_UNITS.YEAR]: 24 * 60 * 60 * 1000 * 365, | ||
[TIME_UNITS.MONTH]: (24 * 60 * 60 * 1000 * 365) / 12, | ||
[TIME_UNITS.DAY]: 24 * 60 * 60 * 1000, | ||
[TIME_UNITS.HOUR]: 60 * 60 * 1000, | ||
[TIME_UNITS.MINUTE]: 60 * 1000, | ||
[TIME_UNITS.SECOND]: 1000, | ||
}; | ||
|
||
const _getRelativeDateTime = (d1, d2) => { | ||
let elapsed = d1 - d2; | ||
const result = []; | ||
for (const [unit, limit] of Object.entries(TIME_UNIT_LIMITS)) { | ||
if (Math.abs(elapsed) > limit || unit === TIME_UNITS.SECOND) { | ||
const diff = Math.trunc(elapsed / limit); | ||
elapsed -= limit * diff; | ||
result.push(`${diff} ${diff <= 1 ? unit : unit + "s"}`); | ||
} | ||
} | ||
return result.join(" "); | ||
}; | ||
|
||
const readableRelativeDateTime = (value, now = new Date()) => { | ||
if (!value) return ""; | ||
return _getRelativeDateTime(value, now); | ||
}; | ||
|
||
module.exports = { | ||
readableRelativeDateTime, | ||
}; |
Oops, something went wrong.