fix
This commit is contained in:
parent
06a8d6e482
commit
9397ebc5ca
File diff suppressed because one or more lines are too long
|
|
@ -75,6 +75,37 @@ export const initExtNotif = async (vi: VG, prasi_ext: PrasiExt) => {
|
|||
switch (data.type) {
|
||||
case "notification-token":
|
||||
prasi_ext.notif = { token: data.token };
|
||||
w.notif = {
|
||||
async send(data: NOTIF_ARG) {
|
||||
if (vi && vi.site.api) {
|
||||
return await vi.site.api._notif("send", {
|
||||
type: "send",
|
||||
id:
|
||||
typeof data.user_id === "string"
|
||||
? data.user_id
|
||||
: data.user_id.toString(),
|
||||
body: data.body,
|
||||
title: data.title,
|
||||
data: data.data,
|
||||
});
|
||||
}
|
||||
},
|
||||
async register(user_id: any) {
|
||||
if (vi && vi.site.api && prasi_ext.notif?.token) {
|
||||
return await vi.site.api._notif("register", {
|
||||
type: "register",
|
||||
id:
|
||||
typeof user_id === "string"
|
||||
? user_id
|
||||
: user_id.toString(),
|
||||
token: prasi_ext.notif.token,
|
||||
});
|
||||
}
|
||||
},
|
||||
onReceive(notif) {},
|
||||
onTap(notif) {},
|
||||
};
|
||||
|
||||
break;
|
||||
case "notification-tap":
|
||||
if (!w.notif?.onTap) {
|
||||
|
|
@ -111,38 +142,5 @@ export const initExtNotif = async (vi: VG, prasi_ext: PrasiExt) => {
|
|||
});
|
||||
|
||||
window.parent.postMessage({ mobile: true, type: "ready" }, "*");
|
||||
w.notif = {
|
||||
async send() {},
|
||||
register() {},
|
||||
onReceive(notif) {},
|
||||
onTap(notif) {},
|
||||
};
|
||||
w.notif.register = async (user_id: any) => {
|
||||
await waitUntil(() => prasi_ext.notif?.token);
|
||||
if (vi && vi.site.api && prasi_ext.notif?.token) {
|
||||
return await vi.site.api._notif("register", {
|
||||
type: "register",
|
||||
id: typeof user_id === "string" ? user_id : user_id.toString(),
|
||||
token: prasi_ext.notif.token,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (w.notif) {
|
||||
w.notif.send = async (data: NOTIF_ARG) => {
|
||||
if (vi && vi.site.api) {
|
||||
return await vi.site.api._notif("send", {
|
||||
type: "send",
|
||||
id:
|
||||
typeof data.user_id === "string"
|
||||
? data.user_id
|
||||
: data.user_id.toString(),
|
||||
body: data.body,
|
||||
title: data.title,
|
||||
data: data.data,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -30,104 +30,110 @@ await build({
|
|||
},
|
||||
});
|
||||
|
||||
const glob = new Glob("**");
|
||||
const public_files = [] as string[];
|
||||
for await (const file of glob.scan(dir.path("app/web/public"))) {
|
||||
public_files.push(file);
|
||||
}
|
||||
await Bun.write(
|
||||
dir.path("app/web/public_files.ts"),
|
||||
`export const files = ${JSON.stringify(public_files, null, 2)}`
|
||||
);
|
||||
|
||||
await removeAsync(dir.path("app/web/.parcel-cache"));
|
||||
await removeAsync(dir.path("app/static"));
|
||||
|
||||
await writeAsync(
|
||||
dir.path("app/web/timestamp.ts"),
|
||||
`export const version = "${createId().substring(0, 7)}";`
|
||||
);
|
||||
|
||||
const args = [
|
||||
"node",
|
||||
dir.path("node_modules/.bin/parcel"),
|
||||
"build",
|
||||
"./src/index.tsx",
|
||||
// "--no-optimize",
|
||||
"--no-scope-hoist",
|
||||
"--dist-dir",
|
||||
dir.path(`app/static`),
|
||||
];
|
||||
|
||||
const parcel = spawn({
|
||||
cmd: args,
|
||||
cwd: dir.path("app/web"),
|
||||
stdio: ["ignore", "inherit", "inherit"],
|
||||
});
|
||||
await parcel.exited;
|
||||
|
||||
const public_br = dir.path("app/web/public-br");
|
||||
if (!(await existsAsync(public_br))) {
|
||||
const api = new fdir().withRelativePaths().crawl(dir.path("app/web/public"));
|
||||
const files = api.sync();
|
||||
if (files) {
|
||||
await Promise.all(
|
||||
files.map(async (file) => {
|
||||
const br = brotli.compress(
|
||||
new Uint8Array(
|
||||
await Bun.file(dir.path(`app/web/public/${file}`)).arrayBuffer()
|
||||
),
|
||||
{ quality: 11 }
|
||||
);
|
||||
if (br) {
|
||||
console.log(`Compressing [public] ${file}`);
|
||||
await writeAsync(
|
||||
dir.path(`app/web/public-br/${file}`),
|
||||
Buffer.from(br)
|
||||
);
|
||||
}
|
||||
})
|
||||
);
|
||||
const build_all =
|
||||
process.argv[process.argv.length - 1] === "main" ? false : true;
|
||||
if (build_all) {
|
||||
const glob = new Glob("**");
|
||||
const public_files = [] as string[];
|
||||
for await (const file of glob.scan(dir.path("app/web/public"))) {
|
||||
public_files.push(file);
|
||||
}
|
||||
}
|
||||
await Bun.write(
|
||||
dir.path("app/web/public_files.ts"),
|
||||
`export const files = ${JSON.stringify(public_files, null, 2)}`
|
||||
);
|
||||
|
||||
const static_br = dir.path("app/static-br");
|
||||
await removeAsync(static_br);
|
||||
const files = await listAsync(dir.path("app/static"));
|
||||
if (files) {
|
||||
await Promise.all(
|
||||
files
|
||||
.filter((file) => statSync(dir.path(`app/static/${file}`)).isFile())
|
||||
.map(async (file) => {
|
||||
if (!(await Bun.file(dir.path(`app/static-br/${file}`)).exists())) {
|
||||
await removeAsync(dir.path("app/web/.parcel-cache"));
|
||||
await removeAsync(dir.path("app/static"));
|
||||
|
||||
await writeAsync(
|
||||
dir.path("app/web/timestamp.ts"),
|
||||
`export const version = "${createId().substring(0, 7)}";`
|
||||
);
|
||||
|
||||
const args = [
|
||||
"node",
|
||||
dir.path("node_modules/.bin/parcel"),
|
||||
"build",
|
||||
"./src/index.tsx",
|
||||
// "--no-optimize",
|
||||
"--no-scope-hoist",
|
||||
"--dist-dir",
|
||||
dir.path(`app/static`),
|
||||
];
|
||||
|
||||
const parcel = spawn({
|
||||
cmd: args,
|
||||
cwd: dir.path("app/web"),
|
||||
stdio: ["ignore", "inherit", "inherit"],
|
||||
});
|
||||
await parcel.exited;
|
||||
|
||||
const public_br = dir.path("app/web/public-br");
|
||||
if (!(await existsAsync(public_br))) {
|
||||
const api = new fdir()
|
||||
.withRelativePaths()
|
||||
.crawl(dir.path("app/web/public"));
|
||||
const files = api.sync();
|
||||
if (files) {
|
||||
await Promise.all(
|
||||
files.map(async (file) => {
|
||||
const br = brotli.compress(
|
||||
new Uint8Array(
|
||||
await Bun.file(dir.path(`app/static/${file}`)).arrayBuffer()
|
||||
await Bun.file(dir.path(`app/web/public/${file}`)).arrayBuffer()
|
||||
),
|
||||
{ quality: 11 }
|
||||
);
|
||||
if (br) {
|
||||
console.log(`Compressing [static] ${file}`);
|
||||
console.log(`Compressing [public] ${file}`);
|
||||
await writeAsync(
|
||||
dir.path(`app/static-br/${file}`),
|
||||
dir.path(`app/web/public-br/${file}`),
|
||||
Buffer.from(br)
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const pub = await listAsync(dir.path("app/web/public-br"));
|
||||
if (pub) {
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const static_br = dir.path("app/static-br");
|
||||
await removeAsync(static_br);
|
||||
const files = await listAsync(dir.path("app/static"));
|
||||
if (files) {
|
||||
await Promise.all(
|
||||
pub.map(async (file) => {
|
||||
if (await existsAsync(`app/static-br/${file}`)) {
|
||||
await removeAsync(`app/static-br/${file}`);
|
||||
}
|
||||
await copyAsync(
|
||||
dir.path(`app/web/public-br/${file}`),
|
||||
dir.path(`app/static-br/${file}`)
|
||||
);
|
||||
})
|
||||
files
|
||||
.filter((file) => statSync(dir.path(`app/static/${file}`)).isFile())
|
||||
.map(async (file) => {
|
||||
if (!(await Bun.file(dir.path(`app/static-br/${file}`)).exists())) {
|
||||
const br = brotli.compress(
|
||||
new Uint8Array(
|
||||
await Bun.file(dir.path(`app/static/${file}`)).arrayBuffer()
|
||||
),
|
||||
{ quality: 11 }
|
||||
);
|
||||
if (br) {
|
||||
console.log(`Compressing [static] ${file}`);
|
||||
await writeAsync(
|
||||
dir.path(`app/static-br/${file}`),
|
||||
Buffer.from(br)
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const pub = await listAsync(dir.path("app/web/public-br"));
|
||||
if (pub) {
|
||||
await Promise.all(
|
||||
pub.map(async (file) => {
|
||||
if (await existsAsync(`app/static-br/${file}`)) {
|
||||
await removeAsync(`app/static-br/${file}`);
|
||||
}
|
||||
await copyAsync(
|
||||
dir.path(`app/web/public-br/${file}`),
|
||||
dir.path(`app/static-br/${file}`)
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue