fix
This commit is contained in:
parent
0801109562
commit
ca8ba09889
|
|
@ -22,18 +22,24 @@ export const _ = {
|
||||||
| { type: "domain-add"; domain: string }
|
| { type: "domain-add"; domain: string }
|
||||||
| { type: "domain-del"; domain: string }
|
| { type: "domain-del"; domain: string }
|
||||||
| { type: "deploy-del"; ts: string }
|
| { type: "deploy-del"; ts: string }
|
||||||
| { type: "deploy"; dlurl: string }
|
| { type: "deploy"; load_from?: string }
|
||||||
| { type: "deploy-status" }
|
| { type: "deploy-status" }
|
||||||
| { type: "redeploy"; ts: string }
|
| { type: "redeploy"; ts: string }
|
||||||
) & {
|
) & {
|
||||||
id_site: string;
|
id_site: string;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const { res } = apiContext(this);
|
const { res, req } = apiContext(this);
|
||||||
|
|
||||||
const path = dir(`app/web/`);
|
const path = dir(`app/web/`);
|
||||||
await dirAsync(path);
|
await dirAsync(path);
|
||||||
|
|
||||||
|
if (typeof req.query_parameters["export"] !== "undefined") {
|
||||||
|
return new Response(
|
||||||
|
Bun.file(dir(`app/web/deploy/${deploy.config.deploy.ts}.gz`))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case "check":
|
case "check":
|
||||||
const deploys = fs.readdirSync(dir(`/app/web/deploy`));
|
const deploys = fs.readdirSync(dir(`/app/web/deploy`));
|
||||||
|
|
@ -164,7 +170,7 @@ export const _ = {
|
||||||
|
|
||||||
await deploy.saveConfig();
|
await deploy.saveConfig();
|
||||||
deploy.config.deploy.ts = Date.now() + "";
|
deploy.config.deploy.ts = Date.now() + "";
|
||||||
await deploy.init();
|
await deploy.init(action.load_from);
|
||||||
const deploys = fs.readdirSync(dir(`/app/web/deploy`));
|
const deploys = fs.readdirSync(dir(`/app/web/deploy`));
|
||||||
|
|
||||||
if (g.mode === "prod") {
|
if (g.mode === "prod") {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import { gunzipAsync } from "./gzip";
|
||||||
|
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
export const deploy = {
|
export const deploy = {
|
||||||
async init() {
|
async init(load_from?: string) {
|
||||||
await dirAsync(dir(`app/web/deploy`));
|
await dirAsync(dir(`app/web/deploy`));
|
||||||
|
|
||||||
if (!(await this.has_gz())) {
|
if (!(await this.has_gz())) {
|
||||||
|
|
@ -32,19 +32,21 @@ export const deploy = {
|
||||||
g.deploy.content = decode(
|
g.deploy.content = decode(
|
||||||
await gunzipAsync(
|
await gunzipAsync(
|
||||||
new Uint8Array(
|
new Uint8Array(
|
||||||
await Bun.file(dir(`app/web/deploy/${ts}.gz`)).arrayBuffer(),
|
await Bun.file(dir(`app/web/deploy/${ts}.gz`)).arrayBuffer()
|
||||||
),
|
)
|
||||||
),
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
g.deploy.content = JSON.parse(
|
g.deploy.content = JSON.parse(
|
||||||
decoder.decode(
|
decoder.decode(
|
||||||
|
new Uint8Array(
|
||||||
await gunzipAsync(
|
await gunzipAsync(
|
||||||
new Uint8Array(
|
new Uint8Array(
|
||||||
await Bun.file(dir(`app/web/deploy/${ts}.gz`)).arrayBuffer(),
|
await Bun.file(dir(`app/web/deploy/${ts}.gz`)).arrayBuffer()
|
||||||
),
|
)
|
||||||
),
|
)
|
||||||
),
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,7 +100,7 @@ export const deploy = {
|
||||||
await removeAsync(dir(`app/web/server`));
|
await removeAsync(dir(`app/web/server`));
|
||||||
await dirAsync(dir(`app/web/server`));
|
await dirAsync(dir(`app/web/server`));
|
||||||
for (const [k, v] of Object.entries(
|
for (const [k, v] of Object.entries(
|
||||||
g.deploy.content.code.server,
|
g.deploy.content.code.server
|
||||||
)) {
|
)) {
|
||||||
await writeAsync(dir(`app/web/server/${k}`), v);
|
await writeAsync(dir(`app/web/server/${k}`), v);
|
||||||
}
|
}
|
||||||
|
|
@ -130,27 +132,37 @@ export const deploy = {
|
||||||
console.error(e.message, `[app/web/deploy/${ts}.gz]`);
|
console.error(e.message, `[app/web/deploy/${ts}.gz]`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async run() {
|
async run(load_from?: string) {
|
||||||
if (!this.config.site_id) {
|
if (!this.config.site_id) {
|
||||||
console.log("site_id is not found on app/web/config.json");
|
console.log("site_id is not found on app/web/config.json");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let buf: ArrayBuffer | null = null;
|
||||||
|
if (!load_from) {
|
||||||
let base_url = "https://prasi.avolut.com";
|
let base_url = "https://prasi.avolut.com";
|
||||||
if (g.mode === "dev") {
|
if (g.mode === "dev") {
|
||||||
base_url = "http://localhost:4550";
|
base_url = "http://localhost:4550";
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`Downloading site deploy: ${this.config.site_id} [ts: ${this.config.deploy.ts}] ${base_url}`,
|
`Downloading site deploy: ${this.config.site_id} [ts: ${this.config.deploy.ts}] ${base_url}`
|
||||||
);
|
);
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${base_url}/prod-zip/${this.config.site_id}?ts=${Date.now()}&msgpack=1`,
|
`${base_url}/prod-zip/${this.config.site_id}?ts=${Date.now()}&msgpack=1`
|
||||||
);
|
);
|
||||||
const ts = Date.now();
|
buf = await res.arrayBuffer();
|
||||||
|
} else {
|
||||||
|
const res = await fetch(load_from);
|
||||||
|
buf = await res.arrayBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!buf) {
|
||||||
|
console.log("Failed to download site deploy");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ts = Date.now();
|
||||||
const file = Bun.file(dir(`app/web/deploy/${ts}.gz`));
|
const file = Bun.file(dir(`app/web/deploy/${ts}.gz`));
|
||||||
await Bun.write(file, await res.arrayBuffer());
|
await Bun.write(file, buf);
|
||||||
await Bun.write(dir(`app/web/deploy/${ts}.mpack`), "ok");
|
await Bun.write(dir(`app/web/deploy/${ts}.mpack`), "ok");
|
||||||
this.config.deploy.ts = ts + "";
|
this.config.deploy.ts = ts + "";
|
||||||
|
|
||||||
|
|
@ -187,13 +199,13 @@ export const deploy = {
|
||||||
saveConfig() {
|
saveConfig() {
|
||||||
return Bun.write(
|
return Bun.write(
|
||||||
Bun.file(dir(`app/web/config.json`)),
|
Bun.file(dir(`app/web/config.json`)),
|
||||||
JSON.stringify(this.config, null, 2),
|
JSON.stringify(this.config, null, 2)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
has_gz() {
|
has_gz() {
|
||||||
if (this.config.deploy.ts) {
|
if (this.config.deploy.ts) {
|
||||||
return Bun.file(
|
return Bun.file(
|
||||||
dir(`app/web/deploy/${this.config.deploy.ts}.gz`),
|
dir(`app/web/deploy/${this.config.deploy.ts}.gz`)
|
||||||
).exists();
|
).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue