Skip to content

Commit 686f4a6

Browse files
MarcoDotIOclaude
andcommitted
fix(server): image attachments report their size when the T3 home is behind a symlink
Image dimensions for attachments were read through openMediaFile, which refuses any path that is not already canonical. The attachment path is built from the configured attachments directory without resolving links, so a T3 home reached through a symlink always returned no dimensions. Resolve the attachment path first, as the workspace and media callers do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 96ffd7a commit 686f4a6

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎apps/server/src/assets/AssetAccess.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,33 @@ describe("AssetAccess", () => {
850850
}).pipe(Effect.provide(layerTest)),
851851
);
852852

853+
it.effect.skipIf(!symlinksSupported)(
854+
"reports image attachment dimensions when the attachments directory is a symlink",
855+
() =>
856+
Effect.gen(function* () {
857+
const config = yield* ServerConfig.ServerConfig;
858+
const fs = yield* FileSystem.FileSystem;
859+
const path = yield* Path.Path;
860+
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-attachments-link-" });
861+
const realAttachmentsDir = path.join(root, "real");
862+
const linkedAttachmentsDir = path.join(root, "linked");
863+
yield* fs.makeDirectory(realAttachmentsDir);
864+
yield* fs.symlink(realAttachmentsDir, linkedAttachmentsDir);
865+
const attachmentId = "thread-1-00000000-0000-4000-8000-000000000041";
866+
yield* fs.writeFile(path.join(realAttachmentsDir, `${attachmentId}.png`), screenshotPng);
867+
868+
const result = yield* issueAssetUrl({
869+
resource: { _tag: "attachment", attachmentId },
870+
}).pipe(
871+
Effect.provideService(ServerConfig.ServerConfig, {
872+
...config,
873+
attachmentsDir: linkedAttachmentsDir,
874+
}),
875+
);
876+
expect(result.imageDimensions).toEqual({ width: 390, height: 844 });
877+
}).pipe(Effect.provide(layerTest)),
878+
);
879+
853880
it.effect("keeps inline requests for other attachment types as downloads", () =>
854881
Effect.gen(function* () {
855882
const config = yield* ServerConfig.ServerConfig;

‎apps/server/src/assets/AssetAccess.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,14 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
639639
? inlinePreviewMimeTypeForExtension(extension)
640640
: undefined;
641641
if (!isGenericFile) {
642-
imageDimensions = yield* readImageDimensionsFromHeader(attachmentPath);
642+
// openMediaFile refuses a non-canonical path, and the attachments
643+
// directory can sit behind a symlink when the T3 home does.
644+
const canonicalAttachmentPath = yield* fileSystem
645+
.realPath(attachmentPath)
646+
.pipe(Effect.orElseSucceed(() => null));
647+
if (canonicalAttachmentPath !== null) {
648+
imageDimensions = yield* readImageDimensionsFromHeader(canonicalAttachmentPath);
649+
}
643650
}
644651
claims = {
645652
version: 1,

0 commit comments

Comments
 (0)