upload files into repos
This commit is contained in:
parent
3516e3554f
commit
5c3dda0daa
@ -34,6 +34,7 @@ server.resposne = (response) => ({
|
||||
code: 200
|
||||
});
|
||||
server.paramsError = (required, additional) => ({ required, additional });
|
||||
server.typeError = 'param {param} must be only {long_type} ({short_type})';
|
||||
|
||||
// Создаём класс группы методов
|
||||
class ExampleMethodGroup extends backend.Group {
|
||||
|
@ -14,7 +14,7 @@ class Main {
|
||||
}
|
||||
|
||||
call (method, params) {
|
||||
return this.methods[method.path].execute(params);
|
||||
return this.methods[method.path].pre_execute(params);
|
||||
}
|
||||
|
||||
router (returnMiddlewareFunction = true, middlewareFunction = (req, res, next) => next()) {
|
||||
|
@ -4,7 +4,7 @@ class Method {
|
||||
this.paramsCompiles = params;
|
||||
}
|
||||
|
||||
compileParams (
|
||||
executeIntoExpressRouter (
|
||||
headers,
|
||||
json,
|
||||
params,
|
||||
@ -13,13 +13,15 @@ class Method {
|
||||
files,
|
||||
cookies
|
||||
) {
|
||||
let paramsEndless = new Object();
|
||||
let paramScheme;
|
||||
let required = { missed : [], unsyntax : [] };
|
||||
let required = { missed : [], unsyntax : [] };
|
||||
let additional = { missed : [], unsyntax : [] };
|
||||
let checkKeys = new Array();
|
||||
for (let param in this.paramsCompiles) {
|
||||
paramScheme = {
|
||||
required : false,
|
||||
type : require('./types').unknown,
|
||||
allow_methods : ['get', 'post', 'put', 'delete'],
|
||||
allow_params : ['headers', 'json', 'params', 'query', 'body', 'files', 'cookies']
|
||||
};
|
||||
@ -27,16 +29,80 @@ class Method {
|
||||
for (let key in this.paramsCompiles[param]) { paramScheme[key] = this.paramsCompiles[param][key]; }
|
||||
// check missible
|
||||
if (headers[param] !== undefined & paramScheme.allow_params.indexOf('headers') != -1) { checkKeys.push('headers'); }
|
||||
if (json[param] !== undefined) { checkKeys.push('json'); }
|
||||
if (query[param] !== undefined) { checkKeys.push('query'); }
|
||||
if (body[param] !== undefined) { checkKeys.push('body'); }
|
||||
if (files[param] !== undefined) { checkKeys.push('files'); }
|
||||
if (cookies[param] !== undefined) { checkKeys.push('cookies'); }
|
||||
if (params[param] !== undefined) { checkKeys.push('params'); }
|
||||
if (json[param] !== undefined & paramScheme.allow_params.indexOf('json') != -1) { checkKeys.push('json'); }
|
||||
if (query[param] !== undefined & paramScheme.allow_params.indexOf('query') != -1) { checkKeys.push('query'); }
|
||||
if (body[param] !== undefined & paramScheme.allow_params.indexOf('body') != -1) { checkKeys.push('body'); }
|
||||
if (files[param] !== undefined & paramScheme.allow_params.indexOf('files') != -1) { checkKeys.push('files'); }
|
||||
if (cookies[param] !== undefined & paramScheme.allow_params.indexOf('cookies') != -1) { checkKeys.push('cookies'); }
|
||||
if (params[param] !== undefined & paramScheme.allow_params.indexOf('params') != -1) { checkKeys.push('params'); }
|
||||
|
||||
if (checkKeys.length == 0) {
|
||||
if (paramScheme.required) { required.missed.push(param); }
|
||||
else { additional.missed.push(param); }
|
||||
}
|
||||
else {
|
||||
checkKeys = checkKeys.sort((a, b) => Number(b == 'query' || b == 'cookies') - Number(a == 'query' || a == 'cookies'));
|
||||
let isSyntax;
|
||||
let convertedValue;
|
||||
for (let key in checkKeys) {
|
||||
switch (key) {
|
||||
case 'query' :
|
||||
[isSyntax, convertedValue] = paramScheme.type(query[param], true);
|
||||
break;
|
||||
case 'cookies' :
|
||||
[isSyntax, convertedValue] = paramScheme.type(query[param], true);
|
||||
break;
|
||||
case 'json' :
|
||||
[isSyntax, convertedValue] = paramScheme.type(query[param], false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isSyntax) {
|
||||
paramsEndless[param] = convertedValue;
|
||||
}
|
||||
else {
|
||||
if (paramScheme.required) { required.unsyntax.push({param : param, description : this.typeError.split('{param}').join(param).split('{long_type}').join(paramScheme.type.long_name).split('{short_type}').join(paramScheme.type.short_name)}); }
|
||||
else { additional.unsyntax.push({param : param, description : this.typeError.split('{param}').join(param).split('{long_type}').join(paramScheme.type.long_name).split('{short_type}').join(paramScheme.type.short_name)}); }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (required.missed.length > 0 || required.unsyntax.length > 0 || additional.unsyntax.length > 0) {
|
||||
throw this.paramsError(required, additional);
|
||||
}
|
||||
else {
|
||||
return this.pre_execute(paramsEndless, false);
|
||||
}
|
||||
}
|
||||
|
||||
execute () {}
|
||||
pre_execute (params, needsChecking = true) {
|
||||
if (needsChecking) {
|
||||
let required = { missed : [], unsyntax : [] };
|
||||
let additional = { missed : [], unsyntax : [] };
|
||||
let isSyntax;
|
||||
let _;
|
||||
let paramScheme;
|
||||
|
||||
for (let param in this.paramsCompiles) {
|
||||
paramScheme = {
|
||||
required : false,
|
||||
type : require('./types').unknown,
|
||||
allow_methods : ['get', 'post', 'put', 'delete'],
|
||||
allow_params : ['headers', 'json', 'params', 'query', 'body', 'files', 'cookies']
|
||||
};
|
||||
for (let key in this.paramsCompiles[param]) { paramScheme[key] = this.paramsCompiles[param][key]; }
|
||||
if (params[param] === undefined) {
|
||||
if (paramScheme.required) {
|
||||
required.missed.push(param);
|
||||
}
|
||||
else {
|
||||
additional.missed.push(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
execute (params) {}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,13 +1,21 @@
|
||||
module.exports = {
|
||||
unknown : {
|
||||
long_name : 'unknown',
|
||||
short_name : 'unk',
|
||||
syntax : (value, needs_convert = true) => throw new Error('Undefined datatype')
|
||||
},
|
||||
string : {
|
||||
long_name : 'string',
|
||||
long_name : 'string',
|
||||
short_name : 'str',
|
||||
syntax : (value, needs_convert = true) => {
|
||||
syntax : (value, needs_convert = false) => {
|
||||
if (typeof(value) == 'string') {
|
||||
return true, value;
|
||||
}
|
||||
else if (needs_convert) {
|
||||
return true, needs_convert.toString()
|
||||
}
|
||||
else {
|
||||
return false, needs_convert ? value.toString() : undefined;
|
||||
return false, undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user