ffffng/shared/validation/constraints.js

141 lines
3.9 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
2014-05-12 20:08:19 +02:00
// ATTENTION: Those constraints are no longer the same file as for the server.
// Make sure changes are also reflected in /server/validation/constraints.ts.
2018-12-17 22:49:54 +01:00
(function () {
const constraints = {
id: {
type: "string",
regex: /^[1-9][0-9]*$/,
optional: false,
},
token: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^[0-9a-f]{16}$/i,
optional: false,
2016-06-07 00:21:26 +02:00
},
2018-12-17 22:49:54 +01:00
node: {
hostname: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^[-a-z0-9_]{1,32}$/i,
optional: false,
2018-12-17 22:49:54 +01:00
},
key: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^([a-f0-9]{64})$/i,
optional: true,
2018-12-17 22:49:54 +01:00
},
email: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
optional: false,
2018-12-17 22:49:54 +01:00
},
nickname: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^[-a-z0-9_ äöüß]{1,64}$/i,
optional: false,
2018-12-17 22:49:54 +01:00
},
mac: {
type: "string",
2022-07-22 17:10:39 +02:00
regex: /^([a-f0-9]{12}|([a-f0-9]{2}:){5}[a-f0-9]{2}|([a-f0-9]{2}-){5}[a-f0-9]{2})$/i,
optional: false,
2018-12-17 22:49:54 +01:00
},
coords: {
type: "string",
regex: /^(-?[0-9]{1,3}(\.[0-9]{1,20})? -?[0-9]{1,3}(\.[0-9]{1,20})?)$/,
optional: true,
2018-12-17 22:49:54 +01:00
},
monitoring: {
type: "boolean",
optional: false,
},
},
2018-12-17 22:49:54 +01:00
nodeFilters: {
hasKey: {
type: "boolean",
optional: true,
},
2018-12-17 22:49:54 +01:00
hasCoords: {
type: "boolean",
optional: true,
},
2018-12-17 22:49:54 +01:00
onlineState: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^(ONLINE|OFFLINE)$/,
optional: true,
},
2018-12-17 22:49:54 +01:00
monitoringState: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^(disabled|active|pending)$/,
optional: true,
2016-06-07 12:39:52 +02:00
},
2018-12-17 22:49:54 +01:00
site: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^[a-z0-9_-]{1,32}$/,
optional: true,
2018-12-17 22:49:54 +01:00
},
domain: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^[a-z0-9_-]{1,32}$/,
optional: true,
},
2018-12-17 22:49:54 +01:00
},
rest: {
list: {
_page: {
type: "number",
2018-12-17 22:49:54 +01:00
min: 1,
optional: true,
default: 1,
2018-12-17 22:49:54 +01:00
},
_perPage: {
type: "number",
2018-12-17 22:49:54 +01:00
min: 1,
max: 50,
optional: true,
default: 20,
2018-12-17 22:49:54 +01:00
},
_sortDir: {
type: "enum",
allowed: ["ASC", "DESC"],
2018-12-17 22:49:54 +01:00
optional: true,
default: "ASC",
2018-12-17 22:49:54 +01:00
},
_sortField: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^[a-zA-Z0-9_]{1,32}$/,
optional: true,
2018-12-17 22:49:54 +01:00
},
q: {
type: "string",
2018-12-17 22:49:54 +01:00
regex: /^[äöüß a-z0-9!#$%&@:.'*+/=?^_`{|}~-]{1,64}$/i,
optional: true,
},
},
},
};
2018-12-17 22:49:54 +01:00
let _angular = null;
2018-12-17 22:49:54 +01:00
try {
_angular = angular;
} catch (error) {
2018-12-17 22:49:54 +01:00
// ReferenceError, as angular is not defined.
}
let _module = null;
2018-12-17 22:49:54 +01:00
try {
_module = module;
} catch (error) {
2018-12-17 22:49:54 +01:00
// ReferenceError, as module is not defined.
}
if (_angular) {
angular.module("ffffng").constant("Constraints", constraints);
2018-12-17 22:49:54 +01:00
}
if (_module) {
module.exports = constraints;
2018-12-17 22:49:54 +01:00
}
})();