mirror of
https://github.com/gethomepage/homepage.git
synced 2026-04-03 08:41:21 -07:00
Normalize widget version in URLs
This commit is contained in:
@@ -12,6 +12,22 @@ export function formatApiCall(url, args) {
|
||||
return url.replace(find, replace).replace(find, replace);
|
||||
}
|
||||
|
||||
export function parseVersionForUrl(version, defaultValue = null) {
|
||||
if (version === undefined || version === null || version === "") {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
if (typeof version === "number") {
|
||||
return Number.isInteger(version) && version >= 0 ? version : defaultValue;
|
||||
}
|
||||
|
||||
if (typeof version === "string" && /^\d+$/.test(version)) {
|
||||
return Number(version);
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
export function getURLSearchParams(widget, endpoint) {
|
||||
const params = new URLSearchParams({
|
||||
group: widget.service_group,
|
||||
|
||||
Reference in New Issue
Block a user