mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
题目搜索,收藏功能
This commit is contained in:
1 parent
a248425db6
commit
441eeadaf3
23 files changed
+158
-97
No files matched your search
+13
-11
@@ -1,17 +1,19 @@
|
||||
const superagent = require('superagent');
|
||||
const fs = require('fs');
|
||||
|
||||
async function download(url, path, retry = 3) {
|
||||
if (path) {
|
||||
const w = await fs.createWriteStream(path);
|
||||
await superagent.get(url).retry(retry).pipe(w);
|
||||
await new Promise((resolve, reject) => {
|
||||
w.on('finish', resolve);
|
||||
w.on('error', reject);
|
||||
});
|
||||
return path;
|
||||
}
|
||||
return superagent.get(url);
|
||||
async function _download(url, path, retry) {
|
||||
const w = fs.createWriteStream(path);
|
||||
await superagent.get(url).retry(retry).pipe(w);
|
||||
await new Promise((resolve, reject) => {
|
||||
w.on('finish', resolve);
|
||||
w.on('error', reject);
|
||||
});
|
||||
return path;
|
||||
}
|
||||
|
||||
function download(url, path, retry = 3) {
|
||||
if (path) return _download(url, path, retry);
|
||||
return superagent.get(url).retry(retry);
|
||||
}
|
||||
|
||||
global.Hydro.lib.download = module.exports = download;
|
||||
+2
-2
@@ -60,8 +60,8 @@ async function del(id) {
|
||||
fs.unlinkSync(root(`${moduleRoot}/${id}.hydro`));
|
||||
}
|
||||
|
||||
async function install(url) {
|
||||
await download(url, root(`${moduleRoot}/${String.random(16)}.hydro`));
|
||||
function install(url) {
|
||||
return download(url, root(`${moduleRoot}/${String.random(16)}.hydro`));
|
||||
}
|
||||
|
||||
global.Hydro.lib.hpm = module.exports = {
|
||||
|
||||
Reference in new issue
Block a user