Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var streamArgs = function(req, defaultCount, maxCount) {
var args = {};
try {
if (_(maxCount).isUndefined()) {
maxCount = 10 * defaultCount;
}
if (_(req.query).has("count")) {
if (!validator.isInt(req.query.count, {min: 0, max: maxCount})) {
throw new Error("Count must be between 0 and " + maxCount);
}else {
args.count = validator.toInt(req.query.count);
}
} else {
args.count = defaultCount;
}
// XXX: Check "before" and "since" for injection...?
// XXX: Check "before" and "since" for URI...?
if (_(req.query).has("before")) {
if (validator.isEmpty(req.query.before)) {
throw new Error(req.query.before + " is null");
} else {
args.before = validator.trim(req.query.before);
}
}
exports.get = async (apiContext) => { // TODO: フィルター指定
await apiContext.proceed({
query: {
limit: { cafy: $().string().pipe(i => validator.isInt(i, { min: 0, max: 100 })), default: '30' },
next: { cafy: $().string().pipe(i => MongoAdapter.validateId(i)), default: null },
includeFileData: { cafy: $().string().pipe(i => validator.isBoolean(i)), default: 'false' }
},
scopes: ['storage.read']
});
if (apiContext.responsed) return;
// convert query value
const limit = validator.toInt(apiContext.query.limit);
const next = apiContext.query.next != null ? MongoAdapter.buildId(apiContext.query.next) : null;
const includeFileData = validator.toBoolean(apiContext.query.includeFileData);
// user
const user = await apiContext.repository.findById('users', apiContext.params.id);
if (user == null) {
apiContext.response(404, 'user as premise not found');
return;
}
const isOwnerAccess = user._id.equals(apiContext.user._id);
if (!isOwnerAccess) {
apiContext.response(403, 'this operation is not permitted');
return;
}
result = validator.toBoolean(any, true);
}
{
let result: Date;
result = validator.toDate(any);
}
{
let result: number;
result = validator.toFloat(any);
result = validator.toInt(any);
result = validator.toInt(any, 10);
}
{
let result: string;
result = validator.trim('sample');
result = validator.trim('sample', ' ');
result = validator.whitelist('sample', 'abc');
}
{
let str: string;
str = validator.toString([123, 456, '123', '456', true, false]);
}
static parse(s) {
if (!s) return null;
var p= null;
var sAry= s.split(SPLIT_TOKEN,6);
var i = 0;
if (sAry.length===6) {
p= new PackageProgress();
p.totalFiles= validator.toInt(sAry[i++],0);
p.processedFiles= validator.toInt(sAry[i++],0);
p.totalBytes= validator.toInt(sAry[i++],0);
p.processedBytes= validator.toInt(sAry[i++],0);
p.finalCompressedBytes= validator.toInt(sAry[i++],0);
if (p.totalFiles && p.processedFiles && p.totalBytes && p.processedBytes && p.finalCompressedBytes) {
p.url= sAry[i++];
}
else {
p=null;
}
}
return p;
}
}
getIntParam(key, def=0) {
const retval= validator.toInt(this.getParam(key)+'');
return !isNaN(retval) ? retval : def;
}
if (validators) {
if (validators.isInt && validators.isInt.message) {
message = validators.isInt.message;
}
if (validators.isLong && validators.isLong.message) {
message = validators.isLong.message;
}
}
fieldErrors[parent + name] = {
message,
value,
};
return;
}
const numberValue = validator.toInt(String(value), 10);
if (!validators) { return numberValue; }
if (validators.minimum && validators.minimum.value) {
if (validators.minimum.value > numberValue) {
fieldErrors[parent + name] = {
message: validators.minimum.message || `min ${validators.minimum.value}`,
value,
};
return;
}
}
if (validators.maximum && validators.maximum.value) {
if (validators.maximum.value < numberValue) {
fieldErrors[parent + name] = {
message: validators.maximum.message || `max ${validators.maximum.value}`,
value,
};
getIntParam(key, def=0) {
var retval= validator.toInt(this.getParam(key));
return !isNaN(retval) ? retval : def;
}
this.addType('INTEGER', function(value){
if(value === null) return null;
return validator.toInt(value);
}, {migration:'integer'});