chore: lint

This commit is contained in:
Outvi V 2025-05-31 10:09:46 +08:00
parent 85bc401e47
commit 5e6c6fccc4

View file

@ -25,52 +25,54 @@ const props = defineProps<{
const note = ref<Misskey.entities.Note | null>(null); const note = ref<Misskey.entities.Note | null>(null);
let timeoutId = null; // eslint-disable-next-line id-denylist
let timeoutId: ReturnType<typeof window.setTimeout> | null = null;
async function sleep(ms: number): Promise<void> { async function sleep(ms: number): Promise<void> {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(() => { window.setTimeout(() => {
resolve() resolve();
}, ms); }, ms);
}); });
} }
async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount: number = 5): Promise<T> { async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount = 5): Promise<T> {
let lastResult: T = undefined!; let lastResult: T;
const r = Math.random(); for (let i = 0; i < retryCount; i++) {
for(let i=0; i<retryCount; i++) {
const [ok, resultOrError] = await f() const [ok, resultOrError] = await f()
.then(result => [true, result]) .then(result => [true, result])
.catch(err => [false, err]); .catch(err => [false, err]);
lastResult = resultOrError; lastResult = resultOrError;
if (ok) { if (ok) {
break; break;
} }
// RATE_LIMIT_EXCEEDED // RATE_LIMIT_EXCEEDED
if (resultOrError?.id === "d5826d14-3982-4d2e-8011-b9e9f02499ef") { if (resultOrError?.id === 'd5826d14-3982-4d2e-8011-b9e9f02499ef') {
await sleep(resultOrError?.info?.fullResetMs ?? 1000); await sleep(resultOrError?.info?.fullResetMs ?? 1000);
continue; continue;
} }
throw resultOrError; throw resultOrError;
} }
return lastResult; return lastResult;
} }
onMounted(() => { onMounted(() => {
if (props.block.note == null) return; if (props.block.note == null) return;
timeoutId = setTimeout(() => { timeoutId = window.setTimeout(() => {
retryOnThrottle(() => misskeyApi('notes/show', { noteId: props.block.note })).then(result => { retryOnThrottle(() => misskeyApi('notes/show', { noteId: props.block.note })).then(result => {
note.value = result; note.value = result;
}); });
}, 500 * props.index); // rate limit is 2 reqs per sec }, 500 * props.index); // rate limit is 2 reqs per sec
}); });
onUnmounted(() => { onUnmounted(() => {
if (timeoutId !== null) clearTimeout(timeoutId); if (timeoutId !== null) {
window.clearTimeout(timeoutId);
}
}); });
</script> </script>