wip fix
This commit is contained in:
parent
269c2a58b9
commit
d7740d323c
|
|
@ -1,4 +1,6 @@
|
||||||
|
import { apiProxy } from "../../../base/load/api/api-proxy";
|
||||||
import { loadApiProxyDef } from "../../../base/load/api/api-proxy-def";
|
import { loadApiProxyDef } from "../../../base/load/api/api-proxy-def";
|
||||||
|
import { dbProxy } from "../../../base/load/db/db-proxy";
|
||||||
import importModule from "../../../render/editor/tools/dynamic-import";
|
import importModule from "../../../render/editor/tools/dynamic-import";
|
||||||
import { viScriptArg } from "../render/script/arg";
|
import { viScriptArg } from "../render/script/arg";
|
||||||
|
|
||||||
|
|
@ -53,9 +55,11 @@ export const viLoadLegacy = async (vi: {
|
||||||
const path = `/npm/site/${vi.site.id}/site.js`;
|
const path = `/npm/site/${vi.site.id}/site.js`;
|
||||||
await importModule(path);
|
await importModule(path);
|
||||||
if (!vi.site.db.get()) {
|
if (!vi.site.db.get()) {
|
||||||
|
vi.site.db.set(dbProxy(api_url));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vi.site.api.get()) {
|
if (!vi.site.api.get()) {
|
||||||
|
vi.site.api.set(apiProxy(api_url));
|
||||||
}
|
}
|
||||||
|
|
||||||
const w = window as any;
|
const w = window as any;
|
||||||
|
|
@ -73,7 +77,7 @@ export const viLoadLegacy = async (vi: {
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
const scope = {
|
const scope = {
|
||||||
...viScriptArg(),
|
...viScriptArg({ site: vi.site }),
|
||||||
types: {},
|
types: {},
|
||||||
exports: w.exports,
|
exports: w.exports,
|
||||||
load: importModule,
|
load: importModule,
|
||||||
|
|
|
||||||
|
|
@ -111,17 +111,22 @@ export const viEvalProps = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updatePropScope = (meta: IMeta, scope: any) => {
|
export const updatePropScope = (
|
||||||
|
vi: { site: { db: any; api: any } },
|
||||||
|
meta: IMeta,
|
||||||
|
scope: any
|
||||||
|
) => {
|
||||||
if (meta.item.script?.props) {
|
if (meta.item.script?.props) {
|
||||||
|
const scopes = { ...scope, api: vi.site.api, db: vi.site.db };
|
||||||
for (const [name, prop] of Object.entries(meta.item.script.props)) {
|
for (const [name, prop] of Object.entries(meta.item.script.props)) {
|
||||||
if (prop.fn) {
|
if (prop.fn) {
|
||||||
const fn = new Function(
|
const fn = new Function(
|
||||||
...Object.keys(scope),
|
...Object.keys(scopes),
|
||||||
`// [${meta.item.name}] ${name}: ${meta.item.id}
|
`// [${meta.item.name}] ${name}: ${meta.item.id}
|
||||||
return ${prop.value || ""}
|
return ${prop.value || ""}
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
prop.fn = fn(...Object.values(scope));
|
prop.fn = fn(...Object.values(scopes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ export const viEvalScript = (
|
||||||
meta.script = {
|
meta.script = {
|
||||||
passprop,
|
passprop,
|
||||||
result: null,
|
result: null,
|
||||||
Local: createViLocal(vi.meta, meta, vi.script?.init_local_effect),
|
Local: createViLocal(vi, meta),
|
||||||
PassProp: createViPassProp(vi, meta),
|
PassProp: createViPassProp(vi, meta),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -35,7 +35,6 @@ export const viEvalScript = (
|
||||||
}
|
}
|
||||||
|
|
||||||
const script = meta.script;
|
const script = meta.script;
|
||||||
|
|
||||||
const exports = (window as any).exports;
|
const exports = (window as any).exports;
|
||||||
const arg = {
|
const arg = {
|
||||||
useEffect,
|
useEffect,
|
||||||
|
|
@ -57,7 +56,7 @@ export const viEvalScript = (
|
||||||
|
|
||||||
if (typeof passprop === "object") {
|
if (typeof passprop === "object") {
|
||||||
for (const [k, v] of Object.entries(passprop)) {
|
for (const [k, v] of Object.entries(passprop)) {
|
||||||
if (typeof v === "object" && (v as any)._jsx) {
|
if (typeof v === "object" && v && (v as any)._jsx) {
|
||||||
const jprop = v as unknown as {
|
const jprop = v as unknown as {
|
||||||
_jsx: true;
|
_jsx: true;
|
||||||
fn: (arg: { passprop: any; meta: IMeta }) => ReactNode;
|
fn: (arg: { passprop: any; meta: IMeta }) => ReactNode;
|
||||||
|
|
@ -69,7 +68,6 @@ export const viEvalScript = (
|
||||||
|
|
||||||
const js = meta.item.adv?.jsBuilt || "";
|
const js = meta.item.adv?.jsBuilt || "";
|
||||||
const src = replaceWithObject(js, replacement) || "";
|
const src = replaceWithObject(js, replacement) || "";
|
||||||
|
|
||||||
const fn = new Function(
|
const fn = new Function(
|
||||||
...Object.keys(arg),
|
...Object.keys(arg),
|
||||||
`// ${meta.item.name}: ${meta.item.id}
|
`// ${meta.item.name}: ${meta.item.id}
|
||||||
|
|
@ -78,7 +76,7 @@ ${src}
|
||||||
);
|
);
|
||||||
fn(...Object.values(arg));
|
fn(...Object.values(arg));
|
||||||
|
|
||||||
updatePropScope(meta, passprop);
|
updatePropScope(vi, meta, passprop);
|
||||||
};
|
};
|
||||||
|
|
||||||
const JsxProp: FC<{
|
const JsxProp: FC<{
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,14 @@ import { updatePropScope } from "./eval-prop";
|
||||||
import { modifyChild } from "./passprop";
|
import { modifyChild } from "./passprop";
|
||||||
|
|
||||||
export const createViLocal = (
|
export const createViLocal = (
|
||||||
metas: Record<string, IMeta>,
|
vi: {
|
||||||
meta: IMeta,
|
site: { db: any; api: any };
|
||||||
init_local_effect: any
|
meta: Record<string, IMeta>;
|
||||||
|
script?: {
|
||||||
|
init_local_effect: any;
|
||||||
|
};
|
||||||
|
},
|
||||||
|
meta: IMeta
|
||||||
) => {
|
) => {
|
||||||
return <T extends Record<string, any>>(arg: {
|
return <T extends Record<string, any>>(arg: {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
|
|
@ -16,11 +21,13 @@ export const createViLocal = (
|
||||||
effect?: (local: T) => void | Promise<void>;
|
effect?: (local: T) => void | Promise<void>;
|
||||||
}) => {
|
}) => {
|
||||||
const { children } = arg;
|
const { children } = arg;
|
||||||
|
const init_local_effect = vi.script?.init_local_effect;
|
||||||
|
const metas = vi.meta;
|
||||||
const ref = useRef<any>(arg.value);
|
const ref = useRef<any>(arg.value);
|
||||||
const local = ref.current;
|
const local = ref.current;
|
||||||
local.render = meta.render;
|
local.render = meta.render;
|
||||||
|
|
||||||
updatePropScope(meta, meta.script?.passprop);
|
updatePropScope(vi, meta, meta.script?.passprop);
|
||||||
|
|
||||||
if (arg.hook) {
|
if (arg.hook) {
|
||||||
arg.hook(local);
|
arg.hook(local);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { g } from "utils/global";
|
import { g } from "utils/global";
|
||||||
|
import { gzipAsync } from "../../../app/srv/ws/sync/entity/zlib";
|
||||||
|
|
||||||
export const _ = {
|
export const _ = {
|
||||||
url: "/_proxy/*",
|
url: "/_proxy/*",
|
||||||
|
|
@ -20,6 +21,21 @@ export const _ = {
|
||||||
headers: arg.headers,
|
headers: arg.headers,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return res as any;
|
|
||||||
|
let body: any = null;
|
||||||
|
const headers: any = {};
|
||||||
|
res.headers.forEach((v, k) => {
|
||||||
|
headers[k] = v;
|
||||||
|
});
|
||||||
|
|
||||||
|
body = await res.arrayBuffer();
|
||||||
|
|
||||||
|
if (headers["content-encoding"] === "gzip") {
|
||||||
|
body = await gzipAsync(new Uint8Array(body));
|
||||||
|
} else {
|
||||||
|
delete headers["content-encoding"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(body, { headers });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue