From cc43831a90ab8b1b460cd7021c100190049ec64b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 14 Aug 2018 11:00:03 +0200 Subject: Filter tracker based on infohash --- server/models/video/video-file.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'server/models/video/video-file.ts') 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 + }) + } } -- cgit v1.2.3