gestalt-mobile 0.76.2 → 0.77.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.
@@ -16,8 +16,8 @@ SPDX-License-Identifier: AGPL-3.0-or-later
16
16
  <link rel="icon" href="/icons/gestalt-mobile-192.png" />
17
17
  <link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
18
18
  <title>Gestalt Mobile</title>
19
- <script type="module" crossorigin src="/assets/index-C274tOWY.js"></script>
20
- <link rel="stylesheet" crossorigin href="/assets/index-CNJK1Kvj.css">
19
+ <script type="module" crossorigin src="/assets/index-DRAAJvJ4.js"></script>
20
+ <link rel="stylesheet" crossorigin href="/assets/index-4TyJ2ZNL.css">
21
21
  </head>
22
22
  <body>
23
23
  <div id="app"></div>
@@ -25,7 +25,7 @@ export function registerReadSessionLink(app, deps) {
25
25
  if (!linked)
26
26
  return reply.code(403).send({ code: 'FILE_PREVIEW_NOT_LINKED' });
27
27
  const result = await deps.readLinkedFile(session.workspacePath, path);
28
- if (result.kind === 'available' && result.preview.kind === 'file')
28
+ if (result.kind === 'available' && result.preview.kind !== 'directory')
29
29
  return reply.send(result.preview);
30
30
  const errors = {
31
31
  missing: [404, 'FILE_PREVIEW_NOT_FOUND'],
@@ -7,6 +7,17 @@ import { copyFile, lstat, mkdir, open, readdir, realpath, rename, rm, stat, writ
7
7
  import { randomUUID } from 'node:crypto';
8
8
  import { constants } from 'node:fs';
9
9
  import { basename, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
10
+ const textPreviewLimit = 1024 * 1024;
11
+ const imagePreviewLimit = 10 * 1024 * 1024;
12
+ const pngSignature = Buffer.from('89504e470d0a1a0a', 'hex');
13
+ const jpegSignature = Buffer.from('ffd8ff', 'hex');
14
+ function previewImageType(bytes) {
15
+ if (bytes.subarray(0, pngSignature.length).equals(pngSignature))
16
+ return 'image/png';
17
+ if (bytes.subarray(0, jpegSignature.length).equals(jpegSignature))
18
+ return 'image/jpeg';
19
+ return undefined;
20
+ }
10
21
  /** Lists exactly one directory; symlinks are represented but never followed. */
11
22
  export class FilesystemWorkspaceFiles {
12
23
  filesystem;
@@ -153,28 +164,48 @@ export class FilesystemWorkspaceFiles {
153
164
  return { kind: 'available', preview: { kind: 'directory', path } };
154
165
  if (!metadata.isFile())
155
166
  return { kind: 'unsupported' };
156
- const limit = 1024 * 1024;
157
- if (metadata.size > limit)
167
+ if (metadata.size > imagePreviewLimit)
158
168
  return { kind: 'too-large' };
159
- const buffer = Buffer.alloc(limit + 1);
169
+ const chunks = [];
170
+ let mediaType;
160
171
  let size = 0;
161
- while (size < buffer.length) {
162
- const read = await handle.read(buffer, size, buffer.length - size, size);
163
- if (!read.bytesRead)
164
- break;
165
- size += read.bytesRead;
172
+ for await (const chunk of handle.createReadStream({
173
+ autoClose: false,
174
+ end: imagePreviewLimit,
175
+ })) {
176
+ if (chunks.length === 0)
177
+ mediaType = previewImageType(chunk);
178
+ size += chunk.length;
179
+ const limit = mediaType ? imagePreviewLimit : textPreviewLimit;
180
+ if (Math.max(metadata.size, size) > limit)
181
+ return { kind: 'too-large' };
182
+ chunks.push(chunk);
166
183
  }
167
- if (size > limit)
168
- return { kind: 'too-large' };
169
184
  if (!(await stableAnchor(root, parentPath, parent.path)) ||
170
185
  !within(root, await realpath(procPath(handle.fd))))
171
186
  return { kind: 'unreadable' };
172
- const bytes = buffer.subarray(0, size);
187
+ const bytes = Buffer.concat(chunks, size);
188
+ if (mediaType) {
189
+ return {
190
+ kind: 'available',
191
+ preview: { kind: 'image', path, size, mediaType, base64: bytes.toString('base64') },
192
+ };
193
+ }
173
194
  if (bytes.includes(0))
174
195
  return { kind: 'unsupported' };
175
196
  try {
176
197
  const content = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
177
- return { kind: 'available', preview: { kind: 'file', path, content, size } };
198
+ const hasUtf8Bom = bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf;
199
+ return {
200
+ kind: 'available',
201
+ preview: {
202
+ kind: 'file',
203
+ path,
204
+ content,
205
+ size,
206
+ ...(hasUtf8Bom ? { hasUtf8Bom: true } : {}),
207
+ },
208
+ };
178
209
  }
179
210
  catch {
180
211
  return { kind: 'unsupported' };
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (C) 2026 Dyne.org foundation
3
+ * Designed by Denis Roio <jaromil@dyne.org>
4
+ * SPDX-License-Identifier: AGPL-3.0-or-later
5
+ */
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.76.2",
3
+ "version": "0.77.0",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",