aboutsummaryrefslogtreecommitdiff
path: root/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/api/configuration/pin/+server.ts32
-rw-r--r--src/routes/hololive/+page.svelte59
2 files changed, 91 insertions, 0 deletions
diff --git a/src/routes/api/configuration/pin/+server.ts b/src/routes/api/configuration/pin/+server.ts
new file mode 100644
index 00000000..f813d8e8
--- /dev/null
+++ b/src/routes/api/configuration/pin/+server.ts
@@ -0,0 +1,32 @@
+import { userIdentity } from '$lib/Data/AniList/identity';
+import { toggleHololiveStreamPinning } from '$lib/Database/userConfiguration';
+
+const unauthorised = new Response('Unauthorised', { status: 401 });
+
+export const PUT = async ({ cookies, url }) => {
+ const userCookie = cookies.get('user');
+
+ if (!userCookie) return unauthorised;
+
+ const user = JSON.parse(userCookie);
+
+ return Response.json(
+ await toggleHololiveStreamPinning(
+ (
+ await userIdentity({
+ tokenType: user['token_type'],
+ expiresIn: user['expires_in'],
+ accessToken: user['access_token'],
+ refreshToken: user['refresh_token']
+ })
+ ).id,
+ url.searchParams.get('stream') || ''
+ ),
+ {
+ headers: {
+ method: 'PUT',
+ 'Access-Control-Allow-Origin': 'https://due.moe'
+ }
+ }
+ );
+};
diff --git a/src/routes/hololive/+page.svelte b/src/routes/hololive/+page.svelte
index d30766b9..aace56a3 100644
--- a/src/routes/hololive/+page.svelte
+++ b/src/routes/hololive/+page.svelte
@@ -6,6 +6,9 @@
import { parseScheduleHtml } from '$lib/Data/hololive';
import proxy from '$lib/Utility/proxy';
import locale from '$stores/locale';
+ import root from '$lib/Utility/root';
+ import identity from '$stores/identity';
+ import Icon from '@iconify/svelte';
interface ParseResult {
lives: {
@@ -21,6 +24,17 @@
}
let schedulePromise: Promise<Response>;
+ let pinnedStreams: string[] = [];
+
+ $: {
+ pinnedStreams = pinnedStreams;
+
+ schedulePromise = fetch(proxy('https://schedule.hololive.tv'), {
+ headers: {
+ Cookie: 'timezone=Asia/Tokyo'
+ }
+ });
+ }
onMount(async () => {
schedulePromise = fetch(proxy('https://schedule.hololive.tv'), {
@@ -28,9 +42,29 @@
Cookie: 'timezone=Asia/Tokyo'
}
});
+
+ getPinnedStreams();
});
+ const getPinnedStreams = () => {
+ if ($identity.id !== -2)
+ fetch(root(`/api/configuration?id=${$identity.id}`)).then((response) => {
+ if (response.ok)
+ response.json().then((data) => {
+ if (data && data.configuration) pinnedStreams = data.pinned_hololive_streams;
+ });
+ });
+ };
+
const typeSchedule = (schedule: any) => schedule as ParseResult;
+
+ const pinStream = (streamer: string) =>
+ fetch(root(`/api/configuration/pin?stream=${encodeURIComponent(streamer)}`), {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ }).then(getPinnedStreams);
</script>
<HeadTitle route="hololive Schedule" path="/hololive" />
@@ -60,6 +94,12 @@
return time.getTime() > Date.now() - 12 * 60 * 60 * 1000 || time.getTime() > Date.now() || live.streaming;
})
.sort((a, b) => {
+ if (pinnedStreams.includes(a.streamer) && a.streaming) {
+ return -1;
+ } else if (pinnedStreams.includes(b.streamer) && b.streaming) {
+ return 1;
+ }
+
if (a.streaming && !b.streaming) {
return -1;
} else if (!a.streaming && b.streaming) {
@@ -77,6 +117,18 @@
return aTime - new Date(b.time).getTime();
}) as live}
<div class="stream card">
+ {#if $identity.id !== -2}
+ <div class="pin-icon">
+ <a href={'#'} on:click={() => pinStream(live.streamer)}>
+ <Icon
+ icon={`pajamas:thumbtack${
+ pinnedStreams.includes(live.streamer) ? '-solid' : ''
+ }`}
+ />
+ </a>
+ </div>
+ {/if}
+
<p>
[{#if live.streaming}
<b class="live">{$locale().hololive.live}</b
@@ -167,4 +219,11 @@
grid-template-columns: repeat(auto-fill, minmax(22.5em, 1fr));
gap: 0.5em;
}
+
+ .pin-icon {
+ position: absolute;
+ right: 0;
+ top: 0;
+ padding: 0.75rem;
+ }
</style>