levix-bot 4.3.1 → 4.5.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.
Files changed (47) hide show
  1. package/README.md +4 -2
  2. package/package.json +1 -1
  3. package/public/dashboard/assets/index-COI8zgqa.css +2 -0
  4. package/public/dashboard/assets/index-IZMBuNAZ.js +505 -0
  5. package/public/dashboard/index.html +2 -2
  6. package/public/dashboard.css +32 -0
  7. package/scheduler.cjs +66 -7
  8. package/src/bootstrap/panel.js +16 -4
  9. package/src/commands/pack.cjs +159 -0
  10. package/src/commands/packs.cjs +47 -0
  11. package/src/commands/send.cjs +1 -18
  12. package/src/commands/sticker.cjs +77 -232
  13. package/src/commands/stickers.cjs +100 -0
  14. package/src/commands/toimage.cjs +88 -0
  15. package/src/config/defaults.cjs +5 -0
  16. package/src/config/settings.cjs +10 -0
  17. package/src/core/events.js +15 -1
  18. package/src/core/session.js +7 -0
  19. package/src/db/db.cjs +387 -0
  20. package/src/db/store.cjs +746 -24
  21. package/src/handlers/command.handler.js +4 -0
  22. package/src/panel/feedback.cjs +43 -14
  23. package/src/routes/dashboard.api.esm.js +172 -20
  24. package/src/routes/stickers.api.esm.js +570 -0
  25. package/src/services/llmDiscovery.cjs +32 -10
  26. package/src/stickers/errors.cjs +239 -0
  27. package/src/stickers/ffmpeg.cjs +133 -0
  28. package/src/stickers/jobs.cjs +183 -0
  29. package/src/stickers/library.cjs +712 -0
  30. package/src/stickers/limits.cjs +60 -0
  31. package/src/stickers/media.cjs +748 -0
  32. package/src/stickers/options.cjs +128 -0
  33. package/src/stickers/owner.cjs +103 -0
  34. package/src/stickers/studio.cjs +473 -0
  35. package/src/stickers/uploads.cjs +263 -0
  36. package/src/stickers/webp.cjs +231 -0
  37. package/src/stickers/zip.cjs +107 -0
  38. package/src/utils/messageContent.cjs +30 -4
  39. package/src/utils/multipart.esm.js +81 -0
  40. package/src/utils/recurrence.cjs +189 -30
  41. package/src/utils/stickerBot.cjs +84 -0
  42. package/src/utils/storage.cjs +3 -0
  43. package/src/utils/storage.esm.js +3 -0
  44. package/views/login.ejs +39 -3
  45. package/views/setup.ejs +21 -0
  46. package/public/dashboard/assets/index-B6RhYFIy.js +0 -446
  47. package/public/dashboard/assets/index-vEwOcxiH.css +0 -2
