Skip to content

Commit

Permalink
yearly review wip checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TsFreddie committed Jan 9, 2025
1 parent 4e389a6 commit cc635ae
Show file tree
Hide file tree
Showing 11 changed files with 981 additions and 17 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@sveltejs/vite-plugin-svelte": "^4.0.4",
"@types/bun": "^1.1.14",
"@types/markdown-it": "^14.1.2",
"@types/sqlstring": "^2.3.2",
"autoprefixer": "^10.4.20",
"croner": "^9.0.0",
"keyv": "^5.2.3",
Expand All @@ -34,6 +35,7 @@
"prettier-plugin-tailwindcss": "^0.6.9",
"rollup": "^4.29.1",
"rss-parser": "^3.13.0",
"sqlstring": "^2.3.3",
"svelte": "^5.15.0",
"svelte-adapter-bun": "^0.5.2",
"svelte-check": "^4.1.1",
Expand Down
18 changes: 9 additions & 9 deletions src/lib/components/TeeRender.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAACACAYAAADktbcKAAAFVklEQVR4nO3dXW8UVRjA8f+2ZVsJYCuCpYoYFYjKmwQSFRHilZFPwCf0K3ilCIbEqBWRKCSG+AYCKgUE6ZbWevHMZueCttTd2bN75v9LNsyy285zYOfZc+a8gSRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkqSB0UgdgIbOOLCx+HMcGAMWgQWgBfwDzCeLTusyljoADZ0DwJurvD4LfNWnWNSlkdQBaOj83eXrGiDWANS2AdgLPAOcXeV9c8BtorrfAh4VP9skmgR31jjPSSJJfEc0G5SQ9wDUBPYXjyawDHwE3K/gXJuA08TnrkUkgUuYCJIZTR2AknoR+BDYReez0AAeAjcqON9rwAvF8RgwA7xK1CruVXA+rcEEUE9N4B3gbaL63jYHfAH8QNQEeu0W8CcwSfQktGPZDUwB14ClCs6rFZgA6ul54uJve0C0+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Vj6uwfAJ8A3ePH3nQmg3u4BV4gLfiux8+4ycJZq1ty/T3zzN4rff4HY3ruqGofW4AALtTWBN4AtwGervO85YnGOFnERLxJV+fHid5xj9drDSSLxXMKNPZIbSx2ABsYCUQ1fyySrL8gxyeoJ4Mw6YlLF7HvVeq21ylAuqxDVgk0ArdcEcRNvvHiMEs2AVvF4SPQySJIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSVKV/gMpgLodSf6HygAAAABJRU5ErkJggg==';
let skin = $state(X_SPEC_SKIN);
let loadedSkin = $state(null) as string | null;
let loadingSkin = $state(null) as string | null;
let bodyFilter = $state(null) as string | null;
let feetFilter = $state(null) as string | null;
Expand All @@ -49,9 +49,9 @@
let root = $state(null) as Element | null;
const updateSkin = async () => {
const currentLoadingSkin = url || name;
const thisLoadingSkin = url || name;
if (currentLoadingSkin == loadedSkin) {
if (thisLoadingSkin == loadingSkin) {
return;
}
Expand All @@ -60,11 +60,12 @@
abortController = null;
}
loadingSkin = thisLoadingSkin;
skin = X_SPEC_SKIN;
if (!name && !url) {
skin = useDefault ? DEFAULT_SKIN : X_SPEC_SKIN;
loadedSkin = 'default';
loadingSkin = 'default';
return;
}
Expand All @@ -90,14 +91,13 @@
const skinData = await response.arrayBuffer();
const buffer = new Uint8Array(skinData);
skin = `data:${contentType};base64,${encodeBase64(buffer)}`;
loadedSkin = currentLoadingSkin;
} else {
skin = useDefault ? DEFAULT_SKIN : X_SPEC_SKIN;
loadedSkin = 'default';
loadingSkin = 'default';
}
} else {
skin = useDefault ? DEFAULT_SKIN : X_SPEC_SKIN;
loadedSkin = 'default';
loadingSkin = 'default';
}
};
Expand All @@ -108,7 +108,7 @@
}
if (intersectionObserver && root) {
intersectionObserver.unobserve(root);
intersectionObserver.disconnect();
intersectionObserver = null;
}
});
Expand All @@ -123,7 +123,7 @@
if (entry.isIntersecting) {
updateSkin();
} else {
if (abortController) {
if (abortController && !alwaysFetch) {
abortController.abort();
abortController = null;
}
Expand Down
9 changes: 9 additions & 0 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ export const unescapeHTML = (str: string) => {
.replace(/'/g, "'");
};

export const escapeHTML = (str: string) => {
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#x27;');
};

export const secondsToTime = (totalSeconds: number) => {
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/server/fetch-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ export class FetchCache<T> {

// not outdated but no cache, means the head response is possibly not ok or errored
if (response) {
throw new Error(`Failed to fetch data: ${response.status} ${response.statusText}`);
throw new Error(`Failed to fetch data: ${this.url} ${response.status} ${response.statusText}`);
} else {
throw new Error('Failed to fetch data: Unknown error');
throw new Error(`Failed to fetch data: ${this.url} Unknown error`);
}
})();

Expand Down
12 changes: 7 additions & 5 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
</script>

<div
class="flex min-h-svh flex-col bg-slate-800 {navigating.to ? 'opacity-60' : 'opacity-100'}"
class="max-w-svw flex min-h-svh flex-col overflow-x-hidden bg-slate-800 {navigating.to
? 'opacity-60'
: 'opacity-100'}"
style={navigating.to ? 'transition: opacity 0.1s ease-in-out 0.1s;' : ''}
>
<header class="flex bg-slate-900 px-4 py-2 text-slate-300 md:py-4">
Expand All @@ -52,14 +54,14 @@
</div>
</header>

<main class="flex-grow basis-1 bg-slate-800 p-2 text-slate-300 md:p-4">
<div class="container mx-auto h-full">
<main class="flex flex-grow bg-slate-800 p-2 text-slate-300 md:p-4">
<div class="container relative mx-auto flex-grow">
{@render children()}
</div>
</main>

<footer class="flex flex-row bg-slate-900 px-4 py-1 text-slate-300 md:py-4 items-center">
<div class="text-sm sm:text-base">
<footer class="flex flex-row items-center bg-slate-900 px-4 py-1 text-slate-300 md:py-4">
<div class="text-sm md:text-base">
<Link href="https://beian.miit.gov.cn/" type="subtle" className="font-bold"
>冀ICP备2021002466号</Link
>
Expand Down
23 changes: 23 additions & 0 deletions src/routes/ddnet/yearly/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { PageServerLoad } from './$types';
import { getSkin } from '$lib/server/ddtracker';
import { getPlayer } from '$lib/server/players';
import { decodeAsciiURIComponent } from '$lib/link';

export const load = (async ({ url, parent }) => {
const year = parseInt(url.searchParams.get('year') || '2024');
const name = decodeAsciiURIComponent(url.searchParams.get('name') || '');

if (!name) {
return { year, ...(await parent()) };
}

const player = await getPlayer(name);
if (!player || !player.name) {
const error = `未找到名为${name}的玩家`;
return { year, error, ...(await parent()) };
}

const skin = getSkin(name, 'as:cn') || getSkin(name);

return { year, name, skin, player, ...(await parent()) };
}) satisfies PageServerLoad;
Loading

0 comments on commit cc635ae

Please sign in to comment.