Skip to content

Commit 9bb9510

Browse files
fix(server): preserve absolute draft symlink previews
1 parent 5e2dc7b commit 9bb9510

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,31 @@ describe("AssetAccess", () => {
424424
}).pipe(Effect.provide(layerTest)),
425425
);
426426

427+
it.effect.skipIf(!symlinksSupported)(
428+
"preserves absolute draft previews through stable symlinks",
429+
() =>
430+
Effect.gen(function* () {
431+
const fs = yield* FileSystem.FileSystem;
432+
const path = yield* Path.Path;
433+
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-draft-absolute-" });
434+
for (const extension of ["png", "mp4", "wav"]) {
435+
const target = path.join(root, `target.${extension}`);
436+
const alias = path.join(root, `alias.${extension}`);
437+
yield* fs.writeFileString(target, "preview bytes");
438+
yield* fs.symlink(target, alias);
439+
const result = yield* issueAssetUrl({
440+
resource: { _tag: "draft-workspace-file", cwd: root, path: alias },
441+
workspaceRoot: root,
442+
});
443+
const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
444+
const separator = suffix.indexOf("/");
445+
expect(
446+
yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1)),
447+
).toMatchObject({ kind: "file", path: yield* fs.realPath(target) });
448+
}
449+
}).pipe(Effect.provide(layerTest)),
450+
);
451+
427452
it.effect.skipIf(!symlinksSupported)(
428453
"rejects a draft media path swapped after workspace containment validation",
429454
() =>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ const readImageDimensionsFromHeader = (filePath: string) =>
353353
const finalizeAbsoluteMediaFileAsset = Effect.fn("AssetAccess.finalizeAbsoluteMediaFileAsset")(
354354
function* (input: {
355355
readonly requestedPath: string;
356+
readonly expectedCanonicalPath?: string;
356357
readonly workspaceRoot: string | undefined;
357358
readonly resource: AssetResource;
358359
readonly expiresAt: number;
@@ -378,11 +379,11 @@ const finalizeAbsoluteMediaFileAsset = Effect.fn("AssetAccess.finalizeAbsoluteMe
378379
(cause) => new AssetWorkspaceAssetInspectionError({ resource: input.resource, cause }),
379380
),
380381
);
381-
// Draft paths already passed canonical workspace containment; never follow a
382+
// The workspace caller pins its containment-checked path; never follow a
382383
// replacement symlink to a different file during this second resolution.
383384
if (
384385
!canonicalFile ||
385-
(input.resource._tag === "draft-workspace-file" && canonicalFile !== requestedPath)
386+
(input.expectedCanonicalPath !== undefined && canonicalFile !== input.expectedCanonicalPath)
386387
) {
387388
return yield* new AssetWorkspaceAssetNotFoundError({
388389
resource: input.resource,
@@ -488,6 +489,7 @@ const finalizeWorkspaceFileAsset = Effect.fn("AssetAccess.finalizeWorkspaceFileA
488489
return yield* finalizeAbsoluteMediaFileAsset({
489490
...input,
490491
requestedPath: canonicalFile,
492+
expectedCanonicalPath: canonicalFile,
491493
});
492494
}
493495
const canonicalWorkspaceRoot = yield* fileSystem.realPath(input.workspaceRoot).pipe(

0 commit comments

Comments
 (0)