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.
- package/README.md +2 -1
- package/dist/client/assets/index-4TyJ2ZNL.css +1 -0
- package/dist/client/assets/index-DRAAJvJ4.js +184 -0
- package/dist/client/index.html +2 -2
- package/dist/server/server/features/files/read-session-link/endpoint.js +1 -1
- package/dist/server/server/platform/filesystem/filesystem-workspace-files.js +43 -12
- package/dist/server/shared/contracts/file-preview.js +6 -0
- package/package.json +1 -1
- package/dist/client/assets/index-C274tOWY.js +0 -184
- package/dist/client/assets/index-CNJK1Kvj.css +0 -1
package/dist/client/index.html
CHANGED
|
@@ -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-
|
|
20
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
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
|
|
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
|
-
|
|
157
|
-
if (metadata.size > limit)
|
|
167
|
+
if (metadata.size > imagePreviewLimit)
|
|
158
168
|
return { kind: 'too-large' };
|
|
159
|
-
const
|
|
169
|
+
const chunks = [];
|
|
170
|
+
let mediaType;
|
|
160
171
|
let size = 0;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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 =
|
|
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
|
-
|
|
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' };
|