mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
模块管理器
This commit is contained in:
1 parent
04941936bc
commit
3e9b074e77
22 files changed
+191
-59
No files matched your search
@@ -0,0 +1,39 @@
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable no-eval */
|
||||
const fs = require('fs');
|
||||
const zlib = require('zlib');
|
||||
const path = require('path');
|
||||
const yaml = require('js-yaml');
|
||||
const download = require('./download');
|
||||
|
||||
function root(name) {
|
||||
return path.resolve(process.cwd(), name);
|
||||
}
|
||||
|
||||
async function getInstalled() {
|
||||
const files = fs.readdirSync(root('.build/module'));
|
||||
const installed = [];
|
||||
for (const file of files) {
|
||||
if (file.endsWith('.hydro-module')) {
|
||||
const f = fs.readFileSync(root(`.build/module/${file}`));
|
||||
const s = fs.statSync(root(`.build/module/${file}`));
|
||||
installed.push({
|
||||
...yaml.safeLoad(zlib.gunzipSync(f)),
|
||||
id: file.split('.')[0],
|
||||
size: s.size,
|
||||
});
|
||||
}
|
||||
}
|
||||
return installed;
|
||||
}
|
||||
|
||||
async function del(id) {
|
||||
fs.unlinkSync(root(`.build/module/${id}.hydro-module`));
|
||||
}
|
||||
|
||||
async function install(id, url) {
|
||||
await download(url, root(`module/${id}.hydro-module`));
|
||||
}
|
||||
|
||||
module.exports = { getInstalled, del, install };
|
||||
+1
-1
@@ -36,7 +36,7 @@ exports.paginate = function* paginate(page, numPages) {
|
||||
yield ['last', numPages];
|
||||
};
|
||||
|
||||
exports.format_size = function formatSize(size, base = 1) {
|
||||
exports.size = function formatSize(size, base = 1) {
|
||||
size *= base;
|
||||
const unit = 1024;
|
||||
const unitNames = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
||||
|
||||
+1
-1
@@ -13,6 +13,6 @@ Item('/p', 'problem_main', 'problem', permission.PERM_VIEW_PROBLEM);
|
||||
Item('/t', 'training_main', 'training', permission.PERM_VIEW_TRAINING);
|
||||
Item('/discuss', 'discussion_main', 'discussion', permission.PERM_VIEW_DISCUSSION);
|
||||
Item('/c', 'contest_main', 'contest', permission.PERM_VIEW_CONTEST);
|
||||
Item('/manage', 'domain_manage', 'domain_manage', permission.PERM_MANAGE);
|
||||
Item('/manage', 'manage', 'manage', permission.PERM_MANAGE);
|
||||
|
||||
global.Hydro.lib.nav = module.exports = Item;
|
||||
Reference in new issue
Block a user