TypeScript
fix(server): image attachments report their size when the T3 home is behind a symlink (#24245)
MarcoDotIO3b066dad5c7f
diff --git a/apps/server/src/assets/AssetAccess.test.ts b/apps/server/src/assets/AssetAccess.test.tsindex 39a6e651b84..11cb490901a 100644--- a/apps/server/src/assets/AssetAccess.test.ts+++ b/apps/server/src/assets/AssetAccess.test.ts@@ -1199,6 +1199,33 @@ describe("AssetAccess", () => {}).pipe(Effect.provide(layerTest)),);+ it.effect.skipIf(!symlinksSupported)(+ "reports image attachment dimensions when the attachments directory is a symlink",+ () =>+ Effect.gen(function* () {+ const config = yield* ServerConfig.ServerConfig;+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-attachments-link-" });+ const realAttachmentsDir = path.join(root, "real");+ const linkedAttachmentsDir = path.join(root, "linked");+ yield* fs.makeDirectory(realAttachmentsDir);+ yield* fs.symlink(realAttachmentsDir, linkedAttachmentsDir);+ const attachmentId = "thread-1-00000000-0000-4000-8000-000000000041";+ yield* fs.writeFile(path.join(realAttachmentsDir, `${attachmentId}.png`), screenshotPng);++ const result = yield* issueAssetUrl({+ resource: { _tag: "attachment", attachmentId },+ }).pipe(+ Effect.provideService(ServerConfig.ServerConfig, {+ ...config,+ attachmentsDir: linkedAttachmentsDir,+ }),+ );+ expect(result.imageDimensions).toEqual({ width: 390, height: 844 });+ }).pipe(Effect.provide(layerTest)),+ );+it.effect("serves document attachments inline when a viewer requests it", () =>Effect.gen(function* () {const config = yield* ServerConfig.ServerConfig;diff --git a/apps/server/src/assets/AssetAccess.ts b/apps/server/src/assets/AssetAccess.tsindex 0ca85e6ea14..8eb78946272 100644--- a/apps/server/src/assets/AssetAccess.ts+++ b/apps/server/src/assets/AssetAccess.ts@@ -659,7 +659,10 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i? inlinePreviewMimeTypeForExtension(extension): undefined;if (!isGenericFile) {- imageDimensions = yield* readImageDimensionsFromHeader(attachmentPath);+ imageDimensions = yield* fileSystem.realPath(attachmentPath).pipe(+ Effect.flatMap(readImageDimensionsFromHeader),+ Effect.orElseSucceed(() => null),+ );}claims = {version: 1,