@@ -0,0 +1,81 @@
1
+ // Minimal multipart/form-data reader for the two panel routes that carry a
2
+ // file (the feedback attachment, scheduled-message media).
3
+ //
4
+ // Node ships undici's Request/FormData/File, so there is no parser dependency
5
+ // to install. undici buffers file parts in memory, so the cap has to bite
6
+ // before that buffering finishes: a declared Content-Length is refused up
7
+ // front, and a chunked body (the Android bridge streams one, with no length)
8
+ // is counted as it arrives and cut off at the same cap.
9
+
10
+ const MAX_TOTAL_BYTES = 26 * 1024 * 1024; // a 20 MB file + fields + MIME overhead
11
+
12
+ export class MultipartError extends Error {}
13
+
14
+ /**
15
+ * Parse a multipart request body.
16
+ *
17
+ * @param {import("express").Request} req
18
+ * @param {{ maxFileSize?: number }} [options]
19
+ * @returns {Promise<{ fields: Record<string, string>, file: File | null } | null>}
20
+ * null when the request is not multipart — the JSON parser owns those.
21
+ */
22
+ export async function readMultipartForm(req, options = {}) {
23
+ const contentType = String(req.headers["content-type"] || "");
24
+ if (!contentType.toLowerCase().startsWith("multipart/form-data")) return null;
25
+
26
+ const declared = Number(req.headers["content-length"] || 0);
27
+ if (declared > MAX_TOTAL_BYTES) {
28
+ throw new MultipartError("Attachment is too large");
29
+ }
30
+
31
+ let tooLarge = false;
32
+ async function* capped() {
33
+ let received = 0;
34
+ for await (const chunk of req) {
35
+ received += chunk.length;
36
+ if (received > MAX_TOTAL_BYTES) {
37
+ tooLarge = true;
38
+ throw new MultipartError("Attachment is too large");
39
+ }
40
+ yield chunk;
41
+ }
42
+ }
43
+
44
+ const request = new Request("http://localhost/", {
45
+ method: "POST",
46
+ headers: { "content-type": contentType },
47
+ body: capped(),
48
+ duplex: "half",
49
+ });
50
+ let form;
51
+ try {
52
+ form = await request.formData();
53
+ } catch {
54
+ if (tooLarge) throw new MultipartError("Attachment is too large");
55
+ // A body that is not really multipart (the browser builds these, so this
56
+ // is a broken client, not an operator error) is refused, not crashed on.
57
+ throw new MultipartError("Could not read the upload");
58
+ }
59
+
60
+ const fields = {};
61
+ let file = null;
62
+ const maxFileSize = options.maxFileSize ?? 0;
63
+ for (const [key, value] of form.entries()) {
64
+ if (typeof value === "string") {
65
+ fields[key] = value;
66
+ continue;
67
+ }
68
+ if (maxFileSize && value.size > maxFileSize) {
69
+ throw new MultipartError("Attachment is too large");
70
+ }
71
+ // The panel forms carry exactly one file each; a later one replaces it.
72
+ file = value;
73
+ }
74
+ return { fields, file };
75
+ }
76
+
77
+ /** Read the parsed file part into a Buffer for forwarding. */
78
+ export async function fileToBuffer(file) {
79
+ if (!file) return null;
80
+ return Buffer.from(await file.arrayBuffer());
81
+ }
@@ -45,6 +45,9 @@ const DAY_ALIASES = new Map([
45
45
  ]);
46
46
 
47
47
  const WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
48
+ const WEEKDAYS_AR = ["الأحد", "الاثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت"];
49
+ // */N restarts at midnight; only these keep a gap of N across the day boundary.
50
+ const HOURLY_INTERVALS = [1, 2, 3, 4, 6, 8, 12];
48
51
 
