fix
This commit is contained in:
parent
a9ff40264e
commit
27a8ef343c
|
|
@ -4,7 +4,7 @@ import path from "path";
|
||||||
import { gzipAsync } from "../ws/sync/entity/zlib";
|
import { gzipAsync } from "../ws/sync/entity/zlib";
|
||||||
import { validate } from "uuid";
|
import { validate } from "uuid";
|
||||||
import { dir } from "dir";
|
import { dir } from "dir";
|
||||||
import { existsAsync, readAsync } from "fs-jetpack";
|
import { existsAsync, readAsync, exists } from "fs-jetpack";
|
||||||
import { code } from "../ws/sync/code/code";
|
import { code } from "../ws/sync/code/code";
|
||||||
|
|
||||||
export const _ = {
|
export const _ = {
|
||||||
|
|
@ -51,6 +51,9 @@ export const _ = {
|
||||||
},
|
},
|
||||||
select: { id: true, content_tree: true },
|
select: { id: true, content_tree: true },
|
||||||
}),
|
}),
|
||||||
|
public: readDirectoryRecursively(
|
||||||
|
code.path(site_id, "site", "src", "public")
|
||||||
|
),
|
||||||
site: await _db.site.findFirst({
|
site: await _db.site.findFirst({
|
||||||
where: { id: site_id },
|
where: { id: site_id },
|
||||||
select: {
|
select: {
|
||||||
|
|
@ -87,6 +90,7 @@ export function readDirectoryRecursively(
|
||||||
): Record<string, string> {
|
): Record<string, string> {
|
||||||
const result: Record<string, string> = {};
|
const result: Record<string, string> = {};
|
||||||
|
|
||||||
|
if (!exists(dirPath)) return result;
|
||||||
const contents = fs.readdirSync(dirPath);
|
const contents = fs.readdirSync(dirPath);
|
||||||
|
|
||||||
for (const item of contents) {
|
for (const item of contents) {
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,16 @@ declare global {
|
||||||
inputValue?: string;
|
inputValue?: string;
|
||||||
notification: PushNotificationSchema;
|
notification: PushNotificationSchema;
|
||||||
}
|
}
|
||||||
|
interface NOTIF_ARG {
|
||||||
|
user_id: any;
|
||||||
|
body: string;
|
||||||
|
title: string;
|
||||||
|
data?: any;
|
||||||
|
}
|
||||||
const notif:
|
const notif:
|
||||||
| {
|
| {
|
||||||
loaded: (send: (data: any) => void) => void;
|
send: (data: NOTIF_ARG) => Promise<void>;
|
||||||
|
register: (user_id: string) => void;
|
||||||
onReceive: (notif: PushNotificationSchema) => void | Promise<void>;
|
onReceive: (notif: PushNotificationSchema) => void | Promise<void>;
|
||||||
onTap: (notif: null | ActionPerformed) => void | Promise<void>;
|
onTap: (notif: null | ActionPerformed) => void | Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { waitUntil } from "web-utils";
|
||||||
import { PG } from "../../ed/logic/ed-global";
|
import { PG } from "../../ed/logic/ed-global";
|
||||||
import { VG } from "../render/global";
|
import { VG } from "../render/global";
|
||||||
import { PrasiExt, prasi_ext } from "./types";
|
import { PrasiExt, prasi_ext } from "./types";
|
||||||
|
|
@ -32,7 +33,8 @@ interface ActionPerformed {
|
||||||
const w = window as unknown as {
|
const w = window as unknown as {
|
||||||
notif:
|
notif:
|
||||||
| {
|
| {
|
||||||
loaded: (send: (data: any) => void) => void;
|
send: (data: NOTIF_ARG) => Promise<void>;
|
||||||
|
register: (user_id: string) => void;
|
||||||
onReceive: (notif: PushNotificationSchema) => void | Promise<void>;
|
onReceive: (notif: PushNotificationSchema) => void | Promise<void>;
|
||||||
onTap: (notif: null | ActionPerformed) => void | Promise<void>;
|
onTap: (notif: null | ActionPerformed) => void | Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
@ -41,6 +43,13 @@ const w = window as unknown as {
|
||||||
|
|
||||||
export const initExtNotif = async (vi: VG, prasi_ext: PrasiExt) => {
|
export const initExtNotif = async (vi: VG, prasi_ext: PrasiExt) => {
|
||||||
const config = prasi_ext.notif;
|
const config = prasi_ext.notif;
|
||||||
|
w.notif = {
|
||||||
|
async send() {},
|
||||||
|
register() {},
|
||||||
|
onReceive(notif) {},
|
||||||
|
onTap(notif) {},
|
||||||
|
};
|
||||||
|
|
||||||
if (window.parent && config) {
|
if (window.parent && config) {
|
||||||
window.addEventListener("message", async ({ data: raw }) => {
|
window.addEventListener("message", async ({ data: raw }) => {
|
||||||
if (typeof raw === "object" && raw.mobile) {
|
if (typeof raw === "object" && raw.mobile) {
|
||||||
|
|
@ -53,7 +62,7 @@ export const initExtNotif = async (vi: VG, prasi_ext: PrasiExt) => {
|
||||||
| { type: "notification-receive"; notif: PushNotificationSchema };
|
| { type: "notification-receive"; notif: PushNotificationSchema };
|
||||||
|
|
||||||
const waitUntil = async (fn: () => boolean) => {
|
const waitUntil = async (fn: () => boolean) => {
|
||||||
if (!current.notif.onTap) {
|
if (!w.notif?.onTap) {
|
||||||
let ival = null as any;
|
let ival = null as any;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
await new Promise(() => {
|
await new Promise(() => {
|
||||||
|
|
@ -76,10 +85,10 @@ export const initExtNotif = async (vi: VG, prasi_ext: PrasiExt) => {
|
||||||
config.token = data.token;
|
config.token = data.token;
|
||||||
break;
|
break;
|
||||||
case "notification-tap":
|
case "notification-tap":
|
||||||
if (!current.notif.onTap) {
|
if (!w.notif?.onTap) {
|
||||||
waitUntil(() => {
|
waitUntil(() => {
|
||||||
if (current.notif.onTap) {
|
if (w.notif?.onTap) {
|
||||||
current.notif.onTap(data.notif);
|
w.notif?.onTap(data.notif);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -87,63 +96,53 @@ export const initExtNotif = async (vi: VG, prasi_ext: PrasiExt) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current.notif.onTap) {
|
if (w.notif?.onTap) {
|
||||||
current.notif.onTap(data.notif);
|
w.notif?.onTap(data.notif);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "notification-receive":
|
case "notification-receive":
|
||||||
if (!current.notif.onReceive) {
|
if (!w.notif?.onReceive) {
|
||||||
waitUntil(() => {
|
waitUntil(() => {
|
||||||
if (current.notif.onReceive) {
|
if (w.notif?.onReceive) {
|
||||||
current.notif.onReceive(data.notif);
|
w.notif?.onReceive(data.notif);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (current.notif.onReceive) {
|
if (w.notif?.onReceive) {
|
||||||
current.notif.onReceive(data.notif);
|
w.notif?.onReceive(data.notif);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const current = {
|
window.parent.postMessage({ mobile: true, type: "ready" }, "*");
|
||||||
send: (msg: { type: "ready" }) => {
|
w.notif.register = async (user_id: any) => {
|
||||||
window.parent.postMessage({ mobile: true, ...msg }, "*");
|
await waitUntil(() => config.token);
|
||||||
},
|
if (vi && vi.site.api) {
|
||||||
config,
|
return await vi.site.api._notif("register", {
|
||||||
notif: {
|
type: "register",
|
||||||
register: async (user_id: any) => {
|
id: typeof user_id === "string" ? user_id : user_id.toString(),
|
||||||
if (vi && vi.site.api) {
|
token: config.token,
|
||||||
return await vi.site.api._notif("register", {
|
});
|
||||||
type: "register",
|
}
|
||||||
id: typeof user_id === "string" ? user_id : user_id.toString(),
|
};
|
||||||
token: config.token,
|
|
||||||
});
|
w.notif.send = async (data: NOTIF_ARG) => {
|
||||||
}
|
if (vi && vi.site.api) {
|
||||||
},
|
return await vi.site.api._notif("send", {
|
||||||
send: async (data: NOTIF_ARG) => {
|
type: "send",
|
||||||
if (vi && vi.site.api) {
|
id:
|
||||||
return await vi.site.api._notif("send", {
|
typeof data.user_id === "string"
|
||||||
type: "send",
|
? data.user_id
|
||||||
id:
|
: data.user_id.toString(),
|
||||||
typeof data.user_id === "string"
|
body: data.body,
|
||||||
? data.user_id
|
title: data.title,
|
||||||
: data.user_id.toString(),
|
data: data.data,
|
||||||
body: data.body,
|
});
|
||||||
title: data.title,
|
}
|
||||||
data: data.data,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onTap: null as null | Exclude<typeof w.notif, undefined>["onTap"],
|
|
||||||
onReceive: null as
|
|
||||||
| null
|
|
||||||
| Exclude<typeof w.notif, undefined>["onReceive"],
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
current.send({ type: "ready" });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue