mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
Hello Typescript!
This commit is contained in:
1 parent
c9b6412527
commit
ba03d7a7bf
98 files changed
+3186
-2616
No files matched your search
@@ -0,0 +1,68 @@
|
||||
// TODO check more
|
||||
|
||||
import os from 'os';
|
||||
import superagent from 'superagent';
|
||||
import * as system from './model/system';
|
||||
import * as db from './service/db';
|
||||
|
||||
const c = {};
|
||||
|
||||
async function checkDb(log, warn, error) {
|
||||
try {
|
||||
const coll = db.collection('check');
|
||||
const d = await coll.findOne({ _id: 'check' });
|
||||
if (!d) await coll.insertOne({ _id: 'check', value: 'check' });
|
||||
await coll.createIndex('check');
|
||||
await coll.deleteOne({ _id: 'check' });
|
||||
await coll.drop();
|
||||
} catch (e) {
|
||||
error(`Mongo Error: Database read-write failed.\n${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function checkPerm(log, warn) {
|
||||
const { username } = os.userInfo();
|
||||
if (username === 'root') warn('Hydro should not be run as root.');
|
||||
// TODO check cwd read-write
|
||||
}
|
||||
|
||||
async function checkMail(log, warn) {
|
||||
const from = await system.get('smtp.from');
|
||||
if (!from) warn('SMTP account was not provided, email verification disabled.');
|
||||
}
|
||||
|
||||
async function checkProxy(log, warn) {
|
||||
const [github, google, proxy] = await system.getMany([
|
||||
'oauth.githubappid', 'oauth.googleappid', 'proxy',
|
||||
]);
|
||||
if (proxy) {
|
||||
superagent.get('https://www.google.com/').timeout(10000).proxy(proxy)
|
||||
.catch(() => warn('The proxy configured seem to be invalid.'));
|
||||
} else if (github || google) {
|
||||
warn('OAuth enabled. But for well-known reasons, a proxy is required.');
|
||||
}
|
||||
}
|
||||
|
||||
const checks = [
|
||||
checkDb,
|
||||
checkPerm,
|
||||
checkMail,
|
||||
checkProxy,
|
||||
];
|
||||
|
||||
export async function start(log, warn, error, cb) {
|
||||
const id = String.random(6);
|
||||
cb(id);
|
||||
for (const check of checks) {
|
||||
if (c[id]) {
|
||||
delete c[id];
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await check(log, warn, error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function cancel(id) {
|
||||
c[id] = true;
|
||||
}
|
||||
Reference in new issue
Block a user