ACTIVITY_PUB,
API_VERSION,
CONSTRAINTS_FIELDS,
- HLS_REDUNDANCY_DIRECTORY,
- HLS_STREAMING_PLAYLIST_DIRECTORY,
LAZY_STATIC_PATHS,
REMOTE_SCHEME,
STATIC_DOWNLOAD_PATHS,
import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file'
import { MThumbnail } from '../../typings/models/video/thumbnail'
import { VideoFile } from '@shared/models/videos/video-file.model'
-import { getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath, getHLSDirectory } from '@server/lib/video-paths'
+import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
+import * as validator from 'validator'
// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [
const escapedSearch = VideoModel.sequelize.escape(options.search)
const escapedLikeSearch = VideoModel.sequelize.escape('%' + options.search + '%')
if (options.search) {
- whereAnd.push(
- {
- id: {
- [ Op.in ]: Sequelize.literal(
- '(' +
- 'SELECT "video"."id" FROM "video" ' +
- 'WHERE ' +
- 'lower(immutable_unaccent("video"."name")) % lower(immutable_unaccent(' + escapedSearch + ')) OR ' +
- 'lower(immutable_unaccent("video"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))' +
- 'UNION ALL ' +
- 'SELECT "video"."id" FROM "video" LEFT JOIN "videoTag" ON "videoTag"."videoId" = "video"."id" ' +
- 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
- 'WHERE "tag"."name" = ' + escapedSearch +
- ')'
- )
- }
+ const trigramSearch = {
+ id: {
+ [ Op.in ]: Sequelize.literal(
+ '(' +
+ 'SELECT "video"."id" FROM "video" ' +
+ 'WHERE ' +
+ 'lower(immutable_unaccent("video"."name")) % lower(immutable_unaccent(' + escapedSearch + ')) OR ' +
+ 'lower(immutable_unaccent("video"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))' +
+ 'UNION ALL ' +
+ 'SELECT "video"."id" FROM "video" LEFT JOIN "videoTag" ON "videoTag"."videoId" = "video"."id" ' +
+ 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
+ 'WHERE "tag"."name" = ' + escapedSearch +
+ ')'
+ )
}
- )
+ }
+
+ if (validator.isUUID(options.search)) {
+ whereAnd.push({
+ [Op.or]: [
+ trigramSearch,
+ {
+ uuid: options.search
+ }
+ ]
+ })
+ } else {
+ whereAnd.push(trigramSearch)
+ }
attributesInclude.push(createSimilarityAttribute('VideoModel.name', options.search))
}
describe('Test videos search', function () {
let server: ServerInfo = null
let startDate: string
+ let videoUUID: string
before(async function () {
this.timeout(30000)
const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined })
const res = await uploadVideo(server.url, server.accessToken, attributes3)
const videoId = res.body.video.id
+ videoUUID = res.body.video.uuid
await createVideoCaption({
url: server.url,
}
})
+ it('Should search by UUID', async function () {
+ const search = videoUUID
+ const res = await advancedVideosSearch(server.url, { search })
+
+ expect(res.body.total).to.equal(1)
+ expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3')
+ })
+
after(async function () {
await cleanupTests([ server ])
})