@a11ywatch/core
Version:
a11ywatch central API
43 lines • 1.73 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateUID = exports.getBaseParamsList = exports.getBaseParams = exports.paramParser = void 0;
const utils_1 = require("../../core/utils");
const paramParser = (req, value) => {
return (req.query && req.query[value]) || (req.body && req.body[value]);
};
exports.paramParser = paramParser;
const getBaseParams = (req) => {
var _a;
const usr = (0, utils_1.getUserFromToken)(req.headers.authorization);
const dman = (0, exports.paramParser)(req, "domain");
const url = (0, exports.paramParser)(req, "url") || (0, exports.paramParser)(req, "pageUrl");
const domain = dman ? decodeURIComponent(dman) : undefined;
const pageUrl = url ? decodeURIComponent(url) : undefined;
const userId = (_a = usr === null || usr === void 0 ? void 0 : usr.payload) === null || _a === void 0 ? void 0 : _a.keyid;
return {
userId,
domain,
pageUrl,
};
};
exports.getBaseParams = getBaseParams;
const getBaseParamsList = (req) => {
const { userId, domain, pageUrl } = (0, exports.getBaseParams)(req);
const query = req.query;
let offset;
if (query === null || query === void 0 ? void 0 : query.offset) {
const oset = Number(query === null || query === void 0 ? void 0 : query.offset);
offset = Number.isNaN(oset) ? 0 : oset;
}
return {
userId,
domain,
pageUrl,
offset,
limit: query.limit ? Math.max(query.limit, 100) : 5,
};
};
exports.getBaseParamsList = getBaseParamsList;
const validateUID = (id) => typeof id === "number" || typeof id === "string";
exports.validateUID = validateUID;
//# sourceMappingURL=extracter.js.map
;