followerActorId: number
includeLocalVideos: boolean
+ withoutId?: boolean
+
filter?: VideoFilter
categoryOneOf?: number[]
nsfw?: boolean
{
model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }),
required: true
+ },
+ {
+ attributes: [ 'type', 'filename' ],
+ model: ThumbnailModel,
+ required: false
}
]
}
return query
},
[ ScopeNames.AVAILABLE_FOR_LIST_IDS ]: (options: AvailableForListIDsOptions) => {
+ const attributes = options.withoutId === true ? [] : [ 'id' ]
+
const query: FindOptions = {
raw: true,
- attributes: [ 'id' ],
+ attributes,
where: {
id: {
[ Op.and ]: [
const countQuery = buildBaseQuery()
const findQuery = buildBaseQuery()
- findQuery.include.push({
- model: ScheduleVideoUpdateModel,
- required: false
- })
-
- findQuery.include.push({
- model: VideoBlacklistModel,
- required: false
- })
+ const findScopes = [
+ ScopeNames.WITH_SCHEDULED_UPDATE,
+ ScopeNames.WITH_BLACKLISTED,
+ ScopeNames.WITH_THUMBNAILS
+ ]
if (withFiles === true) {
findQuery.include.push({
return Promise.all([
VideoModel.count(countQuery),
- VideoModel.findAll(findQuery)
+ VideoModel.scope(findScopes).findAll(findQuery)
]).then(([ count, rows ]) => {
return {
data: rows,
.then(results => results.length === 1)
}
+ static bulkUpdateSupportField (videoChannel: VideoChannelModel, t: Transaction) {
+ const options = {
+ where: {
+ channelId: videoChannel.id
+ },
+ transaction: t
+ }
+
+ return VideoModel.update({ support: videoChannel.support }, options)
+ }
+
+ static getAllIdsFromChannel (videoChannel: VideoChannelModel) {
+ const query = {
+ attributes: [ 'id' ],
+ where: {
+ channelId: videoChannel.id
+ }
+ }
+
+ return VideoModel.findAll(query)
+ .then(videos => videos.map(v => v.id))
+ }
+
// threshold corresponds to how many video the field should have to be returned
static async getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) {
const serverActor = await getServerActor()
const scopeOptions: AvailableForListIDsOptions = {
serverAccountId: serverActor.Account.id,
followerActorId,
- includeLocalVideos: true
+ includeLocalVideos: true,
+ withoutId: true // Don't break aggregation
}
const query: FindOptions = {
]
}
- const apiScope: (string | ScopeOptions)[] = [ ScopeNames.WITH_THUMBNAILS ]
+ const apiScope: (string | ScopeOptions)[] = []
if (options.user) {
apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] })