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 = "";
|
||||
|
||||
if (
|
||||
to_url.hostname === 'localhost' ||
|
||||
// to_url.hostname === 'localhost' ||
|
||||
to_url.host === cur_url.host ||
|
||||
(!!g && typeof g.server_hook === "function")
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { useGlobal, useLocal } from "web-utils";
|
|||
import { AutoHeightTextarea } from "../../../../../utils/ui/auto-textarea";
|
||||
import { EDGlobal } from "../../../logic/ed-global";
|
||||
import { apiRef, apiUrl, server } from "./api-utils";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export const EdApiDB = ({
|
||||
db,
|
||||
|
|
@ -13,9 +14,18 @@ export const EdApiDB = ({
|
|||
update: () => void;
|
||||
}) => {
|
||||
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)];
|
||||
|
||||
useEffect(() => {
|
||||
_api.local_prisma("check", p.site.id).then((res: any) => {
|
||||
if (typeof res === "boolean") {
|
||||
local.has_prisma = res;
|
||||
local.render();
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex border-b py-2 px-2 border-slate-300 boxed flex-col items-stretch">
|
||||
<AutoHeightTextarea
|
||||
|
|
@ -33,6 +43,7 @@ export const EdApiDB = ({
|
|||
<div className="flex flex-col items-stretch justify-center h-[20px]">
|
||||
{server.status === "saving" ||
|
||||
server.status === "pulling" ||
|
||||
server.status === "syncing" ||
|
||||
server.status === "deploying" ||
|
||||
server.status === "restarting" ? (
|
||||
<div className="flex justify-between">
|
||||
|
|
@ -41,29 +52,79 @@ export const EdApiDB = ({
|
|||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex justify-between">
|
||||
<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");
|
||||
<div className="flex justify-between select-none">
|
||||
<div className="flex space-x-1">
|
||||
{local.has_prisma ? (
|
||||
<>
|
||||
<div
|
||||
className="border rounded-sm px-2 text-[12px] hover:bg-blue-100 cursor-pointer"
|
||||
onClick={async () => {
|
||||
server.status = "syncing";
|
||||
render();
|
||||
|
||||
localStorage.removeItem(`schema-md-${p.site.id}`);
|
||||
localStorage.setItem(
|
||||
"api-ts-" + p.site.config.api_url,
|
||||
Date.now().toString()
|
||||
);
|
||||
location.reload();
|
||||
}}
|
||||
>
|
||||
DB Pull
|
||||
await api._deploy({
|
||||
type: "db-sync",
|
||||
id_site: p.site.id,
|
||||
url: `${location.protocol}//${location.host}/local-prisma/src/${p.site.id}`,
|
||||
});
|
||||
|
||||
server.status = "ready";
|
||||
render();
|
||||
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
|
||||
className="border rounded-sm px-2 text-[12px] hover:bg-blue-100 cursor-pointer"
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export const server = {
|
|||
| "deploying"
|
||||
| "saving"
|
||||
| "pulling"
|
||||
| "syncing"
|
||||
| "restarting",
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ export const _ = {
|
|||
}
|
||||
return new Response(res_body, { headers: res_headers });
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
status: "failed",
|
||||
|
|
|
|||
Loading…
Reference in New Issue