mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-08 06:38:46 +00:00
utils cleanup, initial static generation
This commit is contained in:
parent
ec8700f3e9
commit
e1a3a82f75
86 changed files with 279 additions and 261 deletions
55
src/utils/proxy/api-helpers.js
Normal file
55
src/utils/proxy/api-helpers.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
export function formatApiCall(url, args) {
|
||||
const find = /\{.*?\}/g;
|
||||
const replace = (match) => {
|
||||
const key = match.replace(/\{|\}/g, "");
|
||||
return args[key];
|
||||
};
|
||||
|
||||
return url.replace(find, replace);
|
||||
}
|
||||
|
||||
function getURLSearchParams(widget, endpoint) {
|
||||
const params = new URLSearchParams({
|
||||
type: widget.type,
|
||||
group: widget.service_group,
|
||||
service: widget.service_name,
|
||||
endpoint,
|
||||
});
|
||||
return params;
|
||||
}
|
||||
|
||||
export function formatProxyUrlWithSegments(widget, endpoint, segments) {
|
||||
const params = getURLSearchParams(widget, endpoint);
|
||||
if (segments) {
|
||||
params.append("segments", JSON.stringify(segments));
|
||||
}
|
||||
return `/api/services/proxy?${params.toString()}`;
|
||||
}
|
||||
|
||||
export function formatProxyUrl(widget, endpoint, queryParams) {
|
||||
const params = getURLSearchParams(widget, endpoint);
|
||||
if (queryParams) {
|
||||
params.append("query", JSON.stringify(queryParams));
|
||||
}
|
||||
return `/api/services/proxy?${params.toString()}`;
|
||||
}
|
||||
|
||||
export function asJson(data) {
|
||||
if (data?.length > 0) {
|
||||
const json = JSON.parse(data.toString());
|
||||
return json;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export function jsonArrayTransform(data, transform) {
|
||||
const json = asJson(data);
|
||||
if (json instanceof Array) {
|
||||
return transform(json);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
export function jsonArrayFilter(data, filter) {
|
||||
return jsonArrayTransform(data, (items) => items.filter(filter));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue