Things broken, implement new types
This commit is contained in:
49
src/app.d.ts
vendored
49
src/app.d.ts
vendored
@@ -26,28 +26,10 @@ declare global {
|
|||||||
|
|
||||||
type serviceType = 'jellyfin' | 'youtube-music'
|
type serviceType = 'jellyfin' | 'youtube-music'
|
||||||
|
|
||||||
interface Service {
|
interface BaseConnection {
|
||||||
type: serviceType
|
|
||||||
userId: string
|
|
||||||
urlOrigin: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Connection {
|
|
||||||
id: string
|
id: string
|
||||||
userId: string
|
userId: string
|
||||||
service: Service
|
type: serviceType
|
||||||
accessToken: string
|
|
||||||
refreshToken?: string
|
|
||||||
expiry?: number
|
|
||||||
connectionInfo?: ConnectionInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ConnectionInfo {
|
|
||||||
connectionId: string
|
|
||||||
serviceType: serviceType
|
|
||||||
username: string
|
|
||||||
serverName?: string
|
|
||||||
profilePicture?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// These Schemas should only contain general info data that is necessary for data fetching purposes.
|
// 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
|
// 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.
|
// 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)
|
// So, ONLY DEFINE THE INTERFACES FOR DATA THAT IS GARUNTEED TO BE RETURNED (unless the data value itself is inherently optional)
|
||||||
|
interface Connection<T = undefined> extends BaseConnection {
|
||||||
|
type: 'jellyfin'
|
||||||
|
jellyfinUserId: string
|
||||||
|
urlOrigin: string
|
||||||
|
accessToken: string
|
||||||
|
info?: T
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConnectionInfo {
|
||||||
|
username?: string
|
||||||
|
serverName?: string
|
||||||
|
}
|
||||||
|
|
||||||
interface User {
|
interface User {
|
||||||
Name: string
|
Name: string
|
||||||
Id: string
|
Id: string
|
||||||
@@ -168,7 +163,19 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace YouTubeMusic {}
|
namespace YouTubeMusic {
|
||||||
|
interface Connection<T = undefined> extends BaseConnection {
|
||||||
|
type: 'youtube-music'
|
||||||
|
youtubeUserId: string
|
||||||
|
accessToken: string
|
||||||
|
info?: T
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConnectionInfo {
|
||||||
|
username?: string
|
||||||
|
profilePicture?: string
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {}
|
export {}
|
||||||
|
|||||||
@@ -73,6 +73,14 @@ export class Connections {
|
|||||||
|
|
||||||
static addConnection = (userId: string, service: Service, accessToken: string, refreshToken?: string, expiry?: number): Connection => {
|
static addConnection = (userId: string, service: Service, accessToken: string, refreshToken?: string, expiry?: number): Connection => {
|
||||||
const connectionId = generateUUID()
|
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')
|
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)
|
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)
|
return this.getConnection(connectionId)
|
||||||
|
|||||||
Reference in New Issue
Block a user