This commit is contained in:
Rizky 2024-01-18 14:56:42 +08:00
parent 55aebc4137
commit 7e39e7dbf0
3 changed files with 22 additions and 13 deletions

View File

@ -30,26 +30,31 @@ export const apiProxy = (api_url: string) => {
) {
return new Promise<any>(async (resolve, reject) => {
try {
let api_def = w.prasiApi[base_url];
let api_ref = w.prasiApi[base_url];
if (!api_def) {
if (
!api_ref &&
apiProxyLoaded &&
typeof apiProxyLoaded[base_url] === "object"
) {
await apiProxyLoaded[base_url];
api_ref = w.prasiApi[base_url];
}
if (api_def) {
if (!api_def.apiEntry) api_def.apiEntry = {};
if (api_def.apiEntry && !api_def.apiEntry[actionName]) {
if (api_ref) {
if (!api_ref.apiEntry) api_ref.apiEntry = {};
if (api_ref.apiEntry && !api_ref.apiEntry[actionName]) {
reject(
`API ${actionName.toString()} not found, existing API: \n - ${Object.keys(
api_def || {}
api_ref || {}
).join("\n - ")}`
);
return;
}
}
let actionUrl = api_def.apiEntry[actionName].url;
const actionParams = api_def.apiEntry[actionName].args;
let actionUrl = api_ref.apiEntry[actionName].url;
const actionParams = api_ref.apiEntry[actionName].args;
if (actionUrl && actionParams) {
if (rest.length > 0 && actionParams.length > 0) {
for (const [idx, p] of Object.entries(rest)) {

View File

@ -1,7 +1,9 @@
import { loadApiProxyDef } from "../../../../../base/load/api/api-proxy-def";
import { apiProxy } from "../../../../../base/load/api/api-proxy";
import { w } from "../../../../../utils/types/general";
import { PG } from "../../../logic/ed-global";
export const apiRef = {} as Record<string, any>;
export const dev = JSON.parse(localStorage.getItem("prasi-dev") || "{}") as {
enabled: boolean;
url: string;
@ -49,10 +51,9 @@ export const checkAPI = async (p: PG) => {
if (!url) return "offline";
try {
if (!w.prasiApi[url]) {
await loadApiProxyDef(url, true);
}
const capi = w.prasiApi[url] as any;
if (!apiRef[url]) apiRef[url] = apiProxy(url) as any;
const capi = apiRef[url];
if (!capi) {
console.error(`Cannot initialize API for ${url}.`, w.prasiApi[url]);
} else {

View File

@ -97,6 +97,9 @@ export const replacement = {
"stroke-width": "strokeWidth",
"fill-rule": "fillRule",
"clip-rule": "clipRule",
"stroke-linejoin": "strokeLinejoin",
"stroke-linecap": "strokeLinecap",
"clip-path": "clipPath",
};
export const replaceWithObject = (tpl: string, data: any) => {