diff options
| author | Fuwn <[email protected]> | 2024-10-09 00:41:20 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-10-09 00:41:43 -0700 |
| commit | 998b63a35256ac985a5a2714dd1ca451af4dfd8a (patch) | |
| tree | 50796121a9d5ab0330fdc5d7e098bda2860d9726 /src/lib/Error | |
| parent | feat(graphql): add badgeCount field (diff) | |
| download | due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.tar.xz due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.zip | |
chore(prettier): use spaces instead of tabs
Diffstat (limited to 'src/lib/Error')
| -rw-r--r-- | src/lib/Error/AnimeRateLimited.svelte | 22 | ||||
| -rw-r--r-- | src/lib/Error/DotDotDot.svelte | 26 | ||||
| -rw-r--r-- | src/lib/Error/LogInRestricted.svelte | 26 | ||||
| -rw-r--r-- | src/lib/Error/RateLimited.svelte | 110 | ||||
| -rw-r--r-- | src/lib/Error/path.ts | 20 | ||||
| -rw-r--r-- | src/lib/Error/rateLimit.ts | 8 |
6 files changed, 106 insertions, 106 deletions
diff --git a/src/lib/Error/AnimeRateLimited.svelte b/src/lib/Error/AnimeRateLimited.svelte index 89b7ede2..96df3ad5 100644 --- a/src/lib/Error/AnimeRateLimited.svelte +++ b/src/lib/Error/AnimeRateLimited.svelte @@ -1,19 +1,19 @@ <script> - import Popup from '$lib/Layout/Popup.svelte'; + import Popup from '$lib/Layout/Popup.svelte'; </script> <Popup locked fullscreen> - <p><slot /></p> + <p><slot /></p> - <span>It is likely that you have been rate-limited by AniList. Please try again later.</span> + <span>It is likely that you have been rate-limited by AniList. Please try again later.</span> - {#await fetch('https://api.waifu.pics/sfw/cry') then response} - {#await response.json() then json} - <p /> + {#await fetch('https://api.waifu.pics/sfw/cry') then response} + {#await response.json() then json} + <p /> - <a href={`https://trace.moe/?url=${encodeURIComponent(json.url)}`} target="_blank"> - <img src={json.url} alt="" style="width: 30vw;" /> - </a> - {/await} - {/await} + <a href={`https://trace.moe/?url=${encodeURIComponent(json.url)}`} target="_blank"> + <img src={json.url} alt="" style="width: 30vw;" /> + </a> + {/await} + {/await} </Popup> diff --git a/src/lib/Error/DotDotDot.svelte b/src/lib/Error/DotDotDot.svelte index c9c62356..73261eba 100644 --- a/src/lib/Error/DotDotDot.svelte +++ b/src/lib/Error/DotDotDot.svelte @@ -1,22 +1,22 @@ <script lang="ts"> - import { onDestroy, onMount } from 'svelte'; + import { onDestroy, onMount } from 'svelte'; - export let max: number | undefined = undefined; - export let perMs = 1000; - export let start = ''; + export let max: number | undefined = undefined; + export let perMs = 1000; + export let start = ''; - let dots = start; - let interval: NodeJS.Timeout; + let dots = start; + let interval: NodeJS.Timeout; - onMount(() => { - interval = setInterval(() => { - dots += '.'; + onMount(() => { + interval = setInterval(() => { + dots += '.'; - if (max && dots.length > max) dots = ''; - }, perMs); - }); + if (max && dots.length > max) dots = ''; + }, perMs); + }); - onDestroy(() => clearInterval(interval)); + onDestroy(() => clearInterval(interval)); </script> {dots} diff --git a/src/lib/Error/LogInRestricted.svelte b/src/lib/Error/LogInRestricted.svelte index 76799da1..07a9adec 100644 --- a/src/lib/Error/LogInRestricted.svelte +++ b/src/lib/Error/LogInRestricted.svelte @@ -1,18 +1,18 @@ <script> - import Popup from '$lib/Layout/Popup.svelte'; - import { env } from '$env/dynamic/public'; + import Popup from '$lib/Layout/Popup.svelte'; + import { env } from '$env/dynamic/public'; </script> <Popup fullscreen locked> - <div class="message"> - Please <a - href={`https://anilist.co/api/v2/oauth/authorize?client_id=${env.PUBLIC_ANILIST_CLIENT_ID}&redirect_uri=${env.PUBLIC_ANILIST_REDIRECT_URI}&response_type=code`} - on:click={() => { - localStorage.setItem( - 'redirect', - window.location.origin + window.location.pathname + window.location.search - ); - }}>log in</a - > to view this page. - </div> + <div class="message"> + Please <a + href={`https://anilist.co/api/v2/oauth/authorize?client_id=${env.PUBLIC_ANILIST_CLIENT_ID}&redirect_uri=${env.PUBLIC_ANILIST_REDIRECT_URI}&response_type=code`} + on:click={() => { + localStorage.setItem( + 'redirect', + window.location.origin + window.location.pathname + window.location.search + ); + }}>log in</a + > to view this page. + </div> </Popup> diff --git a/src/lib/Error/RateLimited.svelte b/src/lib/Error/RateLimited.svelte index 2360a44a..973d75d9 100644 --- a/src/lib/Error/RateLimited.svelte +++ b/src/lib/Error/RateLimited.svelte @@ -1,60 +1,60 @@ <script lang="ts"> - export let type = 'Media'; - export let loginSessionError = true; - export let contact = true; - export let list = true; - export let card = false; - export let might = true; + export let type = 'Media'; + export let loginSessionError = true; + export let contact = true; + export let list = true; + export let card = false; + export let might = true; </script> <div class:card> - {#if list} - <ul> - <li> - <p> - {type} could not be loaded. You{might ? ' might' : ''} have been rate-limited. {#if !might} - Try again in one minute. - {/if} - </p> - - {#if loginSessionError} - <p> - Your login session may have expired. Try logging out and logging back in, or try again - in a few minutes. - </p> - {/if} - - <slot /> - - {#if contact} - <p /> - - If the problem persists, please contact - <a href="https://anilist.co/user/fuwn" target="_blank">@fuwn</a> on AniList. - {/if} - </li> - </ul> - {:else} - <p> - {type} could not be loaded. You{might ? ' might' : ''} have been rate-limited. {#if !might} - Try again in one minute. - {/if} - </p> - - {#if loginSessionError} - <p> - Your login session may have expired. Try logging out and logging back in, or try again in a - few minutes. - </p> - {/if} - - <slot /> - - {#if contact} - <p /> - - If the problem persists, please contact - <a href="https://anilist.co/user/fuwn" target="_blank">@fuwn</a> on AniList. - {/if} - {/if} + {#if list} + <ul> + <li> + <p> + {type} could not be loaded. You{might ? ' might' : ''} have been rate-limited. {#if !might} + Try again in one minute. + {/if} + </p> + + {#if loginSessionError} + <p> + Your login session may have expired. Try logging out and logging back in, or try again + in a few minutes. + </p> + {/if} + + <slot /> + + {#if contact} + <p /> + + If the problem persists, please contact + <a href="https://anilist.co/user/fuwn" target="_blank">@fuwn</a> on AniList. + {/if} + </li> + </ul> + {:else} + <p> + {type} could not be loaded. You{might ? ' might' : ''} have been rate-limited. {#if !might} + Try again in one minute. + {/if} + </p> + + {#if loginSessionError} + <p> + Your login session may have expired. Try logging out and logging back in, or try again in a + few minutes. + </p> + {/if} + + <slot /> + + {#if contact} + <p /> + + If the problem persists, please contact + <a href="https://anilist.co/user/fuwn" target="_blank">@fuwn</a> on AniList. + {/if} + {/if} </div> diff --git a/src/lib/Error/path.ts b/src/lib/Error/path.ts index 1e36268c..a35a4cb8 100644 --- a/src/lib/Error/path.ts +++ b/src/lib/Error/path.ts @@ -1,20 +1,20 @@ import levenshtein from 'fast-levenshtein'; export const closest = (path: string, suggestions: string[]) => { - const partialMatches = suggestions.filter((suggestion) => suggestion.includes(path)); + const partialMatches = suggestions.filter((suggestion) => suggestion.includes(path)); - if (partialMatches.length) return partialMatches[0]; + if (partialMatches.length) return partialMatches[0]; - const suggestionsWithDistance = suggestions.map((suggestion) => { - const distance = levenshtein.get(path, suggestion); + const suggestionsWithDistance = suggestions.map((suggestion) => { + const distance = levenshtein.get(path, suggestion); - return { suggestion, distance }; - }); + return { suggestion, distance }; + }); - suggestionsWithDistance.sort((a, b) => a.distance - b.distance); + suggestionsWithDistance.sort((a, b) => a.distance - b.distance); - for (const suggestion of suggestionsWithDistance) - if (suggestion.distance < suggestion.suggestion.length / 2) return suggestion.suggestion; + for (const suggestion of suggestionsWithDistance) + if (suggestion.distance < suggestion.suggestion.length / 2) return suggestion.suggestion; - return suggestionsWithDistance[0].suggestion; + return suggestionsWithDistance[0].suggestion; }; diff --git a/src/lib/Error/rateLimit.ts b/src/lib/Error/rateLimit.ts index 98e726a2..b70094e6 100644 --- a/src/lib/Error/rateLimit.ts +++ b/src/lib/Error/rateLimit.ts @@ -2,11 +2,11 @@ import type { RequestEvent } from '@sveltejs/kit'; import { RateLimiter } from 'sveltekit-rate-limiter/server'; export const checkRateLimit = async (event: RequestEvent) => { - const limiter = new RateLimiter({ rates: { IP: [5, 's'] } }); + const limiter = new RateLimiter({ rates: { IP: [5, 's'] } }); - await limiter.cookieLimiter?.preflight(event); + await limiter.cookieLimiter?.preflight(event); - if (await limiter.isLimited(event)) return new Response('rate-limited'); + if (await limiter.isLimited(event)) return new Response('rate-limited'); - return null; + return null; }; |