1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 17:59:37 +02:00
Peertube/server/core/models/oauth/oauth-client.ts
Chocobozzz 13bceb5f40
Better thumbnail error handling
* Had to upgrade to es2022 to use `cause` error
 * Had to declare class attributes with declare for sequelize models, so
   it still works as before
2025-07-25 17:01:36 +02:00

62 lines
1.3 KiB
TypeScript

import { AllowNull, Column, CreatedAt, DataType, HasMany, Table, UpdatedAt } from 'sequelize-typescript'
import { OAuthTokenModel } from './oauth-token.js'
import { SequelizeModel } from '../shared/index.js'
@Table({
tableName: 'oAuthClient',
indexes: [
{
fields: [ 'clientId' ],
unique: true
},
{
fields: [ 'clientId', 'clientSecret' ],
unique: true
}
]
})
export class OAuthClientModel extends SequelizeModel<OAuthClientModel> {
@AllowNull(false)
@Column
declare clientId: string
@AllowNull(false)
@Column
declare clientSecret: string
@Column(DataType.ARRAY(DataType.STRING))
declare grants: string[]
@Column(DataType.ARRAY(DataType.STRING))
declare redirectUris: string[]
@CreatedAt
declare createdAt: Date
@UpdatedAt
declare updatedAt: Date
@HasMany(() => OAuthTokenModel, {
onDelete: 'cascade'
})
declare OAuthTokens: Awaited<OAuthTokenModel>[]
static countTotal () {
return OAuthClientModel.count()
}
static loadFirstClient () {
return OAuthClientModel.findOne()
}
static getByIdAndSecret (clientId: string, clientSecret: string) {
const query = {
where: {
clientId,
clientSecret
}
}
return OAuthClientModel.findOne(query)
}
}