This commit is contained in:
2026-10-18 04:40:55 +07:00
parent c36d3fd314
commit 41d3e8ac5e
12 changed files with 4105 additions and 157 deletions
+17 -4
View File
@@ -1,3 +1,4 @@
import { createEveningDetectiveServerClient } from './api/generated/crabs/evening_detective_server/index.js'
import {
ApiError,
NetworkError,
@@ -240,10 +241,18 @@ export async function prepareScreenPackage(
AbortSignal.timeout(30_000),
...(request.signal ? [request.signal] : []),
])
async function get(suffix: string): Promise<unknown> {
const client = createEveningDetectiveServerClient(async (requestData, meta) => {
const suffix =
meta.method === 'GetGameMusic'
? '/music'
: meta.method === 'GetScreenPlan'
? '/screen-plan'
: ''
let response: Response
try {
response = await fetchAPI(`${server}/api/games/${request.gameId}${suffix}`, {
response = await fetchAPI(`${server}/${requestData.path}`, {
method: requestData.method,
body: requestData.body,
headers: { Authorization: `Bearer ${request.token}`, Accept: 'application/json' },
credentials: 'omit',
redirect: 'error',
@@ -292,8 +301,12 @@ export async function prepareScreenPackage(
request.onRequestFailure?.({ path: `/api/games/{id}${suffix}`, reason: 'INVALID_JSON' })
throw new Error('Некорректный JSON в ответе API')
}
}
const [game, plan, music] = await Promise.all([get(''), get('/screen-plan'), get('/music')])
})
const [game, plan, music] = await Promise.all([
client.GetGame({ ID: request.gameId }),
client.GetScreenPlan({ gameID: request.gameId }),
client.GetGameMusic({ gameID: request.gameId }),
])
return buildScreenPackage(server, request.gameId, { game, plan, music })
}