Clarify receive requests and add retry countdowns and device unblock controls

This commit is contained in:
2026-10-14 12:22:07 +09:00
parent ff89daac8c
commit 3852c87e2e
16 changed files with 739 additions and 60 deletions

View File

@@ -26,6 +26,7 @@ export const device = ref(null),
discoveryEnabled = ref(false),
error = ref('');
export const pendingPeers = ref([]);
export const transferCooldown = ref({ until: 0, targetDeviceId: null });
let pendingTimer;
let deviceInfo = {};
export const nextCursor = ref(null);
@@ -60,11 +61,28 @@ export async function api(path, method = 'GET', body, key, signal) {
body: body !== undefined ? JSON.stringify(body) : undefined,
});
const payload = await response.json();
if (!response.ok)
if (!response.ok) {
const retryAfterSeconds = Number(
payload.retryAfterSeconds ?? response.headers.get('Retry-After'),
);
if (
response.status === 429 &&
retryAfterSeconds > 0 &&
Number.isFinite(retryAfterSeconds) &&
method === 'POST' &&
(path === '/transfer-requests' || /^\/vault\/[^/]+\/send$/.test(path))
) {
transferCooldown.value = {
until: Date.now() + Math.ceil(retryAfterSeconds) * 1000,
targetDeviceId: payload.limitScope === 'pair' ? body?.targetDeviceId : null,
};
}
throw Object.assign(new Error(payload.message ?? '요청을 처리하지 못했습니다.'), {
status: response.status,
code: payload.code,
retryAfterSeconds,
});
}
return payload;
}
export async function bootstrap() {
@@ -154,9 +172,13 @@ export function showError(err) {
const message = /^(Failed to fetch|NetworkError|Load failed)$/i.test(raw)
? '서버에 연결하지 못했어요. 잠시 후 다시 시도해 주세요.'
: raw;
error.value = message;
const displayed =
err?.retryAfterSeconds > 0
? `${message} ${Math.ceil(err.retryAfterSeconds)}초 후 다시 시도할 수 있어요.`
: message;
error.value = displayed;
errorTimer = setTimeout(() => {
if (error.value === message) error.value = '';
if (error.value === displayed) error.value = '';
}, 5000);
}
export const refresh = createRefreshQueue(async () => {