diff --git a/src/app.d.ts b/src/app.d.ts index e827dee..38cf362 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -26,28 +26,10 @@ declare global { type serviceType = 'jellyfin' | 'youtube-music' - interface Service { - type: serviceType - userId: string - urlOrigin: string - } - - interface Connection { + interface BaseConnection { id: string userId: string - service: Service - accessToken: string - refreshToken?: string - expiry?: number - connectionInfo?: ConnectionInfo - } - - interface ConnectionInfo { - connectionId: string - serviceType: serviceType - username: string - serverName?: string - profilePicture?: string + type: serviceType } // These Schemas should only contain general info data that is necessary for data fetching purposes. @@ -103,6 +85,19 @@ declare global { // The jellyfin API will not always return the data it says it will, for example /Users/AuthenticateByName says it will // retrun the ServerName, it wont. This must be fetched from /System/Info. // So, ONLY DEFINE THE INTERFACES FOR DATA THAT IS GARUNTEED TO BE RETURNED (unless the data value itself is inherently optional) + interface Connection extends BaseConnection { + type: 'jellyfin' + jellyfinUserId: string + urlOrigin: string + accessToken: string + info?: T + } + + interface ConnectionInfo { + username?: string + serverName?: string + } + interface User { Name: string Id: string @@ -168,7 +163,19 @@ declare global { } } - namespace YouTubeMusic {} + namespace YouTubeMusic { + interface Connection extends BaseConnection { + type: 'youtube-music' + youtubeUserId: string + accessToken: string + info?: T + } + + interface ConnectionInfo { + username?: string + profilePicture?: string + } + } } export {} diff --git a/src/lib/server/users.ts b/src/lib/server/users.ts index bdf4f85..c3da22a 100644 --- a/src/lib/server/users.ts +++ b/src/lib/server/users.ts @@ -73,6 +73,14 @@ export class Connections { static addConnection = (userId: string, service: Service, accessToken: string, refreshToken?: string, expiry?: number): Connection => { const connectionId = generateUUID() + const ytConnection: YouTubeMusic.Connection = { + id: 'test', + userId: 'test', + youtubeUserId: 'test', + type: 'youtube-music', + accessToken: 'test', + } + const test = this.insertConnection(ytConnection) if (!isValidURL(service.urlOrigin)) throw new Error('Service does not have valid url') db.prepare('INSERT INTO Connections(id, userId, service, accessToken, refreshToken, expiry) VALUES(?, ?, ?, ?, ?, ?)').run(connectionId, userId, JSON.stringify(service), accessToken, refreshToken, expiry) return this.getConnection(connectionId)