spee.ch/server/controllers/assets/utils/flipClaimNameAndId.js

24 lines
700 B
JavaScript
Raw Permalink Normal View History

2018-04-27 19:24:40 +02:00
function isValidClaimId (claimId) {
return ((claimId.length === 40) && !/[^A-Za-z0-9]/g.test(claimId));
};
function isValidShortId (claimId) {
return claimId.length === 1; // it should really evaluate the short url itself
};
function isValidShortIdOrClaimId (input) {
return (isValidClaimId(input) || isValidShortId(input));
};
const flipClaimNameAndId = (identifier, name) => {
// this is a patch for backwards compatability with '/name/claimId' url format
2018-04-27 19:24:40 +02:00
if (isValidShortIdOrClaimId(name) && !isValidShortIdOrClaimId(identifier)) {
const tempName = name;
name = identifier;
identifier = tempName;
}
return [identifier, name];
};
module.exports = flipClaimNameAndId;