49
52
  function normalizeDay(value) {
50
53
  return String(value ?? "")
@@ -112,46 +115,202 @@ function parseRecurringArgs(args) {
112
115
  return { error: type ? "type" : "usage" };
113
116
  }
114
117
 
115
- function describeScheduledJob(job, timezone) {
116
- if (job.type === "recurring") {
117
- const parts = String(job.cronString ?? "")
118
- .trim()
119
- .split(/\s+/);
120
- if (parts.length === 5) {
121
- const [minuteText, hourText, dayOfMonth, month, dayText] = parts;
122
- const minute = Number(minuteText);
123
- const hour = Number(hourText);
124
- const validTime =
125
- /^\d+$/.test(minuteText) &&
126
- /^\d+$/.test(hourText) &&
127
- minute >= 0 &&
128
- minute <= 59 &&
129
- hour >= 0 &&
130
- hour <= 23;
131
-
132
- if (validTime && dayOfMonth === "*" && month === "*") {
133
- const time = `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
134
- if (dayText === "*") return `Daily at ${time} (${timezone})`;
135
-
136
- const day = parseDayOfWeek(dayText);
137
- if (day !== null) return `Every ${WEEKDAYS[day]} at ${time} (${timezone})`;
118
+ function uniqueSortedDays(values) {
119
+ if (!Array.isArray(values)) return { error: "weekdays" };
120
+ const days = [];
121
+ for (const value of values) {
122
+ const day = Number(value);
123
+ if (!Number.isInteger(day) || day < 0 || day > 6) return { error: "weekdays" };
124
+ if (!days.includes(day)) days.push(day);
125
+ }
126
+ days.sort((a, b) => a - b);
127
+ return { days };
128
+ }
129
+
130
+ /**
131
+ * Turn a panel recurrence object into a 5-field cron string.
132
+ * The client never supplies the cron — this is the only builder.
133
+ *
134
+ * { kind: "daily"|"weekly"|"monthly"|"hourly", time: "HH:MM",
135
+ * weekdays?: number[], dayOfMonth?: number, everyHours?: number }
136
+ */
137
+ function recurrenceToCron(recurrence) {
138
+ if (!recurrence || typeof recurrence !== "object") return { error: "recurrence" };
139
+ const kind = String(recurrence.kind || "")
140
+ .trim()
141
+ .toLowerCase();
142
+ const time = parseTime(recurrence.time);
143
+
144
+ if (kind === "daily") {
145
+ if (!time) return { error: "time" };
146
+ return {
147
+ kind,
148
+ time: time.text,
149
+ cronString: `${time.minute} ${time.hour} * * *`,
150
+ };
151
+ }
152
+
153
+ if (kind === "weekly") {
154
+ if (!time) return { error: "time" };
155
+ const parsed = uniqueSortedDays(recurrence.weekdays);
156
+ if (parsed.error) return parsed;
157
+ if (!parsed.days.length) return { error: "weekdays" };
158
+ return {
159
+ kind,
160
+ time: time.text,
161
+ weekdays: parsed.days,
162
+ cronString: `${time.minute} ${time.hour} * * ${parsed.days.join(",")}`,
163
+ };
164
+ }
165
+
166
+ if (kind === "monthly") {
167
+ if (!time) return { error: "time" };
168
+ const day = Number(recurrence.dayOfMonth);
169
+ if (!Number.isInteger(day) || day < 1 || day > 31) return { error: "dayOfMonth" };
170
+ return {
171
+ kind,
172
+ time: time.text,
173
+ dayOfMonth: day,
174
+ cronString: `${time.minute} ${time.hour} ${day} * *`,
175
+ };
176
+ }
177
+
178
+ if (kind === "hourly") {
179
+ const n = Number(recurrence.everyHours);
180
+ if (!Number.isInteger(n) || !HOURLY_INTERVALS.includes(n)) return { error: "everyHours" };
181
+ if (!time) return { error: "time" };
182
+ return {
183
+ kind,
184
+ everyHours: n,
185
+ minute: time.minute,
186
+ time: time.text,
187
+ cronString: `${time.minute} */${n} * * *`,
188
+ };
189
+ }
190
+
191
+ return { error: "kind" };
192
+ }
193
+
194
+ function recurrenceErrorMessage(error) {
195
+ switch (error) {
196
+ case "time":
197
+ return "Invalid time";
198
+ case "weekdays":
199
+ return "Select at least one weekday";
200
+ case "dayOfMonth":
201
+ return "Day of month must be between 1 and 31";
202
+ case "everyHours":
203
+ return "Hours must be 1, 2, 3, 4, 6, 8 or 12";
204
+ default:
205
+ return "Invalid recurrence";
206
+ }
207
+ }
208
+
209
+ function joinWeekdayNames(days, lang) {
210
+ const names = days.map((day) => (lang === "ar" ? WEEKDAYS_AR[day] : WEEKDAYS[day]));
211
+ if (lang === "ar") return names.join(" و");
212
+ if (names.length === 1) return names[0];
213
+ if (names.length === 2) return `${names[0]} and ${names[1]}`;
214
+ return `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
215
+ }
216
+
217
+ function withZone(text, timezone) {
218
+ return `${text} (${timezone})`;
219
+ }
220
+
221
+ function arabicEveryHours(n) {
222
+ if (n === 1) return "كل ساعة";
223
+ if (n === 2) return "كل ساعتين";
224
+ if (n >= 3 && n <= 10) return `كل ${n} ساعات`;
225
+ return `كل ${n} ساعة`;
226
+ }
227
+
228
+ function describeRecurringCron(cronString, timezone, lang) {
229
+ const ar = lang === "ar";
230
+ const fallback = withZone(cronString || (ar ? "تكرار غير معروف" : "Unknown recurrence"), timezone);
231
+ const parts = String(cronString ?? "")
232
+ .trim()
233
+ .split(/\s+/);
234
+ if (parts.length !== 5) return fallback;
235
+
236
+ const [minuteText, hourText, dayOfMonth, month, dayText] = parts;
237
+ const minute = Number(minuteText);
238
+ const hour = Number(hourText);
239
+ const validMinute = /^\d+$/.test(minuteText) && minute >= 0 && minute <= 59;
240
+ const validHour = /^\d+$/.test(hourText) && hour >= 0 && hour <= 23;
241
+
242
+ const everyHours = /^\*\/(\d+)$/.exec(hourText);
243
+ if (
244
+ validMinute &&
245
+ everyHours &&
246
+ dayOfMonth === "*" &&
247
+ month === "*" &&
248
+ dayText === "*"
249
+ ) {
250
+ const n = Number(everyHours[1]);
251
+ if (n >= 1 && n <= 12) {
252
+ if (ar) {
253
+ return withZone(`${arabicEveryHours(n)} عند الدقيقة ${minute}`, timezone);
138
254
  }
255
+ return withZone(
256
+ n === 1 ? `Every hour at minute ${minute}` : `Every ${n} hours at minute ${minute}`,
257
+ timezone,
258
+ );
259
+ }
260
+ }
261
+
262
+ if (!validMinute || !validHour || month !== "*") return fallback;
263
+ const time = `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
264
+
265
+ if (dayOfMonth !== "*" && dayText === "*") {
266
+ const day = Number(dayOfMonth);
267
+ if (/^\d+$/.test(dayOfMonth) && day >= 1 && day <= 31) {
268
+ return withZone(
269
+ ar ? `كل شهر في اليوم ${day} الساعة ${time}` : `Every month on day ${day} at ${time}`,
270
+ timezone,
271
+ );
139
272
  }
273
+ return fallback;
274
+ }
275
+
276
+ if (dayOfMonth !== "*") return fallback;
277
+
278
+ if (dayText === "*") {
279
+ return withZone(ar ? `يومياً الساعة ${time}` : `Daily at ${time}`, timezone);
280
+ }
140
281
 
141
- return `${job.cronString || "Unknown recurrence"} (${timezone})`;
282
+ const days = dayText.split(",").map((token) => parseDayOfWeek(token.trim()));
283
+ if (!days.length || days.some((day) => day === null)) return fallback;
284
+ const unique = [...new Set(days)].sort((a, b) => a - b);
285
+ const names = joinWeekdayNames(unique, ar ? "ar" : "en");
286
+ if (ar) return withZone(`كل يوم ${names} الساعة ${time}`, timezone);
287
+ if (unique.length === 1) return withZone(`Every ${names} at ${time}`, timezone);
288
+ return withZone(`Every ${names} at ${time}`, timezone);
289
+ }
290
+
291
+ function describeScheduledJob(job, timezone, lang = "en") {
292
+ const ar = lang === "ar";
293
+ if (job.type === "recurring") {
294
+ return describeRecurringCron(job.cronString, timezone, ar ? "ar" : "en");
142
295
  }
143
296
 
144
297
  const date = new Date(job.date);
145
- if (!Number.isFinite(date.getTime())) return "Invalid date";
146
- return `${new Intl.DateTimeFormat("en-GB", {
147
- dateStyle: "medium",
148
- timeStyle: "short",
149
- timeZone: timezone,
150
- }).format(date)} (${timezone})`;
298
+ if (!Number.isFinite(date.getTime())) return ar ? "تاريخ غير صالح" : "Invalid date";
299
+ return withZone(
300
+ new Intl.DateTimeFormat(ar ? "ar-EG" : "en-GB", {
301
+ dateStyle: "medium",
302
+ timeStyle: "short",
303
+ timeZone: timezone,
304
+ }).format(date),
305
+ timezone,
306
+ );
151
307
  }
152
308
 
153
309
  module.exports = {
154
310
  parseDayOfWeek,
155
311
  parseRecurringArgs,
312
+ parseTime,
313
+ recurrenceToCron,
314
+ recurrenceErrorMessage,
156
315
  describeScheduledJob,
157
316
  };
@@ -0,0 +1,84 @@
1
+ const { downloadContentFromMessage } = require("@whiskeysockets/baileys");
2
+ const brand = require("../config/brand.cjs");
3
+ const runtimeConfig = require("../config/runtime-config.cjs");
4
+ const { downloadMedia } = require("./geminiMedia.cjs");
5
+ const { pickMedia, quotedOf } = require("./messageContent.cjs");
6
+ const media = require("../stickers/media.cjs");
7
+ const library = require("../stickers/library.cjs");
8
+ const { StickerError, isStickerError, userMessage } = require("../stickers/errors.cjs");
9
+ const { WHATSAPP_MEDIA_MAX_BYTES } = require("../stickers/limits.cjs");
10
+ const { tr } = require("./i18n.cjs");
11
+
12
+ function targetOf(msg, { quotedOnly = false } = {}) {
13
+ const quoted = quotedOf(msg);
14
+ return quotedOnly
15
+ ? quoted
16
+ ? pickMedia(quoted)
17
+ : null
18
+ : pickMedia(msg.message) || (quoted ? pickMedia(quoted) : null);
19
+ }
20
+
21
+ async function downloadTarget(target) {
22
+ if (!target) throw new StickerError("NO_MEDIA");
23
+ const size = Number(target.media?.fileLength?.toString?.() ?? target.media?.fileLength);
24
+ if (Number.isFinite(size) && size > WHATSAPP_MEDIA_MAX_BYTES) {
25
+ throw new StickerError("TOO_LARGE", { limitBytes: WHATSAPP_MEDIA_MAX_BYTES });
26
+ }
27
+ const buffer = await downloadMedia(downloadContentFromMessage, target.media, target.type);
28
+ if (buffer.length > WHATSAPP_MEDIA_MAX_BYTES) {
29
+ throw new StickerError("TOO_LARGE", { limitBytes: WHATSAPP_MEDIA_MAX_BYTES });
30
+ }
31
+ return buffer;
32
+ }
33
+
34
+ function firstPackName(owner, sticker) {
35
+ if (!sticker?.packIds?.length) return brand.name;
36
+ return library.getPack(owner, sticker.packIds[0]).pack.name;
37
+ }
38
+
39
+ function packedSticker(buffer, name = brand.name) {
40
+ return media.withStickerMetadata(buffer, { packName: name, publisher: brand.name });
41
+ }
42
+
43
+ async function sendLibrarySticker(sock, jid, owner, sticker) {
44
+ const buffer = library.readStickerFile(owner, sticker.id);
45
+ await sock.sendMessage(jid, { sticker: packedSticker(buffer, firstPackName(owner, sticker)) });
46
+ library.touch(owner, [sticker.id]);
47
+ }
48
+
49
+ function commandHint(name, args = "") {
50
+ return `${runtimeConfig.getPrefix()}${name}${args ? ` ${args}` : ""}`;
51
+ }
52
+
53
+ function countLabel(count, kind = "sticker") {
54
+ const n = Number(count);
55
+ const singular = kind === "pack" ? "pack" : "sticker";
56
+ const english = `${n} ${singular}${n === 1 ? "" : "s"}`;
57
+ if (kind === "pack") {
58
+ return tr(
59
+ english,
60
+ n === 1 ? "حزمة واحدة" : n === 2 ? "حزمتان" : n <= 10 ? `${n} حزم` : `${n} حزمة`,
61
+ );
62
+ }
63
+ return tr(
64
+ english,
65
+ n === 1 ? "ملصق واحد" : n === 2 ? "ملصقان" : n <= 10 ? `${n} ملصقات` : `${n} ملصقًا`,
66
+ );
67
+ }
68
+
69
+ function errorText(error) {
70
+ return isStickerError(error)
71
+ ? userMessage(error)
72
+ : tr("Something went wrong with the sticker.", "حدث خطأ في الملصق.");
73
+ }
74
+
75
+ module.exports = {
76
+ targetOf,
77
+ downloadTarget,
78
+ packedSticker,
79
+ firstPackName,
80
+ sendLibrarySticker,
81
+ commandHint,
82
+ countLabel,
83
+ errorText,
84
+ };
@@ -48,6 +48,8 @@ module.exports = {
48
48
  getTopForwardedMessages: store.getTopForwardedMessages,
49
49
  // User Metadata
50
50
  saveUserMetadata: store.saveUserMetadata,
51
+ rememberSavedName: store.rememberSavedName,
52
+ applyContactRecord: store.applyContactRecord,
51
53
  getUserMetadata: store.getUserMetadata,
52
54
  isUserOwner: store.isUserOwner,
53
55
  isUserBotAdmin: store.isUserBotAdmin,
@@ -59,6 +61,7 @@ module.exports = {
59
61
  storeLidPnMapping: store.storeLidPnMapping,
60
62
  storeLidPnMappings: store.storeLidPnMappings,
61
63
  getLidForPn: store.getLidForPn,
64
+ getLidsForPn: store.getLidsForPn,
62
65
  getLidsForPns: store.getLidsForPns,
63
66
  getPnForLid: store.getPnForLid,
64
67
  getAllLidMappings: store.getAllLidMappings,
@@ -55,6 +55,7 @@ export const deleteQrCode = store.deleteQrCode;
55
55
  export const storeLidPnMapping = store.storeLidPnMapping;
56
56
  export const storeLidPnMappings = store.storeLidPnMappings;
57
57
  export const getLidForPn = store.getLidForPn;
58
+ export const getLidsForPn = store.getLidsForPn;
58
59
  export const getLidsForPns = store.getLidsForPns;
59
60
  export const getPnForLid = store.getPnForLid;
60
61
  export const getAllLidMappings = store.getAllLidMappings;
@@ -66,6 +67,8 @@ export const getTopForwardedMessages = store.getTopForwardedMessages;
66
67
 
67
68
  // ===== User metadata & bot roles =====
68
69
  export const saveUserMetadata = store.saveUserMetadata;
70
+ export const rememberSavedName = store.rememberSavedName;
71
+ export const applyContactRecord = store.applyContactRecord;
69
72
  export const getUserMetadata = store.getUserMetadata;
70
73
  export const isUserOwner = store.isUserOwner;
71
74
  export const isUserBotAdmin = store.isUserBotAdmin;
package/views/login.ejs CHANGED
@@ -33,6 +33,10 @@
33
33
  <section class="gateway-panel">
34
34
  <div class="gateway-panel-inner">
35
35
  <form class="card auth-card" id="login-card" action="/login" method="post">
36
+ <button type="button" class="gateway-back-btn" id="login-back-app" hidden>
37
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
38
+ <span>Back to app</span>
39
+ </button>
36
40
  <div class="auth-head">
37
41
  <span class="eyebrow">Secure access</span>
38
42
  <h1>Welcome back</h1>
@@ -72,6 +76,10 @@
72
76
  </form>
73
77
 
74
78
  <div class="card auth-card" id="reset-card" hidden>
79
+ <button type="button" class="gateway-back-btn" id="reset-back">
80
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
81
+ <span>Back to sign in</span>
82
+ </button>
75
83
  <div class="auth-head">
76
84
  <span class="eyebrow">Password reset</span>
77
85
  <h1>Reset your password</h1>
@@ -143,9 +151,7 @@
143
151
  </form>
144
152
 
145
153
  <div class="error" id="reset-error" role="alert" hidden></div>
146
- <div class="auth-alt">
147
- <button type="button" class="link-btn" id="reset-back">Back to sign in</button>
148
- </div>
154
+
149
155
  </div>
150
156
 
151
157
  <div class="foot"><%= brand.name %> by <%= brand.developer %> · <%= brand.studio %></div>
@@ -156,6 +162,30 @@
156
162
  <script src="/gateway.js"></script>
157
163
  <script>
158
164
  (function () {
165
+ // Android app: show back-to-app buttons, localize labels
166
+ var inApp = typeof window.LevixHost !== "undefined" && typeof window.LevixHost.closePanel === "function";
167
+ if (inApp) {
168
+ var isAr = false;
169
+ try { isAr = localStorage.getItem("levix_lang") === "ar"; } catch(e) {}
170
+ var backLabel = isAr ? "العودة للتطبيق" : "Back to app";
171
+ var resetBackLabel = isAr ? "العودة لتسجيل الدخول" : "Back to sign in";
172
+ ["login-back-app"].forEach(function(id) {
173
+ var btn = document.getElementById(id);
174
+ if (btn) {
175
+ btn.hidden = false;
176
+ btn.querySelector("span").textContent = backLabel;
177
+ if (isAr) { btn.dir = "rtl"; btn.style.direction = "rtl"; }
178
+ btn.addEventListener("click", function() { window.LevixHost.closePanel(); });
179
+ }
180
+ });
181
+ var resetBackBtn = document.getElementById("reset-back");
182
+ if (resetBackBtn && isAr) {
183
+ resetBackBtn.querySelector("span").textContent = resetBackLabel;
184
+ resetBackBtn.dir = "rtl";
185
+ resetBackBtn.style.direction = "rtl";
186
+ }
187
+ }
188
+
159
189
  var loginCard = document.getElementById("login-card");
160
190
  var resetCard = document.getElementById("reset-card");
161
191
  var sendBtn = document.getElementById("reset-send");
@@ -194,6 +224,12 @@
194
224
  document.getElementById("forgot-link").addEventListener("click", showReset);
195
225
  document.getElementById("reset-back").addEventListener("click", showLogin);
196
226
 
227
+ document.addEventListener("keydown", function(e) {
228
+ if (e.key === "Escape" && !resetCard.hidden) {
229
+ showLogin();
230
+ }
231
+ });
232
+
197
233
  sendBtn.addEventListener("click", async function () {
198
234
  sendBtn.disabled = true;
199
235
  hideError();
package/views/setup.ejs CHANGED
@@ -33,6 +33,10 @@
33
33
  <section class="gateway-panel">
34
34
  <div class="gateway-panel-inner">
35
35
  <form class="card auth-card setup-card" action="/setup" method="post">
36
+ <button type="button" class="gateway-back-btn" id="setup-back-app" hidden>
37
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
38
+ <span>Back to app</span>
39
+ </button>
36
40
  <div class="auth-head">
37
41
  <span class="eyebrow">Create your workspace</span>
38
42
  <h1>Welcome to <%= brand.name %></h1>
@@ -89,5 +93,22 @@
89
93
  </main>
90
94
 
91
95
  <script src="/gateway.js"></script>
96
+ <script>
97
+ (function () {
98
+ var inApp = typeof window.LevixHost !== "undefined" && typeof window.LevixHost.closePanel === "function";
99
+ if (inApp) {
100
+ var isAr = false;
101
+ try { isAr = localStorage.getItem("levix_lang") === "ar"; } catch(e) {}
102
+ var backLabel = isAr ? "العودة للتطبيق" : "Back to app";
103
+ var btn = document.getElementById("setup-back-app");
104
+ if (btn) {
105
+ btn.hidden = false;
106
+ btn.querySelector("span").textContent = backLabel;
107
+ if (isAr) { btn.dir = "rtl"; btn.style.direction = "rtl"; }
108
+ btn.addEventListener("click", function() { window.LevixHost.closePanel(); });
109
+ }
110
+ }
111
+ })();
112
+ </script>
92
113
  </body>
93
114
  </html>