Refactor options in models
This commit is contained in:
parent
56d07460b5
commit
9c9a236b54
3 changed files with 82 additions and 110 deletions
|
@ -438,8 +438,28 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static listForApi (parameters: {
|
static listLocalsForSitemap (sort: string): Promise<MChannelActor[]> {
|
||||||
actorId: number
|
const query = {
|
||||||
|
attributes: [ ],
|
||||||
|
offset: 0,
|
||||||
|
order: getSort(sort),
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
attributes: [ 'preferredUsername', 'serverId' ],
|
||||||
|
model: ActorModel.unscoped(),
|
||||||
|
where: {
|
||||||
|
serverId: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return VideoChannelModel
|
||||||
|
.unscoped()
|
||||||
|
.findAll(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
static listForApi (parameters: Pick<AvailableForListOptions, 'actorId'> & {
|
||||||
start: number
|
start: number
|
||||||
count: number
|
count: number
|
||||||
sort: string
|
sort: string
|
||||||
|
@ -462,36 +482,10 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static listLocalsForSitemap (sort: string): Promise<MChannelActor[]> {
|
static searchForApi (options: Pick<AvailableForListOptions, 'actorId' | 'search' | 'host' | 'handles'> & {
|
||||||
const query = {
|
|
||||||
attributes: [ ],
|
|
||||||
offset: 0,
|
|
||||||
order: getSort(sort),
|
|
||||||
include: [
|
|
||||||
{
|
|
||||||
attributes: [ 'preferredUsername', 'serverId' ],
|
|
||||||
model: ActorModel.unscoped(),
|
|
||||||
where: {
|
|
||||||
serverId: null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
return VideoChannelModel
|
|
||||||
.unscoped()
|
|
||||||
.findAll(query)
|
|
||||||
}
|
|
||||||
|
|
||||||
static searchForApi (options: {
|
|
||||||
actorId: number
|
|
||||||
search?: string
|
|
||||||
start: number
|
start: number
|
||||||
count: number
|
count: number
|
||||||
sort: string
|
sort: string
|
||||||
|
|
||||||
host?: string
|
|
||||||
handles?: string[]
|
|
||||||
}) {
|
}) {
|
||||||
let attributesInclude: any[] = [ literal('0 as similarity') ]
|
let attributesInclude: any[] = [ literal('0 as similarity') ]
|
||||||
let where: WhereOptions
|
let where: WhereOptions
|
||||||
|
|
|
@ -19,7 +19,7 @@ import {
|
||||||
} from 'sequelize-typescript'
|
} from 'sequelize-typescript'
|
||||||
import { buildUUID, uuidToShort } from '@server/helpers/uuid'
|
import { buildUUID, uuidToShort } from '@server/helpers/uuid'
|
||||||
import { MAccountId, MChannelId } from '@server/types/models'
|
import { MAccountId, MChannelId } from '@server/types/models'
|
||||||
import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath } from '@shared/core-utils'
|
import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath, pick } from '@shared/core-utils'
|
||||||
import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
|
import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
|
||||||
import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object'
|
import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object'
|
||||||
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
|
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
|
||||||
|
@ -357,19 +357,10 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli
|
||||||
})
|
})
|
||||||
Thumbnail: ThumbnailModel
|
Thumbnail: ThumbnailModel
|
||||||
|
|
||||||
static listForApi (options: {
|
static listForApi (options: AvailableForListOptions & {
|
||||||
followerActorId: number
|
|
||||||
start: number
|
start: number
|
||||||
count: number
|
count: number
|
||||||
sort: string
|
sort: string
|
||||||
type?: VideoPlaylistType
|
|
||||||
accountId?: number
|
|
||||||
videoChannelId?: number
|
|
||||||
listMyPlaylists?: boolean
|
|
||||||
search?: string
|
|
||||||
host?: string
|
|
||||||
uuids?: string[]
|
|
||||||
withVideos?: boolean // false by default
|
|
||||||
}) {
|
}) {
|
||||||
const query = {
|
const query = {
|
||||||
offset: options.start,
|
offset: options.start,
|
||||||
|
@ -382,14 +373,8 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli
|
||||||
method: [
|
method: [
|
||||||
ScopeNames.AVAILABLE_FOR_LIST,
|
ScopeNames.AVAILABLE_FOR_LIST,
|
||||||
{
|
{
|
||||||
type: options.type,
|
...pick(options, [ 'type', 'followerActorId', 'accountId', 'videoChannelId', 'listMyPlaylists', 'search', 'host', 'uuids' ]),
|
||||||
followerActorId: options.followerActorId,
|
|
||||||
accountId: options.accountId,
|
|
||||||
videoChannelId: options.videoChannelId,
|
|
||||||
listMyPlaylists: options.listMyPlaylists,
|
|
||||||
search: options.search,
|
|
||||||
host: options.host,
|
|
||||||
uuids: options.uuids,
|
|
||||||
withVideos: options.withVideos || false
|
withVideos: options.withVideos || false
|
||||||
} as AvailableForListOptions
|
} as AvailableForListOptions
|
||||||
]
|
]
|
||||||
|
@ -406,17 +391,14 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static searchForApi (options: {
|
static searchForApi (options: Pick<AvailableForListOptions, 'followerActorId' | 'search'| 'host'| 'uuids'> & {
|
||||||
followerActorId: number
|
|
||||||
start: number
|
start: number
|
||||||
count: number
|
count: number
|
||||||
sort: string
|
sort: string
|
||||||
search?: string
|
|
||||||
host?: string
|
|
||||||
uuids?: string[]
|
|
||||||
}) {
|
}) {
|
||||||
return VideoPlaylistModel.listForApi({
|
return VideoPlaylistModel.listForApi({
|
||||||
...options,
|
...options,
|
||||||
|
|
||||||
type: VideoPlaylistType.REGULAR,
|
type: VideoPlaylistType.REGULAR,
|
||||||
listMyPlaylists: false,
|
listMyPlaylists: false,
|
||||||
withVideos: true
|
withVideos: true
|
||||||
|
|
|
@ -31,7 +31,7 @@ import { LiveManager } from '@server/lib/live/live-manager'
|
||||||
import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths'
|
import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths'
|
||||||
import { getServerActor } from '@server/models/application/application'
|
import { getServerActor } from '@server/models/application/application'
|
||||||
import { ModelCache } from '@server/models/model-cache'
|
import { ModelCache } from '@server/models/model-cache'
|
||||||
import { AttributesOnly, buildVideoEmbedPath, buildVideoWatchPath } from '@shared/core-utils'
|
import { AttributesOnly, buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils'
|
||||||
import { VideoFile } from '@shared/models/videos/video-file.model'
|
import { VideoFile } from '@shared/models/videos/video-file.model'
|
||||||
import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared'
|
import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared'
|
||||||
import { VideoObject } from '../../../shared/models/activitypub/objects'
|
import { VideoObject } from '../../../shared/models/activitypub/objects'
|
||||||
|
@ -1083,41 +1083,44 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
|
||||||
: serverActor.id
|
: serverActor.id
|
||||||
|
|
||||||
const queryOptions = {
|
const queryOptions = {
|
||||||
start: options.start,
|
...pick(options, [
|
||||||
count: options.count,
|
'start',
|
||||||
sort: options.sort,
|
'count',
|
||||||
|
'sort',
|
||||||
|
'nsfw',
|
||||||
|
'isLive',
|
||||||
|
'categoryOneOf',
|
||||||
|
'licenceOneOf',
|
||||||
|
'languageOneOf',
|
||||||
|
'tagsOneOf',
|
||||||
|
'tagsAllOf',
|
||||||
|
'filter',
|
||||||
|
'withFiles',
|
||||||
|
'accountId',
|
||||||
|
'videoChannelId',
|
||||||
|
'videoPlaylistId',
|
||||||
|
'includeLocalVideos',
|
||||||
|
'user',
|
||||||
|
'historyOfUser',
|
||||||
|
'search'
|
||||||
|
]),
|
||||||
|
|
||||||
followerActorId,
|
followerActorId,
|
||||||
serverAccountId: serverActor.Account.id,
|
serverAccountId: serverActor.Account.id,
|
||||||
nsfw: options.nsfw,
|
|
||||||
isLive: options.isLive,
|
|
||||||
categoryOneOf: options.categoryOneOf,
|
|
||||||
licenceOneOf: options.licenceOneOf,
|
|
||||||
languageOneOf: options.languageOneOf,
|
|
||||||
tagsOneOf: options.tagsOneOf,
|
|
||||||
tagsAllOf: options.tagsAllOf,
|
|
||||||
filter: options.filter,
|
|
||||||
withFiles: options.withFiles,
|
|
||||||
accountId: options.accountId,
|
|
||||||
videoChannelId: options.videoChannelId,
|
|
||||||
videoPlaylistId: options.videoPlaylistId,
|
|
||||||
includeLocalVideos: options.includeLocalVideos,
|
|
||||||
user: options.user,
|
|
||||||
historyOfUser: options.historyOfUser,
|
|
||||||
trendingDays,
|
trendingDays,
|
||||||
trendingAlgorithm,
|
trendingAlgorithm
|
||||||
search: options.search
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return VideoModel.getAvailableForApi(queryOptions, options.countVideos)
|
return VideoModel.getAvailableForApi(queryOptions, options.countVideos)
|
||||||
}
|
}
|
||||||
|
|
||||||
static async searchAndPopulateAccountAndServer (options: {
|
static async searchAndPopulateAccountAndServer (options: {
|
||||||
|
start: number
|
||||||
|
count: number
|
||||||
|
sort: string
|
||||||
includeLocalVideos: boolean
|
includeLocalVideos: boolean
|
||||||
search?: string
|
search?: string
|
||||||
host?: string
|
host?: string
|
||||||
start?: number
|
|
||||||
count?: number
|
|
||||||
sort?: string
|
|
||||||
startDate?: string // ISO 8601
|
startDate?: string // ISO 8601
|
||||||
endDate?: string // ISO 8601
|
endDate?: string // ISO 8601
|
||||||
originallyPublishedStartDate?: string
|
originallyPublishedStartDate?: string
|
||||||
|
@ -1138,40 +1141,33 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
|
||||||
const serverActor = await getServerActor()
|
const serverActor = await getServerActor()
|
||||||
|
|
||||||
const queryOptions = {
|
const queryOptions = {
|
||||||
|
...pick(options, [
|
||||||
|
'includeLocalVideos',
|
||||||
|
'nsfw',
|
||||||
|
'isLive',
|
||||||
|
'categoryOneOf',
|
||||||
|
'licenceOneOf',
|
||||||
|
'languageOneOf',
|
||||||
|
'tagsOneOf',
|
||||||
|
'tagsAllOf',
|
||||||
|
'user',
|
||||||
|
'filter',
|
||||||
|
'host',
|
||||||
|
'start',
|
||||||
|
'count',
|
||||||
|
'sort',
|
||||||
|
'startDate',
|
||||||
|
'endDate',
|
||||||
|
'originallyPublishedStartDate',
|
||||||
|
'originallyPublishedEndDate',
|
||||||
|
'durationMin',
|
||||||
|
'durationMax',
|
||||||
|
'uuids',
|
||||||
|
'search'
|
||||||
|
]),
|
||||||
|
|
||||||
followerActorId: serverActor.id,
|
followerActorId: serverActor.id,
|
||||||
serverAccountId: serverActor.Account.id,
|
serverAccountId: serverActor.Account.id
|
||||||
|
|
||||||
includeLocalVideos: options.includeLocalVideos,
|
|
||||||
nsfw: options.nsfw,
|
|
||||||
isLive: options.isLive,
|
|
||||||
|
|
||||||
categoryOneOf: options.categoryOneOf,
|
|
||||||
licenceOneOf: options.licenceOneOf,
|
|
||||||
languageOneOf: options.languageOneOf,
|
|
||||||
|
|
||||||
tagsOneOf: options.tagsOneOf,
|
|
||||||
tagsAllOf: options.tagsAllOf,
|
|
||||||
|
|
||||||
user: options.user,
|
|
||||||
filter: options.filter,
|
|
||||||
host: options.host,
|
|
||||||
|
|
||||||
start: options.start,
|
|
||||||
count: options.count,
|
|
||||||
sort: options.sort,
|
|
||||||
|
|
||||||
startDate: options.startDate,
|
|
||||||
endDate: options.endDate,
|
|
||||||
|
|
||||||
originallyPublishedStartDate: options.originallyPublishedStartDate,
|
|
||||||
originallyPublishedEndDate: options.originallyPublishedEndDate,
|
|
||||||
|
|
||||||
durationMin: options.durationMin,
|
|
||||||
durationMax: options.durationMax,
|
|
||||||
|
|
||||||
uuids: options.uuids,
|
|
||||||
|
|
||||||
search: options.search
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return VideoModel.getAvailableForApi(queryOptions)
|
return VideoModel.getAvailableForApi(queryOptions)
|
||||||
|
|
Loading…
Reference in a new issue