brutalism design

This commit is contained in:
2026-05-22 05:08:02 +06:00
parent abf4d41c23
commit e4ed785911
51 changed files with 940 additions and 1171 deletions

View File

@@ -33,13 +33,12 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
},
})
const session = await fastify.lucia.createSession(user.id, {})
const session = await fastify.lucia.createSession(user.username, {})
const cookie = fastify.lucia.createSessionCookie(session.id)
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
return {
id: user.id,
username: user.username,
displayName: user.username,
createdAt: user.createdAt.toISOString(),
@@ -67,7 +66,6 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
const user = await fastify.prisma.user.findFirst({
where: { username: req.body.username },
select: {
id: true,
username: true,
displayName: true,
createdAt: true,
@@ -84,7 +82,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
return reply.notFound('Incorrect username or password')
}
const session = await fastify.lucia.createSession(user.id, {})
const session = await fastify.lucia.createSession(user.username, {})
const cookie = fastify.lucia.createSessionCookie(session.id)
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
@@ -112,7 +110,6 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
const user = req.user!
return {
id: user.id,
username: user.username,
displayName: user.displayName,
createdAt: user.createdAt.toISOString(),

View File

@@ -41,7 +41,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
const channel = await fastify.prisma.channel.create({
data: {
name: req.body.name,
ownerId: user.id,
ownerUsername: user.username,
persistent: req.body.persistent,
},
})
@@ -73,7 +73,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
try {
const channel = await fastify.prisma.channel.delete({
where: { id: req.params.id, ownerId: user.id },
where: { id: req.params.id, ownerUsername: user.username },
})
fastify.bus.emit('channel:removed', channel)

View File

@@ -1,6 +1,7 @@
import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox'
import { Type } from 'typebox'
import { ChatMessageSchema, NewChatMessagePayloadSchema } from '../plugins/schemas/chat.ts'
import { TypeboxRef } from '../utils/typebox-ref.ts'
const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
fastify.post(
@@ -10,9 +11,9 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
summary: 'Send message',
tags: ['Chat'],
operationId: 'chat.send',
body: NewChatMessagePayloadSchema,
body: TypeboxRef(NewChatMessagePayloadSchema),
response: {
200: ChatMessageSchema,
200: TypeboxRef(ChatMessageSchema),
},
},
},
@@ -22,7 +23,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
const message = await fastify.prisma.message.create({
data: {
text: req.body.text,
senderId: user.id,
senderUsername: user.username,
attachments: {
create: (req.body.attachments ?? []).map((attachmentId) => {
return {
@@ -35,6 +36,13 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
}),
},
},
include: {
attachments: {
include: {
attachment: true,
},
},
},
})
if (!message) {
@@ -43,11 +51,11 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
const response = {
id: message.id,
senderId: user.id,
senderUsername: user.username,
text: message.text,
createdAt: message.createdAt.toISOString(),
updatedAt: message.updatedAt.toISOString(),
attachments: req.body.attachments ?? [],
attachments: message.attachments.map(({ attachment }) => attachment),
}
fastify.bus.emit('chat:new-message', response)
@@ -69,7 +77,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
}),
response: {
200: Type.Object({
messages: Type.Array(ChatMessageSchema),
messages: Type.Array(TypeboxRef(ChatMessageSchema)),
nextCursor: Type.Optional(Type.String({ format: 'uuid', description: 'Cursor to last message' })),
}),
},
@@ -81,7 +89,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
const messages = await fastify.prisma.message.findMany({
orderBy: { createdAt: 'desc' },
take: req.query.limit + 1,
include: { attachments: true },
include: { attachments: { include: { attachment: true } } },
...(req.query.cursor && {
cursor: {
id: req.query.cursor,
@@ -99,7 +107,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
...message,
createdAt: message.createdAt.toISOString(),
updatedAt: message.updatedAt.toISOString(),
attachments: message.attachments.map(({ attachmentId }) => attachmentId),
attachments: message.attachments.map(({ attachment }) => attachment),
}
}),
nextCursor: cursorMessage?.id,

View File

@@ -19,9 +19,8 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
},
async (req, reply) => {
const user = await fastify.prisma.user.findFirst({
where: { username: req.query.username, id: req.query.id },
where: { username: req.query.username },
select: {
id: true,
username: true,
displayName: true,
createdAt: true,
@@ -55,8 +54,8 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
const user = req.user!
const preferences = await fastify.prisma.userPreferences.upsert({
where: { userId: user.id },
create: { userId: user.id },
where: { username: user.username },
create: { username: user.username },
update: {},
})
@@ -81,9 +80,9 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
const user = req.user!
return fastify.prisma.userPreferences.upsert({
where: { userId: user.id },
where: { username: user.username },
create: {
userId: user.id,
username: user.username,
...req.body,
},
update: req.body,
@@ -108,12 +107,11 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
const user = req.user!
const updatedUser = await fastify.prisma.user.update({
where: { id: user.id },
where: { username: user.username },
data: {
displayName: req.body.displayName,
},
select: {
id: true,
username: true,
displayName: true,
createdAt: true,