mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
1.0.0-preview
This commit is contained in:
1 parent
90b06d6aa7
commit
8cd84f29e8
18 files changed
+152
-401
No files matched your search
+3
-3
@@ -3,15 +3,15 @@ const bus = require('./bus');
|
||||
const options = require('../options');
|
||||
|
||||
let mongourl = 'mongodb://';
|
||||
if (options.db.username) mongourl += `${options.db.username}:${options.db.password}@`;
|
||||
mongourl += `${options.db.host}:${options.db.port}/${options.db.name}`;
|
||||
if (options.username) mongourl += `${options.username}:${options.password}@`;
|
||||
mongourl += `${options.host}:${options.port}/${options.name}`;
|
||||
/**
|
||||
* @type {import('mongodb').Db}
|
||||
*/
|
||||
let db = null;
|
||||
Mongo.MongoClient.connect(mongourl, { useNewUrlParser: true, useUnifiedTopology: true })
|
||||
.then((Database) => {
|
||||
db = Database.db(options.db.name);
|
||||
db = Database.db(options.name);
|
||||
db.Db = Database;
|
||||
bus.publish('system_database_connected', null);
|
||||
});
|
||||
|
||||
+22
-19
@@ -249,27 +249,30 @@ function Route(route, RouteHandler) {
|
||||
const args = { ...ctx.params, ...ctx.query, ...ctx.request.body };
|
||||
|
||||
if (h.___prepare) await h.___prepare(args);
|
||||
|
||||
for (const l of check) {
|
||||
if (args[l]) {
|
||||
args[l] = new ObjectID(args[l]);
|
||||
if (!args[l]) throw new ValidationError(l);
|
||||
try {
|
||||
for (const l of check) {
|
||||
if (args[l]) {
|
||||
args[l] = new ObjectID(args[l]);
|
||||
if (!args[l]) throw new ValidationError(l);
|
||||
}
|
||||
}
|
||||
if (args.content) validator.checkContent(args.content);
|
||||
if (args.title) validator.checkContent(args.title);
|
||||
if (args.uid) args.uid = parseInt(validator.checkUid(args.uid));
|
||||
if (args.password) validator.checkPassword(args.password);
|
||||
if (args.mail) validator.checkEmail(args.mail);
|
||||
if (args.uname) validator.checkUname(args.uname);
|
||||
if (args.page) args.page = parseInt(args.page);
|
||||
if (args.duration) args.duration = parseFloat(args.duration);
|
||||
if (args.pids) args.pids = args.pids.split(',').map((i) => i.trim());
|
||||
if (args.role) validator.checkRole(args.role);
|
||||
if (args.roles) {
|
||||
for (const i of args.roles) validator.checkRole(i);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof ValidationError) throw e;
|
||||
throw new ValidationError('Argument check failed');
|
||||
}
|
||||
if (args.content) validator.checkContent(args.content);
|
||||
if (args.title) validator.checkContent(args.title);
|
||||
if (args.uid) args.uid = parseInt(validator.checkUid(args.uid));
|
||||
if (args.password) validator.checkPassword(args.password);
|
||||
if (args.mail) validator.checkEmail(args.mail);
|
||||
if (args.uname) validator.checkUname(args.uname);
|
||||
if (args.page) args.page = parseInt(args.page);
|
||||
if (args.duration) args.duration = parseFloat(args.duration);
|
||||
if (args.pids) args.pids = args.pids.split(',').map((i) => i.trim());
|
||||
if (args.role) validator.checkRole(args.role);
|
||||
if (args.roles) {
|
||||
for (const i of args.roles) validator.checkRole(i);
|
||||
}
|
||||
|
||||
if (h.__prepare) await h.__prepare(args);
|
||||
if (h._prepare) await h._prepare(args);
|
||||
if (h.prepare) await h.prepare(args);
|
||||
|
||||
Reference in new issue
Block a user