import * as express from 'express'
-import { buildNSFWFilter } from '../../helpers/express-utils'
+import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
import { getFormattedObjects, getServerActor } from '../../helpers/utils'
import { VideoModel } from '../../models/video/video'
import {
import { VideoChannelsSearchQuery, VideosSearchQuery } from '../../../shared/models/search'
import { getOrCreateActorAndServerAndModel, getOrCreateVideoAndAccountAndChannel } from '../../lib/activitypub'
import { logger } from '../../helpers/logger'
-import { User } from '../../../shared/models/users'
-import { CONFIG } from '../../initializers/constants'
import { VideoChannelModel } from '../../models/video/video-channel'
import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger'
const isURISearch = search.startsWith('http://') || search.startsWith('https://')
const parts = search.split('@')
+
+ // Handle strings like @toto@example.com
+ if (parts.length === 3 && parts[0].length === 0) parts.shift()
const isWebfingerSearch = parts.length === 2 && parts.every(p => p.indexOf(' ') === -1)
if (isURISearch || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res)
if (isUserAbleToSearchRemoteURI(res)) {
try {
- const actor = await getOrCreateActorAndServerAndModel(uri)
+ const actor = await getOrCreateActorAndServerAndModel(uri, 'all', true, true)
videoChannel = actor.VideoChannel
} catch (err) {
logger.info('Cannot search remote video channel %s.', uri, { err })
async function searchVideosDB (query: VideosSearchQuery, res: express.Response) {
const options = Object.assign(query, {
includeLocalVideos: true,
- nsfw: buildNSFWFilter(res, query.nsfw)
+ nsfw: buildNSFWFilter(res, query.nsfw),
+ filter: query.filter,
+ user: res.locals.oauth ? res.locals.oauth.token.User : undefined
})
const resultList = await VideoModel.searchAndPopulateAccountAndServer(options)
refreshVideo: false
}
- const result = await getOrCreateVideoAndAccountAndChannel(url, syncParam)
+ const result = await getOrCreateVideoAndAccountAndChannel({ videoObject: url, syncParam })
video = result ? result.video : undefined
} catch (err) {
logger.info('Cannot search remote video %s.', url, { err })
data: video ? [ video.toFormattedJSON() ] : []
})
}
-
-function isUserAbleToSearchRemoteURI (res: express.Response) {
- const user: User = res.locals.oauth ? res.locals.oauth.token.User : undefined
-
- return CONFIG.SEARCH.REMOTE_URI.ANONYMOUS === true ||
- (CONFIG.SEARCH.REMOTE_URI.USERS === true && user !== undefined)
-}