fix prasi bun
This commit is contained in:
parent
803057b3a5
commit
40df47cd2d
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { apiContext } from "service-srv";
|
||||||
|
import { code } from "../ws/sync/code/code";
|
||||||
|
|
||||||
|
export const _ = {
|
||||||
|
url: "/local-prisma/:mode/:id_site",
|
||||||
|
async api(mode: "check" | "src", id_site: string) {
|
||||||
|
const file = Bun.file(code.path(id_site, "site", "src", "prisma/schema.prisma"));
|
||||||
|
if (mode === 'check') return JSON.stringify(await file.exists());
|
||||||
|
return await file.text();
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -53,7 +53,7 @@ export const fetchViaProxy = async (
|
||||||
let final_url = "";
|
let final_url = "";
|
||||||
|
|
||||||
if (
|
if (
|
||||||
to_url.hostname === 'localhost' ||
|
// to_url.hostname === 'localhost' ||
|
||||||
to_url.host === cur_url.host ||
|
to_url.host === cur_url.host ||
|
||||||
(!!g && typeof g.server_hook === "function")
|
(!!g && typeof g.server_hook === "function")
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { useGlobal, useLocal } from "web-utils";
|
||||||
import { AutoHeightTextarea } from "../../../../../utils/ui/auto-textarea";
|
import { AutoHeightTextarea } from "../../../../../utils/ui/auto-textarea";
|
||||||
import { EDGlobal } from "../../../logic/ed-global";
|
import { EDGlobal } from "../../../logic/ed-global";
|
||||||
import { apiRef, apiUrl, server } from "./api-utils";
|
import { apiRef, apiUrl, server } from "./api-utils";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export const EdApiDB = ({
|
export const EdApiDB = ({
|
||||||
db,
|
db,
|
||||||
|
|
@ -13,9 +14,18 @@ export const EdApiDB = ({
|
||||||
update: () => void;
|
update: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
const local = useLocal({ url: db.url });
|
const local = useLocal({ url: db.url, has_prisma: false });
|
||||||
const api = apiRef[apiUrl(p)];
|
const api = apiRef[apiUrl(p)];
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
_api.local_prisma("check", p.site.id).then((res: any) => {
|
||||||
|
if (typeof res === "boolean") {
|
||||||
|
local.has_prisma = res;
|
||||||
|
local.render();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex border-b py-2 px-2 border-slate-300 boxed flex-col items-stretch">
|
<div className="flex border-b py-2 px-2 border-slate-300 boxed flex-col items-stretch">
|
||||||
<AutoHeightTextarea
|
<AutoHeightTextarea
|
||||||
|
|
@ -33,6 +43,7 @@ export const EdApiDB = ({
|
||||||
<div className="flex flex-col items-stretch justify-center h-[20px]">
|
<div className="flex flex-col items-stretch justify-center h-[20px]">
|
||||||
{server.status === "saving" ||
|
{server.status === "saving" ||
|
||||||
server.status === "pulling" ||
|
server.status === "pulling" ||
|
||||||
|
server.status === "syncing" ||
|
||||||
server.status === "deploying" ||
|
server.status === "deploying" ||
|
||||||
server.status === "restarting" ? (
|
server.status === "restarting" ? (
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
|
|
@ -41,29 +52,79 @@ export const EdApiDB = ({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between select-none">
|
||||||
<div
|
<div className="flex space-x-1">
|
||||||
className="border rounded-sm px-2 text-[12px] hover:bg-blue-100 cursor-pointer"
|
{local.has_prisma ? (
|
||||||
onClick={async () => {
|
<>
|
||||||
server.status = "pulling";
|
<div
|
||||||
render();
|
className="border rounded-sm px-2 text-[12px] hover:bg-blue-100 cursor-pointer"
|
||||||
await api._deploy({
|
onClick={async () => {
|
||||||
type: "db-pull",
|
server.status = "syncing";
|
||||||
id_site: p.site.id,
|
render();
|
||||||
});
|
|
||||||
server.status = "ready";
|
|
||||||
render();
|
|
||||||
alert("DB PULL & GENERATE: OK\nRESTART: OK");
|
|
||||||
|
|
||||||
localStorage.removeItem(`schema-md-${p.site.id}`);
|
await api._deploy({
|
||||||
localStorage.setItem(
|
type: "db-sync",
|
||||||
"api-ts-" + p.site.config.api_url,
|
id_site: p.site.id,
|
||||||
Date.now().toString()
|
url: `${location.protocol}//${location.host}/local-prisma/src/${p.site.id}`,
|
||||||
);
|
});
|
||||||
location.reload();
|
|
||||||
}}
|
server.status = "ready";
|
||||||
>
|
render();
|
||||||
DB Pull
|
alert("Prisma Schema Synchronized");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Sync prisma.schema
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="border rounded-sm px-2 text-[12px] hover:bg-blue-100 cursor-pointer"
|
||||||
|
onClick={async () => {
|
||||||
|
server.status = "restarting";
|
||||||
|
render();
|
||||||
|
|
||||||
|
await api._deploy({
|
||||||
|
type: "db-gen",
|
||||||
|
id_site: p.site.id,
|
||||||
|
});
|
||||||
|
server.status = "ready";
|
||||||
|
render();
|
||||||
|
alert("DB GENERATE: OK\nRESTART: OK");
|
||||||
|
|
||||||
|
localStorage.removeItem(`schema-md-${p.site.id}`);
|
||||||
|
localStorage.setItem(
|
||||||
|
"api-ts-" + p.site.config.api_url,
|
||||||
|
Date.now().toString()
|
||||||
|
);
|
||||||
|
location.reload();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Generate
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
className="border rounded-sm px-2 text-[12px] hover:bg-blue-100 cursor-pointer"
|
||||||
|
onClick={async () => {
|
||||||
|
server.status = "pulling";
|
||||||
|
render();
|
||||||
|
await api._deploy({
|
||||||
|
type: "db-pull",
|
||||||
|
id_site: p.site.id,
|
||||||
|
});
|
||||||
|
server.status = "ready";
|
||||||
|
render();
|
||||||
|
alert("DB PULL & GENERATE: OK\nRESTART: OK");
|
||||||
|
|
||||||
|
localStorage.removeItem(`schema-md-${p.site.id}`);
|
||||||
|
localStorage.setItem(
|
||||||
|
"api-ts-" + p.site.config.api_url,
|
||||||
|
Date.now().toString()
|
||||||
|
);
|
||||||
|
location.reload();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
DB Pull
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="border rounded-sm px-2 text-[12px] hover:bg-blue-100 cursor-pointer"
|
className="border rounded-sm px-2 text-[12px] hover:bg-blue-100 cursor-pointer"
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ export const server = {
|
||||||
| "deploying"
|
| "deploying"
|
||||||
| "saving"
|
| "saving"
|
||||||
| "pulling"
|
| "pulling"
|
||||||
|
| "syncing"
|
||||||
| "restarting",
|
| "restarting",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ export const _ = {
|
||||||
}
|
}
|
||||||
return new Response(res_body, { headers: res_headers });
|
return new Response(res_body, { headers: res_headers });
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
|
||||||
new Response(
|
new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
status: "failed",
|
status: "failed",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue