wip fix
This commit is contained in:
parent
829f1367dc
commit
a63cc40afe
|
|
@ -1,3 +1,19 @@
|
||||||
|
declare module "pkgs/api/_prasi" {
|
||||||
|
export const _: {
|
||||||
|
url: string;
|
||||||
|
api(): Promise<void>;
|
||||||
|
};
|
||||||
|
export const getApiEntry: () => any;
|
||||||
|
}
|
||||||
|
declare module "pkgs/api/_web" {
|
||||||
|
export const _: {
|
||||||
|
url: string;
|
||||||
|
api(id: string, _: string): Promise<any>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
declare module "pkgs/utils/dir" {
|
||||||
|
export const dir: (path: string) => string;
|
||||||
|
}
|
||||||
declare module "app/db/db" {
|
declare module "app/db/db" {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -89,19 +105,6 @@ declare module "pkgs/utils/global" {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
declare module "pkgs/server/serve-web" {
|
|
||||||
export const serveWeb: (url: URL, req: Request) => Promise<false | string[] | Response>;
|
|
||||||
export const generateIndexHtml: (base_url: string, site_id: string) => string;
|
|
||||||
}
|
|
||||||
declare module "pkgs/api/_file" {
|
|
||||||
export const _: {
|
|
||||||
url: string;
|
|
||||||
api(): Promise<Response>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
declare module "pkgs/utils/dir" {
|
|
||||||
export const dir: (path: string) => string;
|
|
||||||
}
|
|
||||||
declare module "pkgs/server/load-web" {
|
declare module "pkgs/server/load-web" {
|
||||||
export const loadWeb: () => Promise<void>;
|
export const loadWeb: () => Promise<void>;
|
||||||
export const loadWebCache: (site_id: string, ts: number | string) => Promise<void>;
|
export const loadWebCache: (site_id: string, ts: number | string) => Promise<void>;
|
||||||
|
|
@ -155,12 +158,21 @@ declare module "pkgs/api/_deploy" {
|
||||||
};
|
};
|
||||||
export const downloadFile: (url: string, filePath: string, progress?: (rec: number, total: number) => void) => Promise<boolean>;
|
export const downloadFile: (url: string, filePath: string, progress?: (rec: number, total: number) => void) => Promise<boolean>;
|
||||||
}
|
}
|
||||||
declare module "pkgs/api/_prasi" {
|
declare module "pkgs/api/_upload" {
|
||||||
export const _: {
|
export const _: {
|
||||||
url: string;
|
url: string;
|
||||||
api(): Promise<void>;
|
api(body: any): Promise<string>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
declare module "pkgs/server/serve-web" {
|
||||||
|
export const serveWeb: (url: URL, req: Request) => Promise<false | string[] | Response>;
|
||||||
|
export const generateIndexHtml: (base_url: string, site_id: string) => string;
|
||||||
|
}
|
||||||
|
declare module "pkgs/api/_file" {
|
||||||
|
export const _: {
|
||||||
|
url: string;
|
||||||
|
api(): Promise<Response>;
|
||||||
};
|
};
|
||||||
export const getApiEntry: () => any;
|
|
||||||
}
|
}
|
||||||
declare module "pkgs/api/_notif" {
|
declare module "pkgs/api/_notif" {
|
||||||
export const _: {
|
export const _: {
|
||||||
|
|
@ -190,10 +202,10 @@ declare module "pkgs/api/_notif" {
|
||||||
}>;
|
}>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
declare module "pkgs/api/_web" {
|
declare module "pkgs/api/_api_frm" {
|
||||||
export const _: {
|
export const _: {
|
||||||
url: string;
|
url: string;
|
||||||
api(id: string, _: string): Promise<any>;
|
api(): Promise<void>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
declare module "pkgs/api/_proxy" {
|
declare module "pkgs/api/_proxy" {
|
||||||
|
|
@ -207,31 +219,19 @@ declare module "pkgs/api/_proxy" {
|
||||||
}): Promise<Response>;
|
}): Promise<Response>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
declare module "pkgs/api/_upload" {
|
|
||||||
export const _: {
|
|
||||||
url: string;
|
|
||||||
api(body: any): Promise<string>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
declare module "pkgs/api/_dbs" {
|
declare module "pkgs/api/_dbs" {
|
||||||
export const _: {
|
export const _: {
|
||||||
url: string;
|
url: string;
|
||||||
api(dbName: any, action?: string): Promise<void>;
|
api(dbName: any, action?: string): Promise<void>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
declare module "pkgs/api/_api_frm" {
|
|
||||||
export const _: {
|
|
||||||
url: string;
|
|
||||||
api(): Promise<void>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
declare module "app/srv/exports" {
|
declare module "app/srv/exports" {
|
||||||
export const _file: {
|
export const _web: {
|
||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
path: string;
|
path: string;
|
||||||
args: any[];
|
args: string[];
|
||||||
handler: Promise<typeof import("pkgs/api/_file")>;
|
handler: Promise<typeof import("pkgs/api/_web")>;
|
||||||
};
|
};
|
||||||
export const _deploy: {
|
export const _deploy: {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -240,6 +240,13 @@ declare module "app/srv/exports" {
|
||||||
args: string[];
|
args: string[];
|
||||||
handler: Promise<typeof import("pkgs/api/_deploy")>;
|
handler: Promise<typeof import("pkgs/api/_deploy")>;
|
||||||
};
|
};
|
||||||
|
export const _upload: {
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
path: string;
|
||||||
|
args: string[];
|
||||||
|
handler: Promise<typeof import("pkgs/api/_upload")>;
|
||||||
|
};
|
||||||
export const _prasi: {
|
export const _prasi: {
|
||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|
@ -247,6 +254,13 @@ declare module "app/srv/exports" {
|
||||||
args: any[];
|
args: any[];
|
||||||
handler: Promise<typeof import("pkgs/api/_prasi")>;
|
handler: Promise<typeof import("pkgs/api/_prasi")>;
|
||||||
};
|
};
|
||||||
|
export const _file: {
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
path: string;
|
||||||
|
args: any[];
|
||||||
|
handler: Promise<typeof import("pkgs/api/_file")>;
|
||||||
|
};
|
||||||
export const _notif: {
|
export const _notif: {
|
||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|
@ -254,12 +268,12 @@ declare module "app/srv/exports" {
|
||||||
args: string[];
|
args: string[];
|
||||||
handler: Promise<typeof import("pkgs/api/_notif")>;
|
handler: Promise<typeof import("pkgs/api/_notif")>;
|
||||||
};
|
};
|
||||||
export const _web: {
|
export const _api_frm: {
|
||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
path: string;
|
path: string;
|
||||||
args: string[];
|
args: any[];
|
||||||
handler: Promise<typeof import("pkgs/api/_web")>;
|
handler: Promise<typeof import("pkgs/api/_api_frm")>;
|
||||||
};
|
};
|
||||||
export const _proxy: {
|
export const _proxy: {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -268,13 +282,6 @@ declare module "app/srv/exports" {
|
||||||
args: string[];
|
args: string[];
|
||||||
handler: Promise<typeof import("pkgs/api/_proxy")>;
|
handler: Promise<typeof import("pkgs/api/_proxy")>;
|
||||||
};
|
};
|
||||||
export const _upload: {
|
|
||||||
name: string;
|
|
||||||
url: string;
|
|
||||||
path: string;
|
|
||||||
args: string[];
|
|
||||||
handler: Promise<typeof import("pkgs/api/_upload")>;
|
|
||||||
};
|
|
||||||
export const _dbs: {
|
export const _dbs: {
|
||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|
@ -282,11 +289,4 @@ declare module "app/srv/exports" {
|
||||||
args: string[];
|
args: string[];
|
||||||
handler: Promise<typeof import("pkgs/api/_dbs")>;
|
handler: Promise<typeof import("pkgs/api/_dbs")>;
|
||||||
};
|
};
|
||||||
export const _api_frm: {
|
|
||||||
name: string;
|
|
||||||
url: string;
|
|
||||||
path: string;
|
|
||||||
args: any[];
|
|
||||||
handler: Promise<typeof import("pkgs/api/_api_frm")>;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
export const _file = {
|
export const _web = {
|
||||||
name: "_file",
|
name: "_web",
|
||||||
url: "/_file/**",
|
url: "/_web/:id/**",
|
||||||
path: "app/srv/api/_file.ts",
|
path: "app/srv/api/_web.ts",
|
||||||
args: [],
|
args: ["id","_"],
|
||||||
handler: import("../../pkgs/api/_file")
|
handler: import("../../pkgs/api/_web")
|
||||||
}
|
}
|
||||||
export const _deploy = {
|
export const _deploy = {
|
||||||
name: "_deploy",
|
name: "_deploy",
|
||||||
|
|
@ -12,6 +12,13 @@ export const _deploy = {
|
||||||
args: ["action"],
|
args: ["action"],
|
||||||
handler: import("../../pkgs/api/_deploy")
|
handler: import("../../pkgs/api/_deploy")
|
||||||
}
|
}
|
||||||
|
export const _upload = {
|
||||||
|
name: "_upload",
|
||||||
|
url: "/_upload",
|
||||||
|
path: "app/srv/api/_upload.ts",
|
||||||
|
args: ["body"],
|
||||||
|
handler: import("../../pkgs/api/_upload")
|
||||||
|
}
|
||||||
export const _prasi = {
|
export const _prasi = {
|
||||||
name: "_prasi",
|
name: "_prasi",
|
||||||
url: "/_prasi/**",
|
url: "/_prasi/**",
|
||||||
|
|
@ -19,6 +26,13 @@ export const _prasi = {
|
||||||
args: [],
|
args: [],
|
||||||
handler: import("../../pkgs/api/_prasi")
|
handler: import("../../pkgs/api/_prasi")
|
||||||
}
|
}
|
||||||
|
export const _file = {
|
||||||
|
name: "_file",
|
||||||
|
url: "/_file/**",
|
||||||
|
path: "app/srv/api/_file.ts",
|
||||||
|
args: [],
|
||||||
|
handler: import("../../pkgs/api/_file")
|
||||||
|
}
|
||||||
export const _notif = {
|
export const _notif = {
|
||||||
name: "_notif",
|
name: "_notif",
|
||||||
url: "/_notif/:action/:token",
|
url: "/_notif/:action/:token",
|
||||||
|
|
@ -26,12 +40,12 @@ export const _notif = {
|
||||||
args: ["action","data"],
|
args: ["action","data"],
|
||||||
handler: import("../../pkgs/api/_notif")
|
handler: import("../../pkgs/api/_notif")
|
||||||
}
|
}
|
||||||
export const _web = {
|
export const _api_frm = {
|
||||||
name: "_web",
|
name: "_api_frm",
|
||||||
url: "/_web/:id/**",
|
url: "/_api_frm",
|
||||||
path: "app/srv/api/_web.ts",
|
path: "app/srv/api/_api_frm.ts",
|
||||||
args: ["id","_"],
|
args: [],
|
||||||
handler: import("../../pkgs/api/_web")
|
handler: import("../../pkgs/api/_api_frm")
|
||||||
}
|
}
|
||||||
export const _proxy = {
|
export const _proxy = {
|
||||||
name: "_proxy",
|
name: "_proxy",
|
||||||
|
|
@ -40,13 +54,6 @@ export const _proxy = {
|
||||||
args: ["arg"],
|
args: ["arg"],
|
||||||
handler: import("../../pkgs/api/_proxy")
|
handler: import("../../pkgs/api/_proxy")
|
||||||
}
|
}
|
||||||
export const _upload = {
|
|
||||||
name: "_upload",
|
|
||||||
url: "/_upload",
|
|
||||||
path: "app/srv/api/_upload.ts",
|
|
||||||
args: ["body"],
|
|
||||||
handler: import("../../pkgs/api/_upload")
|
|
||||||
}
|
|
||||||
export const _dbs = {
|
export const _dbs = {
|
||||||
name: "_dbs",
|
name: "_dbs",
|
||||||
url: "/_dbs/:dbName/:action",
|
url: "/_dbs/:dbName/:action",
|
||||||
|
|
@ -54,10 +61,3 @@ export const _dbs = {
|
||||||
args: ["dbName","action"],
|
args: ["dbName","action"],
|
||||||
handler: import("../../pkgs/api/_dbs")
|
handler: import("../../pkgs/api/_dbs")
|
||||||
}
|
}
|
||||||
export const _api_frm = {
|
|
||||||
name: "_api_frm",
|
|
||||||
url: "/_api_frm",
|
|
||||||
path: "app/srv/api/_api_frm.ts",
|
|
||||||
args: [],
|
|
||||||
handler: import("../../pkgs/api/_api_frm")
|
|
||||||
}
|
|
||||||
|
|
@ -190,6 +190,7 @@ export const downloadFile = async (
|
||||||
if (_url.hostname === "localhost") {
|
if (_url.hostname === "localhost") {
|
||||||
_url.hostname = "127.0.0.1";
|
_url.hostname = "127.0.0.1";
|
||||||
}
|
}
|
||||||
|
g.log.info(`Downloading ${url} to ${filePath}`);
|
||||||
const res = await fetch(_url);
|
const res = await fetch(_url);
|
||||||
if (res.body) {
|
if (res.body) {
|
||||||
const file = Bun.file(filePath);
|
const file = Bun.file(filePath);
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,20 @@ import { config } from "./utils/config";
|
||||||
import { g } from "./utils/global";
|
import { g } from "./utils/global";
|
||||||
import { createLogger } from "./utils/logger";
|
import { createLogger } from "./utils/logger";
|
||||||
import { loadWeb } from "./server/load-web";
|
import { loadWeb } from "./server/load-web";
|
||||||
import { ensureNotRunning } from "utils/ensure";
|
import { ensureNotRunning, randomBetween } from "utils/ensure";
|
||||||
import { preparePrisma } from "utils/prisma";
|
import { preparePrisma } from "utils/prisma";
|
||||||
import { startDevWatcher } from "utils/dev-watcher";
|
import { startDevWatcher } from "utils/dev-watcher";
|
||||||
|
|
||||||
g.mode = process.argv.includes("dev") ? "dev" : "prod";
|
g.mode = process.argv.includes("dev") ? "dev" : "prod";
|
||||||
g.datadir = g.mode === "prod" ? "../data" : ".data";
|
g.datadir = g.mode === "prod" ? "../data" : ".data";
|
||||||
|
|
||||||
|
if (!process.env.PORT) {
|
||||||
|
g.port = randomBetween(5000, 15000);
|
||||||
|
await Bun.write(".env", `PORT=${g.port}`);
|
||||||
|
} else {
|
||||||
|
g.port = parseInt(process.env.PORT);
|
||||||
|
}
|
||||||
|
|
||||||
await preparePrisma();
|
await preparePrisma();
|
||||||
await createLogger();
|
await createLogger();
|
||||||
await ensureNotRunning();
|
await ensureNotRunning();
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export const ensureNotRunning = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!(await checkPort())) {
|
if (!(await checkPort())) {
|
||||||
g.log.warn(`Port ${process.env.PORT} is used, waiting...`);
|
g.log.warn(`Port ${g.port} is used, waiting...`);
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
if (await checkPort()) resolve();
|
if (await checkPort()) resolve();
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
@ -35,3 +35,7 @@ export const ensureNotRunning = async () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function randomBetween(min: number, max: number) {
|
||||||
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,4 @@ export const preparePrisma = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
g.dburl = process.env.DATABASE_URL || "";
|
g.dburl = process.env.DATABASE_URL || "";
|
||||||
g.port = parseInt(process.env.PORT || "3000");
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue