+ Video: VideoModel
+
+ @HasMany(() => VideoRedundancyModel, {
+ foreignKey: {
+ allowNull: false
+ },
+ onDelete: 'CASCADE',
+ hooks: true
+ })
+ RedundancyVideos: VideoRedundancyModel[]
+
+ static isInfohashExists (infoHash: string) {
+ const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1'
+ const options = {
+ type: Sequelize.QueryTypes.SELECT,
+ bind: { infoHash },
+ raw: true
+ }
+
+ return VideoModel.sequelize.query(query, options)
+ .then(results => {
+ return results.length === 1
+ })
+ }
+
+ static loadWithVideo (id: number) {
+ const options = {
+ include: [
+ {
+ model: VideoModel.unscoped(),
+ required: true
+ }
+ ]
+ }
+
+ return VideoFileModel.findById(id, options)
+ }
+
+ static async getStats () {
+ let totalLocalVideoFilesSize = await VideoFileModel.sum('size', {
+ include: [
+ {
+ attributes: [],
+ model: VideoModel.unscoped(),
+ where: {
+ remote: false
+ }
+ }
+ ]
+ } as any)
+ // Sequelize could return null...
+ if (!totalLocalVideoFilesSize) totalLocalVideoFilesSize = 0