Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(server): report image dimensions with signed asset URLs #10198

Mergedjuliusmarmingemerged 4 commits intomain fromrefs/pull/10198/headmerged by juliusmarminge View on GitHub

Showing 8 changed files with 108 additions and 5 deletions (loading 5).

x
0 of 8 viewed, 8 left
24 additions and 0 deletionsapps/server/src/assets/AssetAccess.test.tsModified
View file
@@ -83,6 +83,30 @@
}).pipe(Effect.provide(testLayer)),
);
​
+ it.effect("reports pixel dimensions from an image header and nothing for other files", () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-dimensions-" });
+ const png = Uint8Array.from([
+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 13, 0x49, 0x48, 0x44, 0x52, 0, 0,
+ 0x06, 0x40, 0, 0, 0x03, 0x84,
+ ]);
+ yield* fs.writeFile(path.join(root, "shot.png"), png);
+ yield* fs.writeFileString(path.join(root, "clip.mp4"), "video");
+ yield* fs.writeFileString(path.join(root, "broken.png"), "not a png");
+ const issue = (name: string) =>
+ issueAssetUrl({
+ resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: name },
+ workspaceRoot: root,
+ });
+​
+ expect((yield* issue("shot.png")).imageDimensions).toEqual({ width: 1600, height: 900 });
+ expect((yield* issue("clip.mp4")).imageDimensions).toBeUndefined();
+ expect((yield* issue("broken.png")).imageDimensions).toBeUndefined();
+ }).pipe(Effect.provide(testLayer)),
+ );
+​
it.effect("resolves relative media paths from the thread workspace, including outside it", () =>
Effect.gen(function* () {