WIP v1.3.7: 기록 묶음(경기 · 경기 전후 대화) 관리 · zip 내보내기/받아오기
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -188,7 +188,7 @@ export class RelayHub {
|
||||
}
|
||||
|
||||
/** 브라우저 요청 하나를 게임 PC 로 넘긴다 */
|
||||
request(method: string, path: string, headers: Record<string, string>, user: { id: string; name: string; avatar: string | null }, body: string | null, timeoutMs = 20000): Promise<RelayResponse> {
|
||||
request(method: string, path: string, headers: Record<string, string>, user: { id: string; name: string; avatar: string | null }, body: string | Buffer | null, timeoutMs = 20000): Promise<RelayResponse> {
|
||||
const dev = this.device;
|
||||
if (!dev || !this.status().online) return Promise.reject(new Error('device_offline'));
|
||||
const id = crypto.randomBytes(8).toString('hex');
|
||||
@@ -200,6 +200,17 @@ export class RelayHub {
|
||||
}
|
||||
}, timeoutMs);
|
||||
this.pending.set(id, { resolve, reject, timer, chunks: [] });
|
||||
if (Buffer.isBuffer(body)) {
|
||||
// 바이너리 본문(zip 받아오기): 1MB 조각으로 먼저 보내고 요청을 보낸다 (앱은 한 메시지 8MB 까지)
|
||||
const idBuf = Buffer.from(id, 'utf8');
|
||||
const head = Buffer.alloc(4);
|
||||
head.writeUInt32BE(idBuf.length, 0);
|
||||
const CH = 1024 * 1024;
|
||||
for (let i = 0; i < body.length; i += CH) dev.ws.send(Buffer.concat([head, idBuf, body.subarray(i, i + CH)]), { binary: true });
|
||||
const msg: RelayToDevice = { t: 'req', id, method, path, headers, user, body: null, bin: true };
|
||||
dev.ws.send(JSON.stringify(msg));
|
||||
return;
|
||||
}
|
||||
const msg: RelayToDevice = { t: 'req', id, method, path, headers, user, body };
|
||||
dev.ws.send(JSON.stringify(msg));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user