添加部分注释,修复一些功能

This commit is contained in:
masnn committed 2020-04-13 17:41:44 +08:00
1 parent f40e4e2c74
commit d3e36fcb6c
32 files changed
+320 -174

No files matched your search

+39 -19
View File
@@ -1,8 +1,11 @@
require('./utils');
const
Mongo = require('mongodb'),
{ defaults } = require('lodash'),
builtin = require('./model/builtin'),
pwhash = require('./lib/pwhash'),
options = require('./options');
options = require('./options'),
{ udoc } = require('../interfaces');
async function run() {
let mongourl = 'mongodb://';
@@ -13,30 +16,47 @@ async function run() {
let coll_user = db.collection('user');
let coll_role = db.collection('role');
let coll_blacklist = db.collection('blacklist');
async function createRootUser() {
let coll_token = db.collection('token');
async function createUser() {
let salt = pwhash.salt();
await coll_user.insertOne({
_id: -1,
email: 'root@hydro',
emailLower: 'root@hydro',
uname: 'Root',
unameLower: 'root',
password: pwhash.hash('root', salt),
salt,
regat: new Date(),
regip: '127.0.0.1',
loginat: new Date(),
loginip: '127.0.0.1',
gravatar: 'root@hydro',
role: 'admin'
});
await coll_user.insertMany([
defaults({
_id: 0,
uname: 'Hydro',
unameLower: 'hydro',
mail: 'hydro@hydro',
mailLower: 'hydro@hydro',
role: 'guest'
}, udoc),
defaults({
_id: 1,
mail: 'guest@hydro',
mailLower: 'guest@hydro',
uname: 'Guest',
unameLower: 'guest',
role: 'guest'
}, udoc),
defaults({
_id: -1,
mail: 'root@hydro',
mailLower: 'root@hydro',
uname: 'Root',
unameLower: 'root',
hash: pwhash.hash('rootroot', salt),
salt,
gravatar: 'root@hydro',
role: 'admin'
}, udoc)
]);
}
await coll_user.createIndex('unameLower', { unique: true });
await coll_user.createIndex('emailLower', { sparse: true });
await coll_user.createIndex('mailLower', { sparse: true });
await coll_role.insertMany(builtin.BUILTIN_ROLES);
await coll_user.insertMany(builtin.BUILTIN_USERS);
await coll_blacklist.createIndex('expireAt', { expireAfterSeconds: 0 });
await createRootUser();
await coll_token.createIndex([{ uid: 1 }, { tokenType: 1 }, { updateAt: -1 }], { sparse: true });
await coll_token.createIndex('expireAt', { expireAfterSeconds: 0 });
await createUser();
console.log('Installed');
process.exit(0);
}