This commit is contained in:
Rizky 2024-02-04 16:24:09 +07:00
parent 2301d94a0a
commit c2ea5caba8
3 changed files with 44 additions and 38 deletions

View File

@ -28,6 +28,7 @@ export default page({
})(); })();
return <Loading note="init" />; return <Loading note="init" />;
} }
if (!edInitSync(p)) { if (!edInitSync(p)) {
return <Loading note="connecting-ws" />; return <Loading note="connecting-ws" />;
} }

View File

@ -33,51 +33,55 @@ export const edInitSync = (p: PG) => {
p.user.id = "ab1390f5-40d5-448e-a8c3-84b0fb600930"; p.user.id = "ab1390f5-40d5-448e-a8c3-84b0fb600930";
p.user.username = "anonymous"; p.user.username = "anonymous";
} }
if (!params.page_id) {
if (location.pathname.startsWith("/vi/")) {
if (page.list.length === 0) {
db.page
.findMany({
where: {
id_site: params.site_id,
is_deleted: false,
is_default_layout: false,
},
select: {
id: true,
url: true,
},
})
.then((list) => {
page.list = list;
edInitSync(p);
});
return; if (location.pathname.startsWith("/vi/")) {
} else { if (page.list.length === 0) {
if (!page.route) { db.page
page.route = createRouter(); .findMany({
for (const e of page.list) { where: {
page.route.insert(e.url, e); id_site: params.site_id,
} is_deleted: false,
} is_default_layout: false,
},
select: {
id: true,
url: true,
},
})
.then((list) => {
page.list = list;
edInitSync(p);
});
const arrpath = location.pathname.split("/"); return;
const pathname = "/" + arrpath.slice(3).join("/"); }
if (!page.route) {
page.route = createRouter();
for (const e of page.list) {
page.route.insert(e.url, e);
}
}
const res = page.route.lookup(pathname); const arrpath = location.pathname.split("/");
if (res) { const pathname = "/" + arrpath.slice(3).join("/");
params.page_id = res.id;
if (res.params) { if (!params.page_id) {
for (const [k, v] of Object.entries(res.params)) { const res = page.route.lookup(pathname);
if (!["site_id", "page_id"].includes(k)) { if (res) {
params[k] = v; params.page_id = res.id;
} if (res.params) {
for (const [k, v] of Object.entries(res.params)) {
if (!["site_id", "page_id"].includes(k)) {
params[k] = v;
} }
} }
} }
} }
} else if (location.pathname.startsWith("/ed")) { }
}
if (!params.page_id) {
if (location.pathname.startsWith("/ed")) {
if (!params.site_id) { if (!params.site_id) {
db.page db.page
.findFirst({ .findFirst({

View File

@ -46,6 +46,7 @@ export const ViPreview = (arg: { pathname: string }) => {
_href = `${w.basepath}${_href}`; _href = `${w.basepath}${_href}`;
} }
if ( if (
location.hostname.split(".").length === 4 ||
location.hostname === "prasi.app" || location.hostname === "prasi.app" ||
location.hostname === "prasi.avolut.com" || location.hostname === "prasi.avolut.com" ||
location.hostname.includes("ngrok") || location.hostname.includes("ngrok") ||