X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-file.ts;h=3bc4855f38afb2bb5c86cb1adf24a8ed96caf0a6;hb=5cf84858d49f4231cc4efec5e3132f17f65f6cf6;hp=f5a2b6c1f5ef99a4cc3a5381490a6912c37b4b28;hpb=8cd72bd37724054f8942f2fefc7aa2e60eca74cf;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index f5a2b6c1f..3bc4855f3 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts @@ -9,6 +9,7 @@ import { import { CONSTRAINTS_FIELDS } from '../../initializers' import { throwIfNotValid } from '../utils' import { VideoModel } from './video' +import * as Sequelize from 'sequelize' @Table({ tableName: 'videoFile', @@ -68,4 +69,18 @@ export class VideoFileModel extends Model { onDelete: 'CASCADE' }) Video: VideoModel + + 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 + }) + } }