mirror of
https://github.com/ArthurDanjou/website.git
synced 2026-01-25 09:20:32 +01:00
Remove trpc and use H3 instead
This commit is contained in:
7
src/auth.d.ts
vendored
Normal file
7
src/auth.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
declare module '#auth-utils' {
|
||||||
|
interface UserSession {
|
||||||
|
user: {
|
||||||
|
username: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
src/pages/guestbook.vue
Normal file
64
src/pages/guestbook.vue
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
useHead({
|
||||||
|
title: 'Sign my guestbook • Arthur Danjou',
|
||||||
|
})
|
||||||
|
|
||||||
|
const providers = [
|
||||||
|
{
|
||||||
|
slug: 'github',
|
||||||
|
label: 'Use Github',
|
||||||
|
icon: 'i-ph-github-logo-bold',
|
||||||
|
link: '/api/auth/github',
|
||||||
|
color: 'black',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
slug: 'twitter',
|
||||||
|
label: 'Use Twitter',
|
||||||
|
icon: 'i-ph-twitter-logo-bold',
|
||||||
|
link: '/api/auth/twitter',
|
||||||
|
color: 'cyan',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
slug: 'google',
|
||||||
|
label: 'Use Google',
|
||||||
|
icon: 'i-ph-google-logo-bold',
|
||||||
|
link: '/api/auth/google',
|
||||||
|
color: 'red',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="w-container lg:my-24 my-16">
|
||||||
|
<div class="max-w-2xl space-y-8 mb-16">
|
||||||
|
<h1 class="text-4xl font-bold tracking-tight text-zinc-800 dark:text-zinc-100 sm:text-5xl !leading-tight">
|
||||||
|
You want to leave a message ?
|
||||||
|
</h1>
|
||||||
|
<p class="leading-relaxed text-subtitle">
|
||||||
|
Your opinion means a lot to me. Feel free to share your impressions of my projects, explore my site, or simply leave a personalised message. Your comments are a source of inspiration and continuous improvement. Thank you for taking the time to contribute to this virtual community. I look forward to reading what you have to share!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="my-12 flex flex-col rounded-2xl border border-zinc-100 p-6 dark:border-zinc-700/40">
|
||||||
|
<div class="flex items-center gap-2 mb-4">
|
||||||
|
<UIcon name="i-ph-circle-wavy-question-bold" class="text-subtitle text-xl" />
|
||||||
|
<h1 class="text-lg font-bold">
|
||||||
|
Login to sign my book
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<UButton
|
||||||
|
v-for="provider in providers"
|
||||||
|
:key="provider.slug"
|
||||||
|
:label="provider.label"
|
||||||
|
:color="provider.color"
|
||||||
|
variant="solid"
|
||||||
|
:icon="provider.icon"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
||||||
7
src/server/api/announcement.get.ts
Normal file
7
src/server/api/announcement.get.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export default defineEventHandler(() => {
|
||||||
|
return usePrisma().announcement.findFirst({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: 'desc',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
16
src/server/api/article.post.ts
Normal file
16
src/server/api/article.post.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
const PostSchema = z.object({ slug: z.string() }).parse
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const { slug } = await readValidatedBody(event, PostSchema)
|
||||||
|
return usePrisma().post.upsert({
|
||||||
|
where: {
|
||||||
|
slug,
|
||||||
|
},
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
slug,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
3
src/server/api/categories.get.ts
Normal file
3
src/server/api/categories.get.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export default defineEventHandler(async () => {
|
||||||
|
return await usePrisma().category.findMany()
|
||||||
|
})
|
||||||
17
src/server/api/like.put.ts
Normal file
17
src/server/api/like.put.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
const PostSchema = z.object({ slug: z.string() }).parse
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const { slug } = await readValidatedBody(event, PostSchema)
|
||||||
|
return usePrisma().post.update({
|
||||||
|
where: {
|
||||||
|
slug,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
likes: {
|
||||||
|
increment: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
23
src/server/api/maintenance.get.ts
Normal file
23
src/server/api/maintenance.get.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
export default defineEventHandler(async () => {
|
||||||
|
const maintenance = await usePrisma().maintenance.findFirst({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: 'desc',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
let enabled = true
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const today = new Date()
|
||||||
|
enabled = !!maintenance
|
||||||
|
&& maintenance.enabled
|
||||||
|
&& maintenance.beginAt.getTime() < today.getTime()
|
||||||
|
&& maintenance.endAt.getTime() > today.getTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
enabled,
|
||||||
|
maintenance,
|
||||||
|
}
|
||||||
|
})
|
||||||
11
src/server/api/suggestion.post.ts
Normal file
11
src/server/api/suggestion.post.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
const SuggestionValidator = z.object({
|
||||||
|
author: z.string().trim(),
|
||||||
|
content: z.string(),
|
||||||
|
}).parse
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const { author, content } = await getValidatedQuery(event, SuggestionValidator)
|
||||||
|
const { user } = await requireUserSession(event)
|
||||||
|
})
|
||||||
47
src/server/api/talents.get.ts
Normal file
47
src/server/api/talents.get.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const { favorite, category } = getQuery(event)
|
||||||
|
const prisma = usePrisma()
|
||||||
|
|
||||||
|
let whereClause: any
|
||||||
|
|
||||||
|
if (favorite === 'true') {
|
||||||
|
category === 'all'
|
||||||
|
? whereClause = {
|
||||||
|
favorite: true,
|
||||||
|
categories: { every: { category: {} } },
|
||||||
|
}
|
||||||
|
: whereClause = {
|
||||||
|
favorite: true,
|
||||||
|
categories: { some: { category: { slug: category } } },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
category === 'all'
|
||||||
|
? whereClause = {
|
||||||
|
categories: { every: { category: {} } },
|
||||||
|
}
|
||||||
|
: whereClause = {
|
||||||
|
categories: { some: { category: { slug: category } } },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return await prisma.talent.findMany({
|
||||||
|
where: whereClause,
|
||||||
|
orderBy: {
|
||||||
|
createdAt: 'desc',
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
categories: {
|
||||||
|
include: {
|
||||||
|
talent: true,
|
||||||
|
category: true,
|
||||||
|
},
|
||||||
|
orderBy: {
|
||||||
|
category: {
|
||||||
|
name: 'asc',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
17
src/server/api/view.put.ts
Normal file
17
src/server/api/view.put.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
const PostSchema = z.object({ slug: z.string() }).parse
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const { slug } = await readValidatedBody(event, PostSchema)
|
||||||
|
return usePrisma().post.update({
|
||||||
|
where: {
|
||||||
|
slug,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
views: {
|
||||||
|
increment: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
13
src/server/utils/prisma.ts
Normal file
13
src/server/utils/prisma.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { PrismaClient } from '@prisma/client'
|
||||||
|
|
||||||
|
let prisma: PrismaClient | undefined
|
||||||
|
|
||||||
|
export function usePrisma() {
|
||||||
|
if (!prisma) {
|
||||||
|
prisma = new PrismaClient({
|
||||||
|
log: ['warn', 'info', 'error'],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return prisma
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user