Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paasei #228

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions prisma/migrations/20230917122645_pasen/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- CreateTable
CREATE TABLE `Egg` (
`id` VARCHAR(191) NOT NULL,
`img` VARCHAR(191) NOT NULL DEFAULT 'egg1.png',
`name` VARCHAR(191) NOT NULL DEFAULT 'Egg',
`found` TINYBLOB NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateIndex
CREATE UNIQUE INDEX `Egg_name_key` ON `Egg`(`name`);

INSERT IGNORE INTO `Egg` (`id`, `name`, `found`)
VALUES ('HX1aAqX25B4lo1FQgNUeKjPEGH53r5byWc0Id6gmwkPeevvG7N', 'urEI', 0x0),
('UWn89YWEeurHH6NfeUFYBaewEu88uhl2iWTCh4OP18VguRs078', 'spEItify', 0x0),
('ZX0cAYFXqIyMQQz4cVmgVI7vRZfx3Fb9EH1lHZUAHPp4qVlSNN', 'strEIbos', 0x0),
('xkzR2iH1Ut4kwoT8G53vlxFoRQqfZLrKESLO7lFygpSMiPfDk7', 'Markdown', 0x0),
('FDaR8VJklWZdZX9qYMabhAJlR9wWWU7gPgagGfZG8AbckOY27T', 'profEIl', 0x0),
('3BoXkqmZITrIkVQ2WzaFXTROlx8VxjRKinjWcz6H1LLdVfZnLP', 'tutorEIal', 0x0),
('HnSF3i41PdqTzUpvmO7S0RwiB7RA6el5nfRUBAY7IhJVAK0DkT', 'Menu Ei', 0x0),
('wCZXlGQDecVPXIrQyz8lmR8BLpe730hTPu0mEVcFetBPjWXxwH', '100 Kliks', 0x0),
('Zask8Z6FdyZwxFQkwwUrPAUd53he7ydiLW1lJezA1mg0m7zm7O', 'instEIlingen', 0x0);


INSERT IGNORE INTO `Settings` (`name`, `description`, `value`) VALUES ('EGGHUNT_ENABLED', 'Of het paasei zoeken aan staat', '0');
7 changes: 7 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -757,3 +757,10 @@ model Comment {
activity Activity? @relation(fields: [activityId], references: [id], onDelete: SetNull)
activityId Int?
}

model Egg {
id String @id
img String @default("egg1.png")
name String @unique @default("Egg")
found Bytes @db.TinyBlob
}
4 changes: 2 additions & 2 deletions src/lib/components/breadcrumps.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
{#each $breadcrumbStore as c, i}
{#if c !== null}
{#if i == $breadcrumbStore.length - 1}
<span>{@html markdown(c.label)}</span>
<span>{@html markdown(c.label, true)}</span>
{:else}
<a href={c.href}>
<span>{@html markdown(c.label)}</span>
<span>{@html markdown(c.label, true)}</span>
</a>
<i><ChevronRight width="1.2em" height="1.2em" /></i>
{/if}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<script lang="ts">
import ProfileIcon from '$lib/components/profile-icon.svelte';
import type { User } from '@prisma/client';

export let user: User;
export let status: 'positive' | 'negative' | 'unsure';
export let user: {
firstName: string;
lastName: string;
profilePictureId: number | null;
ldapId: string;
};
export let status: 'positive' | 'negative' | 'unsure' | null = null;
</script>

<div class="user-card">
Expand All @@ -15,9 +19,11 @@
name={user.firstName + ' ' + user.lastName}
/>

<div class="status">
<div class="status-circle {status}" />
</div>
{#if status}
<div class="status">
<div class="status-circle {status}" />
</div>
{/if}
</div>

<div class="user-card-name">
Expand Down
Binary file added src/lib/oudlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions src/lib/server/egghunt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import db from './db';

export interface Egg {
show: boolean;
id: string;
img: string | undefined;
name: string | undefined;
}

export const shouldShowEgg = async (eggId: string, userId: number): Promise<Egg> => {
const enabled = await db.settings.findUnique({
where: {
name: 'EGGHUNT_ENABLED'
}
});
if (enabled?.value != '1')
return {
show: false,
img: undefined,
name: undefined,
id: eggId
};

const egg = await db.egg.findUnique({
where: { id: eggId }
});

return {
show: !!(egg && !([...egg.found][Math.round((userId - 1) / 8)] & (1 << (userId - 1) % 8))),
img: egg?.img,
name: egg?.name,
id: eggId
};
};
27 changes: 27 additions & 0 deletions src/lib/server/spotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,31 @@ export const refreshToken = async () => {
spotify.setAccessToken(accessToken);
};

export const getLikedTracks = async (locals: App.Locals) => {
return (
await db.trackReaction.findMany({
where: {
userId: locals.user.id,
liked: true
},
select: {
trackId: true
}
})
).map((r) => r.trackId);
};

export const getPlaylist = async () => {
return (
await db.track.findMany({
where: {
inPlaylist: true
},
select: {
id: true
}
})
).map((track) => track.id);
};

export default spotify;
43 changes: 24 additions & 19 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,40 @@ import markdownItSup from 'markdown-it-sup';
import markdownItIns from 'markdown-it-ins';
import markdownItEmojis from 'markdown-it-emoji';
// @ts-expect-error Geen types
import markdownItArrow from 'markdown-it-smartarrows'
import markdownItArrow from 'markdown-it-smartarrows';
import markdownItKbd from 'markdown-it-kbd';
import markdownItPlainText from 'markdown-it-plain-text'

import xss from 'xss'
import markdownItPlainText from 'markdown-it-plain-text';

import xss from 'xss';

const md = new markdownIt({
linkify: true,
breaks: true
})
.use(markdownItSub)
.use(markdownItSup)
.use(markdownItIns)
.use(markdownItEmojis)
.use(markdownItArrow)
.use(markdownItKbd)
.use(markdownItPlainText)
.disable(['image']);

export function markdown(text: string | null | undefined): string | null {
if (text === null || text === undefined) return null;
return xss(md.renderInline(text))
.use(markdownItSub)
.use(markdownItSup)
.use(markdownItIns)
.use(markdownItEmojis)
.use(markdownItArrow)
.use(markdownItKbd)
.use(markdownItPlainText)
.disable(['image']);

export function markdown(text: string | null | undefined, disableEgg = false): string | null {
if (text === null || text === undefined) return null;
let html = md.renderInline(text);
if (!disableEgg)
html = html.replace(
/paasei/gi,
'<a href="/pasen/gevonden/xkzR2iH1Ut4kwoT8G53vlxFoRQqfZLrKESLO7lFygpSMiPfDk7"><img src="/image/eggs/egg1.png?static=true" alt="paasei" /></a>'
);
return xss(html);
}

export function stripMarkdown(text: string | undefined) {
if (text === null || text === undefined) return null;
md.render(text)
return (md as any).plainText
if (text === null || text === undefined) return null;
md.render(text);
return (md as any).plainText;
}

// Currently in dark mode?
Expand Down
74 changes: 42 additions & 32 deletions src/routes/(app)/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
import type { Committee } from '@prisma/client';
import type { LayoutServerLoad } from './$types';
import { LDAP_IDS } from '$lib/constants';
import { shouldShowEgg } from '$lib/server/egghunt';

export const load = (async ({ locals }) => {
return {
topRole: getTopRole(locals.committees),
};
return {
topRole: getTopRole(locals.committees),
menuEgg: shouldShowEgg('HnSF3i41PdqTzUpvmO7S0RwiB7RA6el5nfRUBAY7IhJVAK0DkT', locals.user.id),
profileEgg: shouldShowEgg('FDaR8VJklWZdZX9qYMabhAJlR9wWWU7gPgagGfZG8AbckOY27T', locals.user.id)
};
}) satisfies LayoutServerLoad;

const ranking = [LDAP_IDS.FEUTEN, LDAP_IDS.SENAAT, LDAP_IDS.ADMINS, LDAP_IDS.FINANCIE, LDAP_IDS.COLOSSEUM, LDAP_IDS.MEMBERS]
const ranking = [
LDAP_IDS.FEUTEN,
LDAP_IDS.SENAAT,
LDAP_IDS.ADMINS,
LDAP_IDS.FINANCIE,
LDAP_IDS.COLOSSEUM,
LDAP_IDS.MEMBERS
];

function getTopRole(committees: Committee[]) {
// Get the best committee where ldapId is lowest in the ranking
let topIdx = ranking.length - 1
let topCommittee = committees[topIdx]
for (const c of committees) {
const index = ranking.indexOf(c.ldapId)
if (index === -1) continue
if (index < topIdx) {
topIdx = index
topCommittee = c
}
}
// Get the best committee where ldapId is lowest in the ranking
let topIdx = ranking.length - 1;
let topCommittee = committees[topIdx];
for (const c of committees) {
const index = ranking.indexOf(c.ldapId);
if (index === -1) continue;
if (index < topIdx) {
topIdx = index;
topCommittee = c;
}
}

switch (topCommittee?.ldapId) {
case LDAP_IDS.FEUTEN:
return 'Feut'
case LDAP_IDS.SENAAT:
return 'Senaat'
case LDAP_IDS.ADMINS:
return 'Admin'
case LDAP_IDS.FINANCIE:
return 'FinanCie'
case LDAP_IDS.COLOSSEUM:
return 'Colosseum-bewoner'
case LDAP_IDS.MEMBERS:
return 'Lid'
default:
return 'Lid'
}
}
switch (topCommittee?.ldapId) {
case LDAP_IDS.FEUTEN:
return 'Feut';
case LDAP_IDS.SENAAT:
return 'Senaat';
case LDAP_IDS.ADMINS:
return 'Admin';
case LDAP_IDS.FINANCIE:
return 'FinanCie';
case LDAP_IDS.COLOSSEUM:
return 'Colosseum-bewoner';
case LDAP_IDS.MEMBERS:
return 'Lid';
default:
return 'Lid';
}
}
7 changes: 5 additions & 2 deletions src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { afterNavigate } from '$app/navigation';
import { Modals, closeModal } from 'svelte-modals';
import MobileMenu from './_mobile-menu.svelte';
import type { LayoutData } from './$types';

afterNavigate(() => {
// Reset scroll position on layout--container-slot
Expand All @@ -22,10 +23,12 @@

let open = false;
const openMenu = () => (open = !open);

export let data: LayoutData;
</script>

<main class="layout--main">
<Navbar {openMenu} {open} />
<Navbar {openMenu} {open} egg={data.menuEgg} />

{#if open}
<div class="layout--mobimenu">
Expand All @@ -40,7 +43,7 @@

<div class="layout--stripe" data-open={open} />

<Topbar />
<Topbar egg={data.profileEgg} />

{#if !open}
<div class="layout--container">
Expand Down
Loading