Skip to content

Commit 3b066da

Browse files
MarcoDotIOclaudemaria-rcks
authored
fix(server): image attachments report their size when the T3 home is behind a symlink (pingdotgg#24245)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 2c37797 commit 3b066da

2 files changed

Lines changed: 31 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
@@ -1199,6 +1199,33 @@ describe("AssetAccess", () => {
11991199
}).pipe(Effect.provide(layerTest)),
12001200
);
12011201

1202+
it.effect.skipIf(!symlinksSupported)(
1203+
"reports image attachment dimensions when the attachments directory is a symlink",
1204+
() =>
1205+
Effect.gen(function* () {
1206+
const config = yield* ServerConfig.ServerConfig;
1207+
const fs = yield* FileSystem.FileSystem;
1208+
const path = yield* Path.Path;
1209+
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-attachments-link-" });
1210+
const realAttachmentsDir = path.join(root, "real");
1211+
const linkedAttachmentsDir = path.join(root, "linked");
1212+
yield* fs.makeDirectory(realAttachmentsDir);
1213+
yield* fs.symlink(realAttachmentsDir, linkedAttachmentsDir);
1214+
const attachmentId = "thread-1-00000000-0000-4000-8000-000000000041";
1215+
yield* fs.writeFile(path.join(realAttachmentsDir, `${attachmentId}.png`), screenshotPng);
1216+
1217+
const result = yield* issueAssetUrl({
1218+
resource: { _tag: "attachment", attachmentId },
1219+
}).pipe(
1220+
Effect.provideService(ServerConfig.ServerConfig, {
1221+
...config,
1222+
attachmentsDir: linkedAttachmentsDir,
1223+
}),
1224+
);
1225+
expect(result.imageDimensions).toEqual({ width: 390, height: 844 });
1226+
}).pipe(Effect.provide(layerTest)),
1227+
);
1228+
12021229
it.effect("serves document attachments inline when a viewer requests it", () =>
12031230
Effect.gen(function* () {
12041231
const config = yield* ServerConfig.ServerConfig;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,10 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
659659
? inlinePreviewMimeTypeForExtension(extension)
660660
: undefined;
661661
if (!isGenericFile) {
662-
imageDimensions = yield* readImageDimensionsFromHeader(attachmentPath);
662+
imageDimensions = yield* fileSystem.realPath(attachmentPath).pipe(
663+
Effect.flatMap(readImageDimensionsFromHeader),
664+
Effect.orElseSucceed(() => null),
665+
);
663666
}
664667
claims = {
665668
version: 1,

0 commit comments

Comments
 (0)