fix(desktop): resolve local media linked from remote threads (#10619)

Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
mariaandmaria-rcks authored and GitHub committed 2026-09-07 23:52:28 -03:00
1 parent 9fe4d6568b
commit a01b227d6f
6 files changed
+248 -11

No files matched your search

+37
View File
@@ -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();
+5 -1
View File
@@ -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 });
}
+19 -1
View File
@@ -2,12 +2,30 @@ import {
createAssetEnvironmentAtoms,
createProjectFaviconUrlAtomFamily,
} from "@t3tools/client-runtime/state/assets";
import { Atom } from "effect/unstable/reactivity";
import { connectionAtomRuntime } from "../connection/runtime";
import { projectFaviconCache } from "../assets/projectFaviconCache";
import { isElectron } from "../env";
import { primaryEnvironmentIdAtom } from "./primaryEnvironment";
import { environmentSession } from "./session";
export const assetEnvironment = createAssetEnvironmentAtoms(connectionAtomRuntime);
const localMediaEnvironment = Atom.make((get) => {
if (!isElectron) return null;
const environmentId = get(primaryEnvironmentIdAtom);
if (environmentId === null) return null;
const connection = get(environmentSession.preparedConnectionValueAtom(environmentId));
// The session's bootstrap config clears on disconnect and refreshes on reconnect.
const config = get(environmentSession.initialConfigValueAtom(environmentId));
return connection._tag === "None" || config === null
? null
: { environmentId, httpBaseUrl: connection.value.httpBaseUrl };
});
export const assetEnvironment = createAssetEnvironmentAtoms(
connectionAtomRuntime,
localMediaEnvironment,
);
export const projectFaviconUrlAtom = createProjectFaviconUrlAtomFamily({
imageCache: projectFaviconCache,