odant-work 1.0.102 → 1.0.103

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.
@@ -53,6 +53,9 @@ export class $user extends $class {
53
53
  /** Быстрое включение/отключение пользователя супер-админом (BOSS корня WORK `/`). */
54
54
  async set_enabled(params = {}) {
55
55
  await globalThis.WORK.assertAccess(params, $class.ACCESS_LEVEL.BOSS);
56
+ await this.init;
57
+ if (this.DATA?.usersContainer === true)
58
+ throw new Error('Нельзя отключить общий раздел пользователей');
56
59
  const nextEnabled = !(params.enabled === false || params.enabled === 'false' || params.enabled === 0 || params.enabled === '0');
57
60
  if (!nextEnabled && params?.session?.uid && params.session.uid === this.id)
58
61
  throw new Error('Нельзя отключить собственную учётную запись');
@@ -98,6 +101,48 @@ export class $user extends $class {
98
101
  return { enabled: nextEnabled };
99
102
  }
100
103
 
104
+ async writeOwnSettings(patch = {}) {
105
+ await this.init;
106
+ const metaDir = this.meta_folder?.real_dir;
107
+ if (!metaDir)
108
+ throw new Error('Не найдена папка профиля');
109
+ const ownFile = path.join(metaDir, 'class.js');
110
+ let ownObj = {};
111
+ if (fs.existsSync(ownFile)) {
112
+ try {
113
+ ownObj = (await this.constructor.importScript(fs.readFileSync(ownFile, 'utf-8'), this.path)) || {};
114
+ }
115
+ catch { ownObj = {}; }
116
+ }
117
+ const cur = (ownObj.settings && typeof ownObj.settings === 'object' && !Array.isArray(ownObj.settings))
118
+ ? { ...ownObj.settings }
119
+ : {};
120
+ if ('chatSound' in patch)
121
+ cur.chatSound = patch.chatSound !== false;
122
+ if ('aiModel' in patch)
123
+ cur.aiModel = typeof patch.aiModel === 'string' ? patch.aiModel.trim().slice(0, 512) : '';
124
+ for (const [k, v] of Object.entries(patch)) {
125
+ if (k === 'chatSound' || k === 'aiModel' || k === '__proto__' || k === 'constructor' || k === 'prototype')
126
+ continue;
127
+ if (!/^[a-zA-Z0-9_-]{1,64}$/.test(k))
128
+ continue;
129
+ if (v === null || v === undefined)
130
+ delete cur[k];
131
+ else if (typeof v === 'boolean' || typeof v === 'number' || typeof v === 'string')
132
+ cur[k] = typeof v === 'string' ? v.slice(0, 1024) : v;
133
+ }
134
+ const nextSettings = { chatSound: cur.chatSound !== false, aiModel: cur.aiModel || '', ...cur };
135
+ ownObj.settings = nextSettings;
136
+ const post = 'export default ' + this.constructor.toScript(ownObj) + '\n';
137
+ await fs.promises.mkdir(metaDir, { recursive: true });
138
+ await fs.promises.writeFile(ownFile, post, 'utf8');
139
+ this.reset();
140
+ await this.init;
141
+ if (this.DATA)
142
+ this.DATA.settings = nextSettings;
143
+ return nextSettings;
144
+ }
145
+
101
146
  async allowAccess(params) {
102
147
  await this.init;
103
148
  if (this.DATA?.usersContainer === true)
package/start.bat ADDED
@@ -0,0 +1,25 @@
1
+ @echo off
2
+ setlocal
3
+ set "WORK_DIR=%~dp0"
4
+ if "%WORK_DIR:~-1%"=="\" set "WORK_DIR=%WORK_DIR:~0,-1%"
5
+ pushd "%WORK_DIR%" >nul
6
+
7
+ where node >nul 2>nul
8
+ if errorlevel 1 (
9
+ echo [WORK] Node.js не найден в PATH. Установите Node.js 22+ и повторите запуск.
10
+ popd >nul
11
+ exit /b 1
12
+ )
13
+
14
+ set "WD_SCRIPT=%WORK_DIR%\scripts\watchdog.mjs"
15
+ if not exist "%WD_SCRIPT%" set "WD_SCRIPT=%WORK_DIR%\node_modules\odant-work\scripts\watchdog.mjs"
16
+ if not exist "%WD_SCRIPT%" (
17
+ echo [WORK] Не найден scripts\watchdog.mjs
18
+ popd >nul
19
+ exit /b 1
20
+ )
21
+
22
+ node "%WD_SCRIPT%" --start "--root=%WORK_DIR%"
23
+ set "RC=%ERRORLEVEL%"
24
+ popd >nul
25
+ exit /b %RC%
package/start.sh ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env sh
2
+ set -eu
3
+ WORK_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
4
+ cd "$WORK_DIR"
5
+
6
+ if ! command -v node >/dev/null 2>&1; then
7
+ echo "[WORK] Node.js не найден в PATH." >&2
8
+ exit 1
9
+ fi
10
+
11
+ if [ -d /run/systemd/system ] && command -v systemctl >/dev/null 2>&1; then
12
+ if [ -f /etc/systemd/system/odant-work.service ] && [ "$(id -u)" -eq 0 ]; then
13
+ systemctl start odant-work
14
+ exit 0
15
+ fi
16
+ if [ -f "$HOME/.config/systemd/user/odant-work.service" ]; then
17
+ systemctl --user start odant-work
18
+ exit 0
19
+ fi
20
+ fi
21
+
22
+ WD_SCRIPT="$WORK_DIR/scripts/watchdog.mjs"
23
+ if [ ! -f "$WD_SCRIPT" ]; then
24
+ WD_SCRIPT="$WORK_DIR/node_modules/odant-work/scripts/watchdog.mjs"
25
+ fi
26
+
27
+ exec node "$WD_SCRIPT" --start "--root=$WORK_DIR"
package/stop.bat ADDED
@@ -0,0 +1,25 @@
1
+ @echo off
2
+ setlocal
3
+ set "WORK_DIR=%~dp0"
4
+ if "%WORK_DIR:~-1%"=="\" set "WORK_DIR=%WORK_DIR:~0,-1%"
5
+ pushd "%WORK_DIR%" >nul
6
+
7
+ where node >nul 2>nul
8
+ if errorlevel 1 (
9
+ echo [WORK] Node.js не найден в PATH.
10
+ popd >nul
11
+ exit /b 1
12
+ )
13
+
14
+ set "WD_SCRIPT=%WORK_DIR%\scripts\watchdog.mjs"
15
+ if not exist "%WD_SCRIPT%" set "WD_SCRIPT=%WORK_DIR%\node_modules\odant-work\scripts\watchdog.mjs"
16
+ if not exist "%WD_SCRIPT%" (
17
+ echo [WORK] Не найден scripts\watchdog.mjs
18
+ popd >nul
19
+ exit /b 1
20
+ )
21
+
22
+ node "%WD_SCRIPT%" --stop "--root=%WORK_DIR%"
23
+ set "RC=%ERRORLEVEL%"
24
+ popd >nul
25
+ exit /b %RC%
package/stop.sh ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env sh
2
+ set -eu
3
+ WORK_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
4
+ cd "$WORK_DIR"
5
+
6
+ if ! command -v node >/dev/null 2>&1; then
7
+ echo "[WORK] Node.js не найден в PATH." >&2
8
+ exit 1
9
+ fi
10
+
11
+ WD_SCRIPT="$WORK_DIR/scripts/watchdog.mjs"
12
+ if [ ! -f "$WD_SCRIPT" ]; then
13
+ WD_SCRIPT="$WORK_DIR/node_modules/odant-work/scripts/watchdog.mjs"
14
+ fi
15
+
16
+ exec node "$WD_SCRIPT" --stop "--root=$WORK_DIR"
package/sw.js CHANGED
@@ -131,9 +131,10 @@
131
131
  // по ней уже лишнее — закрываем, даже если оно висело с requireInteraction.
132
132
  self.addEventListener('message', async (event) => {
133
133
  const msg = event.data || {};
134
- if (msg.type !== 'work:task-visible' || !msg.path)
134
+ const p = msg.path || msg.task;
135
+ if (msg.type !== 'work:task-visible' || !p)
135
136
  return;
136
- const tag = 'task:' + String(msg.path);
137
+ const tag = 'task:' + String(p);
137
138
  delete pushHandlers[tag];
138
139
  try {
139
140
  const list = await self.registration.getNotifications({ tag });
@@ -314,15 +315,6 @@ const OFFLINE_PAGE = `<!DOCTYPE html><html lang="ru"><head><meta charset="utf-8"
314
315
  // задача открыта в ленте чата/вкладкой — форма на экране отвечает сама
315
316
  if (await taskOnScreen(taskPath, wins))
316
317
  return;
317
- const target = data.data?.url && new URL(data.data.url, self.location.origin).pathname;
318
- const isViewingExplorer = c => {
319
- if (c.visibilityState !== 'visible' || !c.focused)
320
- return false;
321
- const p = new URL(c.url).pathname;
322
- return p === target || p === '/' || p === '/index.html' || p.startsWith('/~/handlers/pages/explorer');
323
- };
324
- if (wins.some(isViewingExplorer))
325
- return;
326
318
  // 9.7: ожидающее разрешение — кнопки «Разрешить/Отклонить» прямо в уведомлении:
327
319
  // подтверждение уходит на сервер (POST file?approve — те же права, что в интерфейсе),
328
320
  // без кнопок (вопрос/прочее) — клик открывает задачу, как раньше