Fix recorder finalize path and add invite-gated login

这个提交包含在:
cryptocommuniums-afk
2026-03-15 00:52:11 +08:00
父节点 ad83ce9c68
当前提交 d1b6603061
修改 13 个文件,包含 458 行新增18 行删除

73
server/mediaService.test.ts 普通文件
查看文件

@@ -0,0 +1,73 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { ENV } from "./_core/env";
import { getRemoteMediaSession } from "./mediaService";
const originalMediaServiceUrl = ENV.mediaServiceUrl;
const originalFetch = global.fetch;
afterEach(() => {
ENV.mediaServiceUrl = originalMediaServiceUrl;
global.fetch = originalFetch;
vi.restoreAllMocks();
});
describe("getRemoteMediaSession", () => {
it("falls back to /media-prefixed routes when the root route returns 404", async () => {
ENV.mediaServiceUrl = "http://127.0.0.1:8081";
const fetchMock = vi.fn()
.mockResolvedValueOnce({
ok: false,
status: 404,
text: vi.fn().mockResolvedValue("404 page not found\n"),
statusText: "Not Found",
})
.mockResolvedValueOnce({
ok: true,
json: vi.fn().mockResolvedValue({
session: {
id: "session-1",
userId: "1",
title: "demo",
archiveStatus: "idle",
playback: {
ready: false,
},
},
}),
});
global.fetch = fetchMock as typeof fetch;
const session = await getRemoteMediaSession("session-1");
expect(session.id).toBe("session-1");
expect(fetchMock).toHaveBeenNthCalledWith(1, "http://127.0.0.1:8081/sessions/session-1");
expect(fetchMock).toHaveBeenNthCalledWith(2, "http://127.0.0.1:8081/media/sessions/session-1");
});
it("uses the configured /media base URL directly when already present", async () => {
ENV.mediaServiceUrl = "http://media:8081/media";
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
json: vi.fn().mockResolvedValue({
session: {
id: "session-2",
userId: "2",
title: "demo",
archiveStatus: "processing",
playback: {
ready: false,
},
},
}),
});
global.fetch = fetchMock as typeof fetch;
const session = await getRemoteMediaSession("session-2");
expect(session.id).toBe("session-2");
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith("http://media:8081/media/sessions/session-2");
});
});