fix(desktop): resolve local media linked from remote threads (#10619)
Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
1 parent
9fe4d6568b
commit
a01b227d6f
6 files changed
+248
-11
No files matched your search
@@ -5473,6 +5473,43 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
it.effect("serves absolute host media without a local thread and rejects relative media", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* buildAppUnderTest();
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-host-media-" });
|
||||
const wsUrl = yield* getWsServerUrl("/ws");
|
||||
const threadId = ThreadId.make("thread-on-another-environment");
|
||||
|
||||
yield* Effect.scoped(
|
||||
withWsRpcClient(wsUrl, (client) =>
|
||||
Effect.gen(function* () {
|
||||
for (const [name, mimeType] of [
|
||||
["screenshot.png", "image/png"],
|
||||
["recording.mp4", "video/mp4"],
|
||||
] as const) {
|
||||
const filePath = path.join(directory, name);
|
||||
yield* fileSystem.writeFileString(filePath, "host media bytes");
|
||||
const issued = yield* client[WS_METHODS.assetsCreateUrl]({
|
||||
resource: { _tag: "media-file", threadId, path: filePath },
|
||||
});
|
||||
const response = yield* HttpClient.get(issued.relativeUrl);
|
||||
assert.equal(response.status, 200);
|
||||
assert.equal(response.headers["content-type"], mimeType);
|
||||
assert.equal(yield* response.text, "host media bytes");
|
||||
|
||||
const error = yield* client[WS_METHODS.assetsCreateUrl]({
|
||||
resource: { _tag: "media-file", threadId, path: name },
|
||||
}).pipe(Effect.flip);
|
||||
assert.equal(error._tag, "AssetWorkspaceContextNotFoundError");
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
it.effect("uploads image bytes through a signed URL issued by websocket rpc", () =>
|
||||
Effect.gen(function* () {
|
||||
const config = yield* buildAppUnderTest();
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Queue from "effect/Queue";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Schema from "effect/Schema";
|
||||
@@ -2390,9 +2391,12 @@ const makeWsRpcLayer = (
|
||||
observeRpcEffect(
|
||||
WS_METHODS.assetsCreateUrl,
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
// An absolute media path can be linked from a thread on another environment.
|
||||
if (
|
||||
input.resource._tag === "attachment" ||
|
||||
input.resource._tag === "native-app-icon"
|
||||
input.resource._tag === "native-app-icon" ||
|
||||
(input.resource._tag === "media-file" && path.isAbsolute(input.resource.path))
|
||||
) {
|
||||
return yield* issueAssetUrl({ resource: input.resource });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user