Changed the DB schema AGAIN
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Services, Connections } from '$lib/server/users'
|
||||
import { Connections } from '$lib/server/users'
|
||||
import { isValidURL } from '$lib/utils'
|
||||
import type { RequestHandler } from '@sveltejs/kit'
|
||||
import { z } from 'zod'
|
||||
@@ -13,10 +13,8 @@ export const GET: RequestHandler = async ({ params }) => {
|
||||
const connectionSchema = z.object({
|
||||
serviceType: z.enum(['jellyfin', 'youtube-music']),
|
||||
serviceUserId: z.string(),
|
||||
url: z.string().refine((val) => isValidURL(val)),
|
||||
urlOrigin: z.string().refine((val) => isValidURL(val)),
|
||||
accessToken: z.string(),
|
||||
refreshToken: z.string().nullable().optional(),
|
||||
expiry: z.number().nullable().optional(),
|
||||
})
|
||||
export type NewConnection = z.infer<typeof connectionSchema>
|
||||
|
||||
@@ -28,9 +26,13 @@ export const POST: RequestHandler = async ({ params, request }) => {
|
||||
const connectionValidation = connectionSchema.safeParse(connection)
|
||||
if (!connectionValidation.success) return new Response(connectionValidation.error.message, { status: 400 })
|
||||
|
||||
const { serviceType, serviceUserId, url, accessToken, refreshToken, expiry } = connectionValidation.data
|
||||
const newService = Services.addService(serviceType as ServiceType, serviceUserId, new URL(url))
|
||||
const newConnection = Connections.addConnection(userId, newService.id, accessToken, refreshToken as string | null, expiry as number | null)
|
||||
const { serviceType, serviceUserId, urlOrigin, accessToken } = connectionValidation.data
|
||||
const service: Service = {
|
||||
type: serviceType,
|
||||
userId: serviceUserId,
|
||||
urlOrigin: new URL(urlOrigin).origin,
|
||||
}
|
||||
const newConnection = Connections.addConnection(userId, service, accessToken)
|
||||
return new Response(JSON.stringify(newConnection))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user