wip fix
This commit is contained in:
+1
-5
@@ -5,7 +5,7 @@ import { apiContext } from "service-srv";
|
||||
import { dir } from "utils/dir";
|
||||
import { g } from "utils/global";
|
||||
import { restartServer } from "utils/restart";
|
||||
import { loadWebCache } from "../server/load-web";
|
||||
|
||||
export const _ = {
|
||||
url: "/_deploy",
|
||||
async api(
|
||||
@@ -35,8 +35,6 @@ export const _ = {
|
||||
case "check":
|
||||
return {
|
||||
now: Date.now(),
|
||||
current: web.current,
|
||||
deploys: web.deploys,
|
||||
db: {
|
||||
url: g.dburl || "-",
|
||||
},
|
||||
@@ -121,7 +119,6 @@ datasource db {
|
||||
await fs.promises.writeFile(`${path}/current`, cur.toString());
|
||||
web.current = cur;
|
||||
web.deploys.push(cur);
|
||||
await loadWebCache(web.site_id, web.current);
|
||||
}
|
||||
web.deploying = null;
|
||||
|
||||
@@ -140,7 +137,6 @@ datasource db {
|
||||
if (web.deploys.find((e) => e === cur)) {
|
||||
web.current = cur;
|
||||
await fs.promises.writeFile(`${path}/current`, cur.toString());
|
||||
await loadWebCache(web.site_id, web.current);
|
||||
}
|
||||
} catch (e) {
|
||||
web.current = lastcur;
|
||||
|
||||
@@ -11,37 +11,6 @@ export const _ = {
|
||||
const rpath = decodeURIComponent(req.params._);
|
||||
|
||||
let res = new Response("NOT FOUND", { status: 404 });
|
||||
try {
|
||||
if (rpath.startsWith("site")) {
|
||||
if (rpath === "site-html") {
|
||||
res = new Response(generateIndexHtml("[[base_url]]", "[[site_id]]"));
|
||||
}
|
||||
if (rpath === "site-zip") {
|
||||
const path = dir(`app/static/site.zip`);
|
||||
res = new Response(Bun.file(path));
|
||||
}
|
||||
if (rpath === "site-md5") {
|
||||
const path = dir(`app/static/md5`);
|
||||
res = new Response(Bun.file(path));
|
||||
}
|
||||
} else if (rpath.startsWith("current-")) {
|
||||
if (rpath.startsWith("current-md5-")) {
|
||||
const site_id = rpath.substring("current-md5-".length);
|
||||
const path = dir(`app/web/${site_id}/current`);
|
||||
res = new Response(Bun.file(path));
|
||||
} else {
|
||||
const site_id = rpath.substring("current-".length);
|
||||
const path = dir(`app/web/${site_id}/current`);
|
||||
const id = await Bun.file(path).text();
|
||||
if (id) {
|
||||
const path = dir(`app/web/${site_id}/deploys/${id}`);
|
||||
res = new Response(Bun.file(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
res = new Response("NOT FOUND", { status: 404 });
|
||||
}
|
||||
|
||||
const path = dir(`${g.datadir}/upload/${rpath}`);
|
||||
const file = Bun.file(path);
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
import mime from "mime";
|
||||
import { apiContext } from "service-srv";
|
||||
import { g } from "utils/global";
|
||||
import { getApiEntry } from "./_prasi";
|
||||
|
||||
export const _ = {
|
||||
url: "/_web/:id/**",
|
||||
async api(id: string, _: string) {
|
||||
const { req, res } = apiContext(this);
|
||||
|
||||
const web = g.web[id];
|
||||
if (web) {
|
||||
const cache = web.cache;
|
||||
if (cache) {
|
||||
const parts = _.split("/");
|
||||
|
||||
switch (parts[0]) {
|
||||
case "site": {
|
||||
res.setHeader("content-type", "application/json");
|
||||
if (req.query_parameters["prod"]) {
|
||||
return {
|
||||
site: cache.site,
|
||||
pages: cache.pages.map((e) => {
|
||||
return {
|
||||
id: e.id,
|
||||
url: e.url,
|
||||
};
|
||||
}),
|
||||
api: getApiEntry(),
|
||||
};
|
||||
} else {
|
||||
return cache.site;
|
||||
}
|
||||
}
|
||||
case "pages": {
|
||||
res.setHeader("content-type", "application/json");
|
||||
return cache.pages.map((e) => {
|
||||
return {
|
||||
id: e.id,
|
||||
url: e.url,
|
||||
};
|
||||
});
|
||||
}
|
||||
case "page": {
|
||||
res.setHeader("content-type", "application/json");
|
||||
return cache.pages.find((e) => e.id === parts[1]);
|
||||
}
|
||||
case "npm-site": {
|
||||
let path = parts.slice(1).join("/");
|
||||
res.setHeader("content-type", mime.getType(path) || "text/plain");
|
||||
|
||||
if (path === "site.js") {
|
||||
path = "index.js";
|
||||
}
|
||||
return cache.npm.site[path];
|
||||
}
|
||||
case "npm-page": {
|
||||
const page_id = parts[1];
|
||||
if (cache.npm.pages[page_id]) {
|
||||
let path = parts.slice(2).join("/");
|
||||
res.setHeader("content-type", mime.getType(path) || "text/plain");
|
||||
|
||||
if (path === "page.js") {
|
||||
path = "index.js";
|
||||
}
|
||||
return cache.npm.pages[page_id][path];
|
||||
}
|
||||
res.setHeader("content-type", "text/javascript");
|
||||
}
|
||||
case "comp": {
|
||||
res.setHeader("content-type", "application/json");
|
||||
return cache.comps.find((e) => e.id === parts[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return req.params;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user