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) => { return new Promise<any>(async (resolve, reject) => {
try { 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]; await apiProxyLoaded[base_url];
api_ref = w.prasiApi[base_url];
} }
if (api_def) { if (api_ref) {
if (!api_def.apiEntry) api_def.apiEntry = {}; if (!api_ref.apiEntry) api_ref.apiEntry = {};
if (api_def.apiEntry && !api_def.apiEntry[actionName]) { if (api_ref.apiEntry && !api_ref.apiEntry[actionName]) {
reject( reject(
`API ${actionName.toString()} not found, existing API: \n - ${Object.keys( `API ${actionName.toString()} not found, existing API: \n - ${Object.keys(
api_def || {} api_ref || {}
).join("\n - ")}` ).join("\n - ")}`
); );
return; return;
} }
} }
let actionUrl = api_def.apiEntry[actionName].url; let actionUrl = api_ref.apiEntry[actionName].url;
const actionParams = api_def.apiEntry[actionName].args; const actionParams = api_ref.apiEntry[actionName].args;
if (actionUrl && actionParams) { if (actionUrl && actionParams) {
if (rest.length > 0 && actionParams.length > 0) { if (rest.length > 0 && actionParams.length > 0) {
for (const [idx, p] of Object.entries(rest)) { 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 { w } from "../../../../../utils/types/general";
import { PG } from "../../../logic/ed-global"; import { PG } from "../../../logic/ed-global";
export const apiRef = {} as Record<string, any>;
export const dev = JSON.parse(localStorage.getItem("prasi-dev") || "{}") as { export const dev = JSON.parse(localStorage.getItem("prasi-dev") || "{}") as {
enabled: boolean; enabled: boolean;
url: string; url: string;
@ -49,10 +51,9 @@ export const checkAPI = async (p: PG) => {
if (!url) return "offline"; if (!url) return "offline";
try { try {
if (!w.prasiApi[url]) { if (!apiRef[url]) apiRef[url] = apiProxy(url) as any;
await loadApiProxyDef(url, true);
} const capi = apiRef[url];
const capi = w.prasiApi[url] as any;
if (!capi) { if (!capi) {
console.error(`Cannot initialize API for ${url}.`, w.prasiApi[url]); console.error(`Cannot initialize API for ${url}.`, w.prasiApi[url]);
} else { } else {

View File

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