levix-bot 4.9.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -3
- package/SETUP.md +63 -7
- package/app.cjs +159 -46
- package/deploy/install.sh +10 -5
- package/package.json +9 -6
- package/public/dashboard/assets/40af6d88b63079a0-BZ8ojJNu.woff2 +0 -0
- package/public/dashboard/assets/481acf6760031cee-BypgxfGb.woff2 +0 -0
- package/public/dashboard/assets/6d3351fc535f8ef3-D2-eand5.woff2 +0 -0
- package/public/dashboard/assets/8ab0af53a3bda9d3-CyCXRvzh.woff2 +0 -0
- package/public/dashboard/assets/8f262393e9249e61-TQp-UTiE.woff2 +0 -0
- package/public/dashboard/assets/94d65887a83f1282-DmpS2jIq.woff2 +0 -0
- package/public/dashboard/assets/99e400330f36ae77-D3oMJlXt.woff2 +0 -0
- package/public/dashboard/assets/9d1f41b13e519d90-BVNSOH3d.woff2 +0 -0
- package/public/dashboard/assets/a005256cb957ecc7-CoYeBiSI.woff2 +0 -0
- package/public/dashboard/assets/b19c2080652a3c2b-DIC32ArD.woff2 +0 -0
- package/public/dashboard/assets/c4064400db3750ce-BehTv68k.woff2 +0 -0
- package/public/dashboard/assets/c69d345fa1068c2d-CmI34b-g.woff2 +0 -0
- package/public/dashboard/assets/cc27b30471250057-6fWv1k7M.woff2 +0 -0
- package/public/dashboard/assets/d8c30647abfeffe6-eXO_dkmS.woff2 +0 -0
- package/public/dashboard/assets/eb83d8d40af4411f-Buze_B52.woff2 +0 -0
- package/public/dashboard/assets/effc6711249e7349-qRpaaN48.woff2 +0 -0
- package/public/dashboard/assets/gateway-BDYet0pI.css +1 -0
- package/public/dashboard/assets/gateway-BYt6-s1O.js +1 -0
- package/public/dashboard/assets/index-B9wFpD_z.css +2 -0
- package/public/dashboard/assets/index-DWcQmu0_.js +124 -0
- package/public/dashboard/assets/index-Da-j89O-.js +458 -0
- package/public/dashboard/font-licenses/jetbrainsmono-OFL.txt +93 -0
- package/public/dashboard/font-licenses/plusjakartasans-OFL.txt +93 -0
- package/public/dashboard/font-licenses/tajawal-OFL.txt +93 -0
- package/public/dashboard/gateway.html +17 -0
- package/public/dashboard/index.html +3 -5
- package/public/ui-boot.js +33 -14
- package/scheduler.cjs +76 -23
- package/src/auth/auth-storage.cjs +54 -7
- package/src/auth/use-database-auth-state.js +70 -39
- package/src/automation/engine.js +412 -0
- package/src/automation/limits.cjs +6 -0
- package/src/automation/manage.js +290 -0
- package/src/automation/reactions.js +471 -0
- package/src/automation/rules.cjs +114 -0
- package/src/automation/status.cjs +76 -0
- package/src/backup/account.cjs +29 -0
- package/src/backup/activation.cjs +247 -0
- package/src/backup/content.cjs +36 -0
- package/src/backup/create.cjs +280 -0
- package/src/backup/extensions.cjs +101 -0
- package/src/backup/format.cjs +565 -0
- package/src/backup/jobs.cjs +111 -0
- package/src/backup/journal.cjs +41 -0
- package/src/backup/plan.cjs +223 -0
- package/src/backup/recovery.cjs +110 -0
- package/src/backup/restore.cjs +460 -0
- package/src/backup/uploads.cjs +146 -0
- package/src/bootstrap/core.js +50 -12
- package/src/bootstrap/panel.js +53 -2
- package/src/bootstrap/session-startup-policy.js +8 -1
- package/src/cli.js +163 -22
- package/src/commands/autodelete.cjs +41 -57
- package/src/commands/autoschedule.cjs +7 -33
- package/src/commands/blacklist.cjs +17 -35
- package/src/commands/block.cjs +4 -18
- package/src/commands/calc.cjs +22 -74
- package/src/commands/debt.cjs +28 -59
- package/src/commands/deleteschedule.cjs +7 -23
- package/src/commands/digit.cjs +5 -39
- package/src/commands/gemini.cjs +135 -218
- package/src/commands/group/add.cjs +28 -76
- package/src/commands/group/all.cjs +4 -15
- package/src/commands/group/antilink.cjs +28 -41
- package/src/commands/group/antispam.cjs +25 -35
- package/src/commands/group/approveall.cjs +7 -21
- package/src/commands/group/clearwarns.cjs +4 -18
- package/src/commands/group/deletenote.cjs +4 -18
- package/src/commands/group/demote.cjs +6 -23
- package/src/commands/group/flagged.cjs +10 -19
- package/src/commands/group/kick.cjs +26 -36
- package/src/commands/group/media.cjs +21 -36
- package/src/commands/group/members.cjs +16 -28
- package/src/commands/group/note.cjs +3 -14
- package/src/commands/group/policy.cjs +16 -37
- package/src/commands/group/promote.cjs +5 -22
- package/src/commands/group/removeall.cjs +6 -38
- package/src/commands/group/rules.cjs +4 -19
- package/src/commands/group/save.cjs +4 -18
- package/src/commands/group/setname.cjs +5 -19
- package/src/commands/group/setpp.cjs +8 -26
- package/src/commands/group/setrules.cjs +4 -15
- package/src/commands/group/setwarn.cjs +6 -23
- package/src/commands/group/tagadmins.cjs +5 -16
- package/src/commands/group/warn.cjs +5 -16
- package/src/commands/group/warns.cjs +12 -33
- package/src/commands/group/welcome.cjs +17 -34
- package/src/commands/group.cjs +91 -68
- package/src/commands/help.cjs +48 -89
- package/src/commands/lang.cjs +38 -97
- package/src/commands/listschedules.cjs +19 -30
- package/src/commands/loop.cjs +9 -55
- package/src/commands/md.cjs +2 -13
- package/src/commands/memory.cjs +53 -87
- package/src/commands/mod.cjs +40 -79
- package/src/commands/notes.cjs +4 -15
- package/src/commands/pack.cjs +26 -49
- package/src/commands/packs.cjs +8 -18
- package/src/commands/perm.cjs +48 -51
- package/src/commands/ping.cjs +2 -10
- package/src/commands/poll.cjs +5 -38
- package/src/commands/prayer.cjs +55 -36
- package/src/commands/qr.cjs +4 -18
- package/src/commands/rand.cjs +9 -58
- package/src/commands/restart.cjs +15 -33
- package/src/commands/schedule.cjs +5 -25
- package/src/commands/score.cjs +6 -27
- package/src/commands/send.cjs +4 -18
- package/src/commands/setprefix.cjs +11 -23
- package/src/commands/shortlink.cjs +13 -39
- package/src/commands/status.cjs +188 -76
- package/src/commands/sticker.cjs +5 -16
- package/src/commands/stickers.cjs +16 -20
- package/src/commands/stopbot.cjs +9 -25
- package/src/commands/stt.cjs +75 -107
- package/src/commands/todo.cjs +11 -31
- package/src/commands/toimage.cjs +11 -27
- package/src/commands/translate.cjs +53 -36
- package/src/commands/tts.cjs +46 -40
- package/src/commands/unblock.cjs +3 -17
- package/src/commands/update.cjs +23 -0
- package/src/commands/weather.cjs +40 -47
- package/src/config/ai-identity.cjs +14 -1
- package/src/config/baileys.config.js +16 -3
- package/src/config/data-dir.cjs +37 -0
- package/src/config/defaults.cjs +1 -0
- package/src/config/exit-codes.cjs +11 -0
- package/src/config/lock.cjs +55 -81
- package/src/config/official-links.cjs +61 -0
- package/src/config/paths.cjs +4 -33
- package/src/config/release.cjs +87 -0
- package/src/config/settings.cjs +199 -10
- package/src/core/connection.js +77 -9
- package/src/core/events.js +119 -33
- package/src/core/session.js +536 -84
- package/src/core/socket.js +81 -10
- package/src/db/copy.cjs +136 -0
- package/src/db/db.cjs +241 -36
- package/src/db/startup-guard.js +5 -0
- package/src/db/store.cjs +561 -54
- package/src/diagnostics/baileysLog.cjs +87 -0
- package/src/diagnostics/debugLog.cjs +16 -4
- package/src/diagnostics/device.cjs +4 -2
- package/src/diagnostics/nodeRuntime.cjs +131 -0
- package/src/diagnostics/signalSessionInspect.cjs +38 -0
- package/src/domain/command.js +24 -22
- package/src/extensions/autoReply.cjs +521 -0
- package/src/extensions/context.cjs +73 -0
- package/src/extensions/contract.cjs +69 -0
- package/src/extensions/entitlement/client.cjs +381 -0
- package/src/extensions/entitlement/index.cjs +629 -0
- package/src/extensions/entitlement/installation.cjs +117 -0
- package/src/extensions/entitlement/keys.cjs +72 -0
- package/src/extensions/entitlement/state.cjs +201 -0
- package/src/extensions/entitlement/target.cjs +7 -0
- package/src/extensions/entitlement/token.cjs +225 -0
- package/src/extensions/host.cjs +519 -0
- package/src/extensions/templateKeys.cjs +81 -0
- package/src/handlers/command.handler.js +191 -64
- package/src/handlers/group.handler.js +78 -18
- package/src/handlers/message.handler.js +56 -25
- package/src/i18n/catalog.generated.cjs +3537 -0
- package/src/index.js +51 -12
- package/src/legal/bundled/ar.json +102 -0
- package/src/legal/bundled/en.json +102 -0
- package/src/legal/bundled/es-419.json +102 -0
- package/src/legal/bundled/pt-BR.json +102 -0
- package/src/legal/cli.cjs +200 -0
- package/src/legal/consent.cjs +187 -0
- package/src/legal/document.cjs +156 -0
- package/src/legal/keys.cjs +100 -0
- package/src/legal/release.cjs +226 -0
- package/src/legal/remote.cjs +419 -0
- package/src/legal/terms.cjs +142 -0
- package/src/messaging/escape.cjs +31 -0
- package/src/messaging/health.cjs +65 -0
- package/src/messaging/identity.cjs +42 -0
- package/src/messaging/message.cjs +136 -0
- package/src/messaging/parser.cjs +88 -0
- package/src/messaging/router.cjs +217 -0
- package/src/middleware/permissions.middleware.js +34 -2
- package/src/panel/account-profile.cjs +489 -0
- package/src/panel/fallback-page.cjs +177 -0
- package/src/panel/password-reset.cjs +13 -14
- package/src/panel/recovery-email.cjs +3 -1
- package/src/routes/backup.api.esm.js +175 -0
- package/src/routes/dashboard.api.esm.js +183 -7
- package/src/routes/plus.api.esm.js +172 -0
- package/src/routes/reactions.api.esm.js +60 -0
- package/src/services/aiAgent.cjs +56 -43
- package/src/services/aiDocs.cjs +187 -0
- package/src/services/aiImage.cjs +183 -0
- package/src/services/aiMedia.cjs +146 -0
- package/src/services/aiProviders.cjs +76 -80
- package/src/services/aiRouter.cjs +2 -2
- package/src/services/aiToolAuth.cjs +76 -4
- package/src/services/aiTools.cjs +431 -105
- package/src/services/autoDelete.cjs +9 -1
- package/src/services/levix-docs.generated.json +2623 -0
- package/src/services/memoryPolicy.cjs +56 -0
- package/src/services/updateCheck.cjs +362 -0
- package/src/stickers/errors.cjs +53 -97
- package/src/stickers/library.cjs +13 -6
- package/src/stickers/owner.cjs +1 -1
- package/src/utils/commandContext.cjs +13 -0
- package/src/utils/commandDocs.cjs +42 -20
- package/src/utils/geminiHttpOptions.cjs +56 -0
- package/src/utils/geminiMedia.cjs +28 -3
- package/src/utils/groupMetadataCache.cjs +386 -21
- package/src/utils/httpsFetch.cjs +113 -0
- package/src/utils/i18n.cjs +117 -7
- package/src/utils/linkPreview.cjs +90 -0
- package/src/utils/logger.cjs +6 -0
- package/src/utils/markdownParser.cjs +3 -3
- package/src/utils/memory.cjs +375 -28
- package/src/utils/messageContent.cjs +7 -1
- package/src/utils/moderationAction.cjs +116 -73
- package/src/utils/moderationSummary.cjs +32 -56
- package/src/utils/permissionLevel.cjs +7 -28
- package/src/utils/permissions.cjs +23 -14
- package/src/utils/permissions.esm.js +99 -166
- package/src/utils/recentMessageCache.esm.js +241 -37
- package/src/utils/recurrence.cjs +78 -66
- package/src/utils/sendBotMessage.cjs +14 -29
- package/src/utils/sendBotMessage.esm.js +28 -13
- package/src/utils/statusMessage.cjs +94 -33
- package/src/utils/stickerBot.cjs +18 -16
- package/src/utils/storage.cjs +2 -0
- package/src/utils/storage.esm.js +2 -0
- package/src/utils/thumbnail.cjs +5 -21
- package/public/dashboard/assets/index-B1sOW2VX.js +0 -561
- package/public/dashboard/assets/index-CK8osB4o.css +0 -2
- package/public/dashboard.css +0 -3127
- package/public/dashboard.js +0 -1981
- package/public/gateway-i18n.js +0 -321
- package/public/gateway.js +0 -70
- package/views/dashboard.ejs +0 -775
- package/views/login.ejs +0 -408
- package/views/qr.ejs +0 -155
- package/views/setup.ejs +0 -118
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
// Connected WhatsApp account profile.
|
|
2
|
+
//
|
|
3
|
+
// Everything here is memory-only and scoped to the live socket: the account's
|
|
4
|
+
// own name, verified phone number, About text and profile picture. The panel
|
|
5
|
+
// never sees a remote image URL (Android's privileged WebView blocks remote
|
|
6
|
+
// resources), so a photo is described by an opaque revision and bytes are read
|
|
7
|
+
// lazily through an authenticated route.
|
|
8
|
+
//
|
|
9
|
+
// The identity rules mirror src/messaging/identity.cjs and
|
|
10
|
+
// src/utils/normalizeJid.cjs: a phone number only ever comes from a
|
|
11
|
+
// `@s.whatsapp.net` JID, never from a LID and never from a typed setting. The
|
|
12
|
+
// current socket is authoritative; the verified pairing credentials are only a
|
|
13
|
+
// fallback, and only while they still describe the socket we are reading.
|
|
14
|
+
//
|
|
15
|
+
// A result is written to the cache only while the socket reference, the
|
|
16
|
+
// normalized self identity, the account epoch and connectivity all still match
|
|
17
|
+
// the context the lookup started in. Disconnect, reconnect or unlink therefore
|
|
18
|
+
// discards in-flight work instead of handing it to the next account.
|
|
19
|
+
|
|
20
|
+
const crypto = require("node:crypto");
|
|
21
|
+
const normalizeJid = require("../utils/normalizeJid.cjs");
|
|
22
|
+
|
|
23
|
+
const PICTURE_TIMEOUT_MS = 8000;
|
|
24
|
+
const ALLOWED_IMAGE_MIME = new Set(["image/jpeg", "image/png", "image/webp"]);
|
|
25
|
+
|
|
26
|
+
// Validate the complete address before the shared device-suffix normalization.
|
|
27
|
+
function ownJid(value) {
|
|
28
|
+
if (typeof value !== "string" || !/^\d+(?::\d+)?@(s\.whatsapp\.net|lid)$/.test(value))
|
|
29
|
+
return null;
|
|
30
|
+
return normalizeJid(value);
|
|
31
|
+
}
|
|
32
|
+
function isPhoneJid(value) {
|
|
33
|
+
return ownJid(value)?.endsWith("@s.whatsapp.net") === true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function boundedText(value, max) {
|
|
37
|
+
if (typeof value !== "string") return null;
|
|
38
|
+
const trimmed = value.trim();
|
|
39
|
+
if (!trimmed) return null;
|
|
40
|
+
return trimmed.slice(0, max);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Digits of a phone-number JID, or null. A LID can never become a phone. */
|
|
44
|
+
function phoneFromPnJid(jid) {
|
|
45
|
+
const normalized = ownJid(jid);
|
|
46
|
+
return normalized?.endsWith("@s.whatsapp.net") ? `+${normalized.split("@")[0]}` : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {object} options
|
|
51
|
+
* @param {() => {socket?: object|null, state?: object, epoch?: number, identity?: object}} options.getContext
|
|
52
|
+
* @param {(socket: object, url: string, init: object) => Promise<object>} [options.fetchImage]
|
|
53
|
+
* @param {() => number} [options.now]
|
|
54
|
+
* @param {number} [options.timeoutMs]
|
|
55
|
+
* @param {number} [options.ttlMs]
|
|
56
|
+
* @param {number} [options.refreshCooldownMs]
|
|
57
|
+
* @param {number} [options.maxPhotoBytes]
|
|
58
|
+
*/
|
|
59
|
+
function createAccountProfile({
|
|
60
|
+
getContext,
|
|
61
|
+
fetchImage = null,
|
|
62
|
+
now = Date.now,
|
|
63
|
+
timeoutMs = 8000,
|
|
64
|
+
ttlMs = 300_000,
|
|
65
|
+
refreshCooldownMs = 10_000,
|
|
66
|
+
maxPhotoBytes = 1024 * 1024,
|
|
67
|
+
} = {}) {
|
|
68
|
+
if (typeof getContext !== "function") throw new TypeError("getContext is required");
|
|
69
|
+
|
|
70
|
+
let generation = 0;
|
|
71
|
+
let metadata = null; // { snapshot, revision, name, phone, about, photoInternal, expiresAt }
|
|
72
|
+
let metadataInFlight = null; // { snapshot, promise }
|
|
73
|
+
let image = null; // { snapshot, revision, expiresAt, negative, bytes?, mime? }
|
|
74
|
+
let imageInFlight = null; // { snapshot, revision, promise }
|
|
75
|
+
let lastLookupAt = null;
|
|
76
|
+
const controllers = new Set();
|
|
77
|
+
|
|
78
|
+
function readContext() {
|
|
79
|
+
let raw = null;
|
|
80
|
+
try {
|
|
81
|
+
raw = getContext();
|
|
82
|
+
} catch {
|
|
83
|
+
raw = null;
|
|
84
|
+
}
|
|
85
|
+
const socket = raw?.socket && typeof raw.socket === "object" ? raw.socket : null;
|
|
86
|
+
const state = raw?.state && typeof raw.state === "object" ? raw.state : {};
|
|
87
|
+
const identity = raw?.identity && typeof raw.identity === "object" ? raw.identity : {};
|
|
88
|
+
const selfJids = Array.isArray(identity.selfJids)
|
|
89
|
+
? [...new Set(identity.selfJids.map(ownJid).filter(Boolean))].sort()
|
|
90
|
+
: [];
|
|
91
|
+
const selfId = ownJid(socket?.user?.id);
|
|
92
|
+
const connected = Boolean(socket && state.connected);
|
|
93
|
+
|
|
94
|
+
let phone = null;
|
|
95
|
+
if (selfId && isPhoneJid(selfId)) {
|
|
96
|
+
phone = phoneFromPnJid(selfId);
|
|
97
|
+
} else if (selfId && selfJids.includes(selfId) && isPhoneJid(identity.phone)) {
|
|
98
|
+
// Only while the verified pairing still names this socket's LID.
|
|
99
|
+
phone = phoneFromPnJid(identity.phone);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
generation,
|
|
104
|
+
socket,
|
|
105
|
+
connected,
|
|
106
|
+
epoch: raw?.epoch ?? null,
|
|
107
|
+
selfId,
|
|
108
|
+
name: boundedText(socket?.user?.name, 256),
|
|
109
|
+
phone,
|
|
110
|
+
selfJidsKey: selfJids.join("|"),
|
|
111
|
+
acceptedIds: selfJids.includes(selfId) ? selfJids : [selfId].filter(Boolean),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function sameContext(a, b) {
|
|
116
|
+
if (!a || !b) return false;
|
|
117
|
+
return (
|
|
118
|
+
a.generation === b.generation &&
|
|
119
|
+
a.socket === b.socket &&
|
|
120
|
+
a.epoch === b.epoch &&
|
|
121
|
+
a.selfId === b.selfId &&
|
|
122
|
+
a.phone === b.phone &&
|
|
123
|
+
a.selfJidsKey === b.selfJidsKey &&
|
|
124
|
+
a.connected === b.connected
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function abortImages() {
|
|
129
|
+
for (const controller of controllers) {
|
|
130
|
+
try {
|
|
131
|
+
controller.abort();
|
|
132
|
+
} catch {}
|
|
133
|
+
}
|
|
134
|
+
controllers.clear();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function resetCache({ abort = true } = {}) {
|
|
138
|
+
metadata = null;
|
|
139
|
+
lastLookupAt = null;
|
|
140
|
+
metadataInFlight = null;
|
|
141
|
+
image = null;
|
|
142
|
+
imageInFlight = null;
|
|
143
|
+
if (abort) abortImages();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function discardStale(snapshot) {
|
|
147
|
+
if (metadata && !sameContext(metadata.snapshot, snapshot)) {
|
|
148
|
+
metadata = null;
|
|
149
|
+
image = null;
|
|
150
|
+
}
|
|
151
|
+
if (image && !sameContext(image.snapshot, snapshot)) image = null;
|
|
152
|
+
if (metadataInFlight && !sameContext(metadataInFlight.snapshot, snapshot)) {
|
|
153
|
+
metadataInFlight = null;
|
|
154
|
+
}
|
|
155
|
+
if (imageInFlight && !sameContext(imageInFlight.snapshot, snapshot)) {
|
|
156
|
+
imageInFlight = null;
|
|
157
|
+
abortImages();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function refreshAfterMs() {
|
|
162
|
+
if (lastLookupAt === null) return 0;
|
|
163
|
+
const remaining = refreshCooldownMs - (now() - lastLookupAt);
|
|
164
|
+
return remaining > 0 ? Math.ceil(remaining) : 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function emptyProfile(snapshot) {
|
|
168
|
+
return {
|
|
169
|
+
connected: Boolean(snapshot?.connected),
|
|
170
|
+
name: null,
|
|
171
|
+
phone: null,
|
|
172
|
+
about: null,
|
|
173
|
+
photoUrl: null,
|
|
174
|
+
revision: null,
|
|
175
|
+
refreshAfterMs: refreshAfterMs(),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function localProfile(snapshot) {
|
|
180
|
+
if (!snapshot?.connected) return emptyProfile(snapshot);
|
|
181
|
+
return {
|
|
182
|
+
connected: true,
|
|
183
|
+
name: snapshot.name ?? null,
|
|
184
|
+
phone: snapshot.phone ?? null,
|
|
185
|
+
about: null,
|
|
186
|
+
photoUrl: null,
|
|
187
|
+
revision: null,
|
|
188
|
+
refreshAfterMs: refreshAfterMs(),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function view(entry, snapshot) {
|
|
193
|
+
const hasPhoto = Boolean(entry.photoInternal);
|
|
194
|
+
return {
|
|
195
|
+
connected: Boolean(snapshot.connected),
|
|
196
|
+
name: snapshot.name ?? null,
|
|
197
|
+
phone: snapshot.phone ?? null,
|
|
198
|
+
about: entry.about ?? null,
|
|
199
|
+
photoUrl: hasPhoto
|
|
200
|
+
? `/dashboard/api/account/photo?revision=${encodeURIComponent(entry.revision)}`
|
|
201
|
+
: null,
|
|
202
|
+
revision: hasPhoto ? entry.revision : null,
|
|
203
|
+
refreshAfterMs: refreshAfterMs(),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Resolve within `ms` even when the wrapped promise ignores its signal. */
|
|
208
|
+
function settleWithin(value, ms) {
|
|
209
|
+
return new Promise((resolve) => {
|
|
210
|
+
let done = false;
|
|
211
|
+
let timer = null;
|
|
212
|
+
const finish = (result) => {
|
|
213
|
+
if (done) return;
|
|
214
|
+
done = true;
|
|
215
|
+
if (timer) clearTimeout(timer);
|
|
216
|
+
resolve(result);
|
|
217
|
+
};
|
|
218
|
+
timer = setTimeout(() => finish({ status: "timeout" }), Math.max(0, ms));
|
|
219
|
+
Promise.resolve(value).then(
|
|
220
|
+
(result) => finish({ status: "fulfilled", value: result }),
|
|
221
|
+
(error) => finish({ status: "rejected", reason: error }),
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function callWithin(socket, method, args) {
|
|
227
|
+
if (!socket || typeof socket[method] !== "function") {
|
|
228
|
+
return Promise.resolve({ status: "fulfilled", value: null });
|
|
229
|
+
}
|
|
230
|
+
let call;
|
|
231
|
+
try {
|
|
232
|
+
call = socket[method](...args);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
return Promise.resolve({ status: "rejected", reason: error });
|
|
235
|
+
}
|
|
236
|
+
return settleWithin(call, timeoutMs);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function statusAbout(value, snapshot) {
|
|
240
|
+
if (!Array.isArray(value)) return null;
|
|
241
|
+
const row = value.find(
|
|
242
|
+
(candidate) =>
|
|
243
|
+
candidate &&
|
|
244
|
+
typeof candidate === "object" &&
|
|
245
|
+
typeof candidate.id === "string" &&
|
|
246
|
+
snapshot.acceptedIds.includes(ownJid(candidate.id)),
|
|
247
|
+
);
|
|
248
|
+
// rc14: { id, status: { status: string|null, setAt: Date } }. A row for
|
|
249
|
+
// any other JID is ignored instead of being shown as this account's About.
|
|
250
|
+
const status = row?.status;
|
|
251
|
+
return boundedText(status && typeof status === "object" ? status.status : null, 2048);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function lookup(snapshot) {
|
|
255
|
+
const [picture, status] = await Promise.all([
|
|
256
|
+
callWithin(snapshot.socket, "profilePictureUrl", [
|
|
257
|
+
snapshot.selfId,
|
|
258
|
+
"image",
|
|
259
|
+
PICTURE_TIMEOUT_MS,
|
|
260
|
+
]),
|
|
261
|
+
callWithin(snapshot.socket, "fetchStatus", [snapshot.selfId]),
|
|
262
|
+
]);
|
|
263
|
+
|
|
264
|
+
const photoInternal =
|
|
265
|
+
picture.status === "fulfilled" && typeof picture.value === "string" && picture.value.trim()
|
|
266
|
+
? picture.value.trim()
|
|
267
|
+
: null;
|
|
268
|
+
const about = status.status === "fulfilled" ? statusAbout(status.value, snapshot) : null;
|
|
269
|
+
|
|
270
|
+
const current = readContext();
|
|
271
|
+
if (!sameContext(snapshot, current) || !current.connected) {
|
|
272
|
+
return emptyProfile(current);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const entry = {
|
|
276
|
+
snapshot,
|
|
277
|
+
revision: crypto.randomUUID(),
|
|
278
|
+
name: snapshot.name,
|
|
279
|
+
phone: snapshot.phone,
|
|
280
|
+
about,
|
|
281
|
+
photoInternal,
|
|
282
|
+
expiresAt: now() + ttlMs,
|
|
283
|
+
};
|
|
284
|
+
metadata = entry;
|
|
285
|
+
if (image && (image.revision !== entry.revision || !sameContext(image.snapshot, current))) {
|
|
286
|
+
image = null;
|
|
287
|
+
}
|
|
288
|
+
return view(entry, snapshot);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function startLookup(snapshot) {
|
|
292
|
+
lastLookupAt = now();
|
|
293
|
+
const promise = lookup(snapshot);
|
|
294
|
+
const flight = { snapshot, promise };
|
|
295
|
+
metadataInFlight = flight;
|
|
296
|
+
promise
|
|
297
|
+
.finally(() => {
|
|
298
|
+
if (metadataInFlight === flight) metadataInFlight = null;
|
|
299
|
+
})
|
|
300
|
+
.catch(() => {});
|
|
301
|
+
return promise;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async function get() {
|
|
305
|
+
const snapshot = readContext();
|
|
306
|
+
if (!snapshot.connected || !snapshot.selfId) {
|
|
307
|
+
resetCache({ abort: true });
|
|
308
|
+
return localProfile(snapshot);
|
|
309
|
+
}
|
|
310
|
+
discardStale(snapshot);
|
|
311
|
+
|
|
312
|
+
if (metadata && sameContext(metadata.snapshot, snapshot) && now() < metadata.expiresAt) {
|
|
313
|
+
return view(metadata, snapshot);
|
|
314
|
+
}
|
|
315
|
+
if (metadataInFlight && sameContext(metadataInFlight.snapshot, snapshot)) {
|
|
316
|
+
return metadataInFlight.promise;
|
|
317
|
+
}
|
|
318
|
+
return startLookup(snapshot);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async function refresh() {
|
|
322
|
+
const snapshot = readContext();
|
|
323
|
+
if (!snapshot.connected || !snapshot.selfId) {
|
|
324
|
+
resetCache({ abort: true });
|
|
325
|
+
return localProfile(snapshot);
|
|
326
|
+
}
|
|
327
|
+
discardStale(snapshot);
|
|
328
|
+
|
|
329
|
+
if (metadataInFlight && sameContext(metadataInFlight.snapshot, snapshot)) {
|
|
330
|
+
return metadataInFlight.promise;
|
|
331
|
+
}
|
|
332
|
+
if (lastLookupAt !== null && now() - lastLookupAt < refreshCooldownMs) {
|
|
333
|
+
return metadata && sameContext(metadata.snapshot, snapshot) && now() < metadata.expiresAt
|
|
334
|
+
? view(metadata, snapshot)
|
|
335
|
+
: localProfile(snapshot);
|
|
336
|
+
}
|
|
337
|
+
return startLookup(snapshot);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function mimeOf(response) {
|
|
341
|
+
const raw = response?.headers?.get?.("content-type");
|
|
342
|
+
if (typeof raw !== "string") return null;
|
|
343
|
+
const mime = raw.split(";")[0].trim().toLowerCase();
|
|
344
|
+
return ALLOWED_IMAGE_MIME.has(mime) ? mime : null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async function loadImage(snapshot, revision, url, expiresAt) {
|
|
348
|
+
const controller = new AbortController();
|
|
349
|
+
controllers.add(controller);
|
|
350
|
+
let reader = null;
|
|
351
|
+
let response = null;
|
|
352
|
+
let timer;
|
|
353
|
+
let value = null;
|
|
354
|
+
const cancel = () => {
|
|
355
|
+
controller.abort();
|
|
356
|
+
try {
|
|
357
|
+
reader?.cancel().catch(() => {});
|
|
358
|
+
} catch {}
|
|
359
|
+
try {
|
|
360
|
+
reader?.releaseLock();
|
|
361
|
+
} catch {}
|
|
362
|
+
try {
|
|
363
|
+
if (response?.body && !response.body.locked) response.body.cancel().catch(() => {});
|
|
364
|
+
} catch {}
|
|
365
|
+
};
|
|
366
|
+
const deadline = new Promise((_, reject) => {
|
|
367
|
+
timer = setTimeout(() => {
|
|
368
|
+
cancel();
|
|
369
|
+
reject(new Error("Account photo timed out"));
|
|
370
|
+
}, timeoutMs);
|
|
371
|
+
});
|
|
372
|
+
const read = async () => {
|
|
373
|
+
if (!sameContext(snapshot, readContext())) throw new Error("Stale account");
|
|
374
|
+
response = await fetchImage(snapshot.socket, url, { signal: controller.signal });
|
|
375
|
+
if (controller.signal.aborted) {
|
|
376
|
+
cancel();
|
|
377
|
+
throw new Error("Cancelled");
|
|
378
|
+
}
|
|
379
|
+
if (!sameContext(snapshot, readContext())) throw new Error("Stale account");
|
|
380
|
+
const mime = mimeOf(response);
|
|
381
|
+
if (!response.ok || !mime) throw new Error("Unavailable account photo");
|
|
382
|
+
const declared = response.headers.get("content-length");
|
|
383
|
+
if (declared && (!/^\d+$/.test(declared) || Number(declared) > maxPhotoBytes)) {
|
|
384
|
+
throw new Error("Account photo exceeds size limit");
|
|
385
|
+
}
|
|
386
|
+
if (!response.body?.getReader) throw new Error("Missing photo stream");
|
|
387
|
+
reader = response.body.getReader();
|
|
388
|
+
const chunks = [];
|
|
389
|
+
let total = 0;
|
|
390
|
+
while (true) {
|
|
391
|
+
controller.signal.throwIfAborted();
|
|
392
|
+
const { done, value: chunk } = await reader.read();
|
|
393
|
+
if (done) break;
|
|
394
|
+
total += chunk.byteLength;
|
|
395
|
+
if (total > maxPhotoBytes) throw new Error("Account photo exceeds size limit");
|
|
396
|
+
chunks.push(chunk);
|
|
397
|
+
}
|
|
398
|
+
if (!total) throw new Error("Empty photo");
|
|
399
|
+
return { bytes: Buffer.concat(chunks, total), mime };
|
|
400
|
+
};
|
|
401
|
+
try {
|
|
402
|
+
value = await Promise.race([read(), deadline]);
|
|
403
|
+
} catch {
|
|
404
|
+
value = null;
|
|
405
|
+
} finally {
|
|
406
|
+
clearTimeout(timer);
|
|
407
|
+
controllers.delete(controller);
|
|
408
|
+
// Cleanup is best effort and must never extend the request deadline.
|
|
409
|
+
cancel();
|
|
410
|
+
}
|
|
411
|
+
const current = readContext();
|
|
412
|
+
if (
|
|
413
|
+
!sameContext(snapshot, current) ||
|
|
414
|
+
!current.connected ||
|
|
415
|
+
!metadata ||
|
|
416
|
+
metadata.revision !== revision ||
|
|
417
|
+
now() >= expiresAt
|
|
418
|
+
)
|
|
419
|
+
return null;
|
|
420
|
+
// All failures, including HTTP/MIME/size/empty-body/timeout, share this
|
|
421
|
+
// negative cache. Repeated image requests never refetch the same failure.
|
|
422
|
+
image = { snapshot, revision, expiresAt, negative: !value, ...value };
|
|
423
|
+
return value;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
async function photo(revision) {
|
|
427
|
+
if (typeof revision !== "string" || !revision) return null;
|
|
428
|
+
|
|
429
|
+
const snapshot = readContext();
|
|
430
|
+
if (!snapshot.connected || !snapshot.selfId) {
|
|
431
|
+
resetCache({ abort: true });
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
discardStale(snapshot);
|
|
435
|
+
|
|
436
|
+
if (
|
|
437
|
+
!metadata ||
|
|
438
|
+
!sameContext(metadata.snapshot, snapshot) ||
|
|
439
|
+
metadata.revision !== revision ||
|
|
440
|
+
!metadata.photoInternal ||
|
|
441
|
+
now() >= metadata.expiresAt
|
|
442
|
+
) {
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (
|
|
447
|
+
image &&
|
|
448
|
+
sameContext(image.snapshot, snapshot) &&
|
|
449
|
+
image.revision === revision &&
|
|
450
|
+
now() < image.expiresAt
|
|
451
|
+
) {
|
|
452
|
+
return image.negative ? null : { bytes: image.bytes, mime: image.mime };
|
|
453
|
+
}
|
|
454
|
+
if (
|
|
455
|
+
imageInFlight &&
|
|
456
|
+
sameContext(imageInFlight.snapshot, snapshot) &&
|
|
457
|
+
imageInFlight.revision === revision
|
|
458
|
+
) {
|
|
459
|
+
return imageInFlight.promise;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const expiresAt = metadata.expiresAt;
|
|
463
|
+
const url = metadata.photoInternal;
|
|
464
|
+
if (!fetchImage) {
|
|
465
|
+
image = { snapshot, revision, expiresAt, negative: true };
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const promise = loadImage(snapshot, revision, url, expiresAt);
|
|
470
|
+
const flight = { snapshot, revision, promise };
|
|
471
|
+
imageInFlight = flight;
|
|
472
|
+
promise
|
|
473
|
+
.finally(() => {
|
|
474
|
+
if (imageInFlight === flight) imageInFlight = null;
|
|
475
|
+
})
|
|
476
|
+
.catch(() => {});
|
|
477
|
+
return promise;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function reset() {
|
|
481
|
+
generation += 1;
|
|
482
|
+
lastLookupAt = null;
|
|
483
|
+
resetCache({ abort: true });
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return { get, refresh, photo, reset };
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
module.exports = { createAccountProfile };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// The page the panel serves when the React build is missing: a source checkout
|
|
2
|
+
// before `npm run build:frontend`, or a broken package. Code-owned static HTML,
|
|
3
|
+
// no template engine.
|
|
4
|
+
//
|
|
5
|
+
// Rules this file keeps:
|
|
6
|
+
// - One escape function, `escapeHtml`, wraps every dynamic value.
|
|
7
|
+
// - No script, no inline event handler, no remote resource.
|
|
8
|
+
// - Login and setup are native forms, so they work with JavaScript off: same
|
|
9
|
+
// URLs, same field names, same `autocomplete` values as the React gateway.
|
|
10
|
+
// - The QR string and every secret stay out of it. The QR page and the signed-in
|
|
11
|
+
// `/` only say the panel files are missing.
|
|
12
|
+
//
|
|
13
|
+
// The copy is English only on purpose. This page exists for the operator who
|
|
14
|
+
// has to fix the install, not for the everyday panel, and the translated
|
|
15
|
+
// catalog ships with the frontend build that is missing.
|
|
16
|
+
|
|
17
|
+
const brand = require("../config/brand.cjs");
|
|
18
|
+
|
|
19
|
+
const ESCAPES = {
|
|
20
|
+
"&": "&",
|
|
21
|
+
"<": "<",
|
|
22
|
+
">": ">",
|
|
23
|
+
'"': """,
|
|
24
|
+
"'": "'",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function escapeHtml(value) {
|
|
28
|
+
return String(value ?? "").replace(/[&<>"']/g, (char) => ESCAPES[char]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const STYLE = `
|
|
32
|
+
:root{color-scheme:light dark;--bg:#f6f7f9;--panel:#fff;--text:#14171a;--muted:#5b6670;--line:#d5dae0;--brand:#0b7a75;--danger:#b3261e}
|
|
33
|
+
@media (prefers-color-scheme:dark){:root{--bg:#0f1214;--panel:#181c1f;--text:#eceff1;--muted:#9aa5ad;--line:#2b3338;--brand:#3cc7bf;--danger:#ff8a80}}
|
|
34
|
+
*{box-sizing:border-box}
|
|
35
|
+
body{margin:0;min-height:100vh;display:grid;place-items:center;padding:16px;background:var(--bg);color:var(--text);font:16px/1.5 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif}
|
|
36
|
+
main{width:100%;max-width:26rem;background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:24px}
|
|
37
|
+
h1{margin:0 0 4px;font-size:1.4rem}
|
|
38
|
+
p{margin:8px 0}
|
|
39
|
+
.muted{color:var(--muted);font-size:.9rem}
|
|
40
|
+
label{display:block;margin-top:16px;font-weight:600}
|
|
41
|
+
input{display:block;width:100%;margin-top:6px;padding:10px 12px;border:1px solid var(--line);border-radius:8px;background:var(--bg);color:var(--text);font:inherit}
|
|
42
|
+
small{display:block;margin-top:4px;color:var(--muted);font-weight:400}
|
|
43
|
+
button{margin-top:20px;width:100%;padding:10px 12px;border:0;border-radius:8px;background:var(--brand);color:var(--bg);font:inherit;font-weight:600;cursor:pointer}
|
|
44
|
+
.error{margin-top:16px;color:var(--danger);font-weight:600}
|
|
45
|
+
.notice{margin-top:16px;padding:10px 12px;border:1px solid var(--line);border-radius:8px}
|
|
46
|
+
code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
47
|
+
footer{margin-top:24px;border-top:1px solid var(--line);padding-top:12px;text-align:center}
|
|
48
|
+
footer a{color:inherit}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const MISSING_NOTICE =
|
|
52
|
+
"The panel files are missing, so this basic page is shown. " +
|
|
53
|
+
"Run `npm run build:frontend`, or reinstall Levix.";
|
|
54
|
+
|
|
55
|
+
function notice() {
|
|
56
|
+
return `<p class="notice" role="status">${escapeHtml(MISSING_NOTICE)}</p>`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function errorBlock(error) {
|
|
60
|
+
return error ? `<p class="error" role="alert">${escapeHtml(error)}</p>` : "";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function credits() {
|
|
64
|
+
return (
|
|
65
|
+
`<footer class="muted">Built by ` +
|
|
66
|
+
`<a href="${escapeHtml(brand.developerSite)}">${escapeHtml(brand.developer)}</a>` +
|
|
67
|
+
` · <a href="${escapeHtml(brand.studioSite)}">${escapeHtml(brand.studio)}</a></footer>`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function passwordInput({ name, label, autocomplete, minLength, autofocus }) {
|
|
72
|
+
const min = minLength > 0 ? ` minlength="${escapeHtml(Number(minLength))}"` : "";
|
|
73
|
+
return (
|
|
74
|
+
`<label>${escapeHtml(label)}` +
|
|
75
|
+
`<input type="password" name="${escapeHtml(name)}" autocomplete="${escapeHtml(autocomplete)}"` +
|
|
76
|
+
`${min} spellcheck="false" autocapitalize="off" autocorrect="off" dir="ltr" required` +
|
|
77
|
+
`${autofocus ? " autofocus" : ""}>` +
|
|
78
|
+
`</label>`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function loginBody({ brandName, error }) {
|
|
83
|
+
return (
|
|
84
|
+
`<h1>${escapeHtml(brandName)}</h1>` +
|
|
85
|
+
`<p class="muted">Sign in to manage your ${escapeHtml(brandName)} workspace.</p>` +
|
|
86
|
+
`<form action="/login" method="post">` +
|
|
87
|
+
passwordInput({
|
|
88
|
+
name: "password",
|
|
89
|
+
label: "Control panel password",
|
|
90
|
+
autocomplete: "current-password",
|
|
91
|
+
minLength: 0,
|
|
92
|
+
autofocus: true,
|
|
93
|
+
}) +
|
|
94
|
+
`<button type="submit">Open workspace</button>` +
|
|
95
|
+
`</form>` +
|
|
96
|
+
errorBlock(error) +
|
|
97
|
+
`<p class="muted">Forgot the password? Run <code>levix reset-password</code> on the server.</p>` +
|
|
98
|
+
notice()
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function setupBody({ brandName, error, needsCode, minLength }) {
|
|
103
|
+
const code = needsCode
|
|
104
|
+
? `<label>Setup code` +
|
|
105
|
+
`<input type="text" name="code" autocomplete="off" required autofocus>` +
|
|
106
|
+
`<small>Printed in the bot's terminal. ` +
|
|
107
|
+
`It confirms you can access the server running ${escapeHtml(brandName)}.</small>` +
|
|
108
|
+
`</label>`
|
|
109
|
+
: "";
|
|
110
|
+
return (
|
|
111
|
+
`<h1>Welcome to ${escapeHtml(brandName)}</h1>` +
|
|
112
|
+
`<p class="muted">Protect the linked WhatsApp account with at least ` +
|
|
113
|
+
`${escapeHtml(Number(minLength))} characters.</p>` +
|
|
114
|
+
`<form action="/setup" method="post">` +
|
|
115
|
+
code +
|
|
116
|
+
passwordInput({
|
|
117
|
+
name: "password",
|
|
118
|
+
label: "Choose a password",
|
|
119
|
+
autocomplete: "new-password",
|
|
120
|
+
minLength,
|
|
121
|
+
autofocus: !needsCode,
|
|
122
|
+
}) +
|
|
123
|
+
passwordInput({
|
|
124
|
+
name: "confirm",
|
|
125
|
+
label: "Repeat the password",
|
|
126
|
+
autocomplete: "new-password",
|
|
127
|
+
minLength,
|
|
128
|
+
}) +
|
|
129
|
+
`<button type="submit">Create workspace</button>` +
|
|
130
|
+
`</form>` +
|
|
131
|
+
errorBlock(error) +
|
|
132
|
+
notice()
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function qrBody({ brandName }) {
|
|
137
|
+
return (
|
|
138
|
+
`<h1>${escapeHtml(brandName)}</h1>` +
|
|
139
|
+
`<p>The pairing QR code cannot be shown on this page.</p>` +
|
|
140
|
+
notice()
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function panelBody({ brandName }) {
|
|
145
|
+
return (
|
|
146
|
+
`<h1>${escapeHtml(brandName)}</h1>` +
|
|
147
|
+
`<p>You are signed in, but the panel cannot be shown.</p>` +
|
|
148
|
+
notice() +
|
|
149
|
+
`<form action="/logout" method="post"><button type="submit">Sign out</button></form>`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const PAGES = {
|
|
154
|
+
login: { title: "Sign in", body: loginBody },
|
|
155
|
+
setup: { title: "Set up", body: setupBody },
|
|
156
|
+
qr: { title: "Link WhatsApp", body: qrBody },
|
|
157
|
+
panel: { title: "Panel", body: panelBody },
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// `page` is "login", "setup", "qr" or "panel" (the signed-in `/`). Anything
|
|
161
|
+
// else renders as "panel". Options: brandName, error (English string or null),
|
|
162
|
+
// needsCode (setup), minLength (setup). The QR value is never an option.
|
|
163
|
+
function renderFallbackPage({ page, brandName = "Levix", error = null, needsCode = false, minLength = 8 } = {}) {
|
|
164
|
+
const view = PAGES[page] || PAGES.panel;
|
|
165
|
+
const body = view.body({ brandName, error, needsCode: needsCode === true, minLength });
|
|
166
|
+
return (
|
|
167
|
+
`<!doctype html>\n<html lang="en">\n<head>\n` +
|
|
168
|
+
`<meta charset="utf-8">\n` +
|
|
169
|
+
`<meta name="viewport" content="width=device-width, initial-scale=1">\n` +
|
|
170
|
+
`<meta name="robots" content="noindex">\n` +
|
|
171
|
+
`<title>${escapeHtml(brandName)} · ${escapeHtml(view.title)}</title>\n` +
|
|
172
|
+
`<style>${STYLE}</style>\n` +
|
|
173
|
+
`</head>\n<body>\n<main>${body}${credits()}</main>\n</body>\n</html>\n`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
module.exports = { escapeHtml, renderFallbackPage, MISSING_NOTICE };
|