"reflect-metadata": "^0.1.12",
"request": "^2.81.0",
"scripty": "^1.5.0",
- "sequelize": "4.42.0",
- "sequelize-typescript": "0.6.7",
+ "sequelize": "5.6.1",
+ "sequelize-typescript": "^1.0.0-beta.1",
"sharp": "^0.22.0",
"sitemap": "^2.1.0",
"socket.io": "^2.2.0",
import { JobQueue } from '../../../lib/job-queue/job-queue'
import { join } from 'path'
import { isArray } from '../../../helpers/custom-validators/misc'
-import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
import { VideoChannelModel } from '../../../models/video/video-channel'
import * as Bluebird from 'bluebird'
import * as parseTorrent from 'parse-torrent'
previewModel: ThumbnailModel,
videoChannel: VideoChannelModel,
tags: string[],
- videoImportAttributes: FilteredModelAttributes<VideoImportModel>
+ videoImportAttributes: Partial<VideoImportModel>
}): Bluebird<VideoImportModel> {
let { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes } = parameters
if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled)
if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) {
- videoInstance.set('originallyPublishedAt', videoInfoToUpdate.originallyPublishedAt)
+ videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt)
}
if (videoInfoToUpdate.privacy !== undefined) {
const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
- videoInstance.set('privacy', newPrivacy)
+ videoInstance.privacy = newPrivacy
if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) {
- videoInstance.set('publishedAt', new Date())
+ videoInstance.publishedAt = new Date()
}
}
const obj = baseInstance.toJSON()
for (const key of Object.keys(obj)) {
- instanceToUpdate.set(key, obj[key])
+ instanceToUpdate[key] = obj[key]
}
}
function resetSequelizeInstance (instance: Model<any>, savedFields: object) {
Object.keys(savedFields).forEach(key => {
- const value = savedFields[key]
- instance.set(key, value)
+ instance[key] = savedFields[key]
})
}
import { VideoPlaylistModel } from '../models/video/video-playlist'
import { VideoPlaylistElementModel } from '../models/video/video-playlist-element'
import { ThumbnailModel } from '../models/video/thumbnail'
+import { QueryTypes, Transaction } from 'sequelize'
require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string
max: poolMax
},
benchmark: isTestInstance(),
- isolationLevel: SequelizeTypescript.Transaction.ISOLATION_LEVELS.SERIALIZABLE,
- operatorsAliases: false,
+ isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE,
logging: (message: string, benchmark: number) => {
if (process.env.NODE_DB_LOG === 'false') return
async function checkPostgresExtension (extension: string) {
const query = `SELECT true AS enabled FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;`
- const [ res ] = await sequelizeTypescript.query(query, { raw: true })
+ const options = {
+ type: QueryTypes.SELECT as QueryTypes.SELECT,
+ raw: true
+ }
+
+ const res = await sequelizeTypescript.query<{ enabled: boolean }>(query, options)
if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) {
- // Try to create the extension ourself
+ // Try to create the extension ourselves
try {
await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true })
const options = {
type: Sequelize.QueryTypes.SELECT
}
- const rawVideos = await utils.sequelize.query(query, options)
+ const rawVideos = await utils.sequelize.query(query, options) as any
for (const rawVideo of rawVideos) {
const videoChannel = await utils.db.VideoChannel.findOne({ where: { authorId: rawVideo.authorId } })
const options = {
type: Sequelize.QueryTypes.SELECT
}
- const res = await utils.sequelize.query(query, options)
+ const res = await utils.sequelize.query(query, options) as any
if (!res[0] || res[0].total !== 0) {
throw new Error('You need to quit friends.')
const accountCreated = await createLocalAccountWithoutKeys(SERVER_ACTOR_NAME, null, applicationInstance.id, undefined)
const { publicKey, privateKey } = await createPrivateAndPublicKeys()
- accountCreated.set('publicKey', publicKey)
- accountCreated.set('privateKey', privateKey)
+ accountCreated.Actor.publicKey = publicKey
+ accountCreated.Actor.privateKey = privateKey
await accountCreated.save()
}
const account = await createLocalAccountWithoutKeys(user.username, user.id, null, undefined)
const { publicKey, privateKey } = await createPrivateAndPublicKeys()
- account.set('publicKey', publicKey)
- account.set('privateKey', privateKey)
+ account.Actor.publicKey = publicKey
+ account.Actor.privateKey = privateKey
await account.save()
}
{
const query = 'SELECT * FROM "actor" WHERE "serverId" IS NULL AND "publicKey" IS NULL'
- const [ res ] = await utils.sequelize.query(query)
+ const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT }
+ const [ res ] = await utils.sequelize.query(query, options)
for (const actor of res) {
const { privateKey, publicKey } = await createPrivateAndPublicKeys()
{
const userQuery = 'SELECT "username" FROM "user";'
- const userResult = await utils.sequelize.query(userQuery, { transaction, type: Sequelize.QueryTypes.SELECT })
+
+ const options = { transaction, type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT }
+ const userResult = await utils.sequelize.query<{ username: string }>(userQuery, options)
const usernames = userResult.map(r => r.username)
for (const username of usernames) {
import { LAST_MIGRATION_VERSION } from './constants'
import { sequelizeTypescript } from './database'
import { readdir } from 'fs-extra'
+import { QueryTypes } from 'sequelize'
async function migrate () {
const tables = await sequelizeTypescript.getQueryInterface().showAllTables()
let actualVersion: number | null = null
- const [ rows ] = await sequelizeTypescript.query('SELECT "migrationVersion" FROM "application"')
+ const query = 'SELECT "migrationVersion" FROM "application"'
+ const options = {
+ type: QueryTypes.SELECT as QueryTypes.SELECT
+ }
+
+ const rows = await sequelizeTypescript.query<{ migrationVersion: number }>(query, options)
if (rows && rows[0] && rows[0].migrationVersion) {
actualVersion = rows[0].migrationVersion
}
const attributes = cacheFileActivityObjectToDBAttributes(cacheFileObject, video, byActor)
- redundancyModel.set('expires', attributes.expiresOn)
- redundancyModel.set('fileUrl', attributes.fileUrl)
+ redundancyModel.expiresOn = attributes.expiresOn
+ redundancyModel.fileUrl = attributes.fileUrl
return redundancyModel.save({ transaction: t })
}
import { isPlaylistElementObjectValid, isPlaylistObjectValid } from '../../helpers/custom-validators/activitypub/playlist'
import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
import { VideoModel } from '../../models/video/video'
-import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
import { sequelizeTypescript } from '../../initializers/database'
import { createPlaylistThumbnailFromUrl } from '../thumbnail'
}
}
- const [ playlist ] = await VideoPlaylistModel.upsert<VideoPlaylistModel>(playlistAttributes, { returning: true })
+ // FIXME: sequelize typings
+ const [ playlist ] = (await VideoPlaylistModel.upsert<VideoPlaylistModel>(playlistAttributes, { returning: true }) as any)
let accItems: string[] = []
await crawlCollectionPage<string>(playlistObject.id, items => {
// ---------------------------------------------------------------------------
async function resetVideoPlaylistElements (elementUrls: string[], playlist: VideoPlaylistModel) {
- const elementsToCreate: FilteredModelAttributes<VideoPlaylistElementModel>[] = []
+ const elementsToCreate: object[] = [] // FIXME: sequelize typings
await Bluebird.map(elementUrls, async elementUrl => {
try {
if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) {
logger.info('Rejecting %s because instance followers are disabled.', targetActor.url)
- return sendReject(actor, targetActor)
+ await sendReject(actor, targetActor)
+
+ return { actorFollow: undefined }
}
const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({
await actor.save({ transaction: t })
- accountOrChannelInstance.set('name', actorAttributesToUpdate.name || actorAttributesToUpdate.preferredUsername)
- accountOrChannelInstance.set('description', actorAttributesToUpdate.summary)
- accountOrChannelInstance.set('support', actorAttributesToUpdate.support)
+ accountOrChannelInstance.name = actorAttributesToUpdate.name || actorAttributesToUpdate.preferredUsername
+ accountOrChannelInstance.description = actorAttributesToUpdate.summary
+
+ if (accountOrChannelInstance instanceof VideoChannelModel) accountOrChannelInstance.support = actorAttributesToUpdate.support
+
await accountOrChannelInstance.save({ transaction: t })
})
const entry = await videoCommentActivityObjectToDBAttributes(videoInstance, actor, body)
if (!entry) return { created: false }
- const [ comment, created ] = await VideoCommentModel.upsert<VideoCommentModel>(entry, { returning: true })
+ // FIXME: sequelize typings
+ const [ comment, created ] = (await VideoCommentModel.upsert<VideoCommentModel>(entry, { returning: true }) as any)
comment.Account = actor.Account
comment.Video = videoInstance
logger.info('Adding %d %s to video %s.', rateCounts, rate, video.uuid)
// This is "likes" and "dislikes"
- if (rateCounts !== 0) await video.increment(rate + 's', { by: rateCounts })
+ if (rateCounts !== 0) {
+ const field = rate === 'like' ? 'likes' : 'dislikes'
+ await video.increment(field, { by: rateCounts })
+ }
return
}
ActivityPlaylistSegmentHashesObject,
ActivityPlaylistUrlObject,
ActivityUrlObject,
- ActivityVideoUrlObject, VideoCreate,
+ ActivityVideoUrlObject,
VideoState
} from '../../../shared/index'
import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
import { Notifier } from '../notifier'
import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist'
import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
-import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
import { AccountVideoRateModel } from '../../models/account/account-video-rate'
import { VideoShareModel } from '../../models/video/video-share'
import { VideoCommentModel } from '../../models/video/video-comment'
// Update or add other one
const upsertTasks = videoFileAttributes.map(a => {
- return VideoFileModel.upsert<VideoFileModel>(a, { returning: true, transaction: t })
+ return (VideoFileModel.upsert<VideoFileModel>(a, { returning: true, transaction: t }) as any) // FIXME: sequelize typings
.then(([ file ]) => file)
})
// Update or add other one
const upsertTasks = streamingPlaylistAttributes.map(a => {
- return VideoStreamingPlaylistModel.upsert<VideoStreamingPlaylistModel>(a, { returning: true, transaction: t })
+ // FIXME: sequelize typings
+ return (VideoStreamingPlaylistModel.upsert<VideoStreamingPlaylistModel>(a, { returning: true, transaction: t }) as any)
.then(([ streamingPlaylist ]) => streamingPlaylist)
})
throw new Error('Cannot find video files for ' + video.url)
}
- const attributes: FilteredModelAttributes<VideoFileModel>[] = []
+ const attributes: object[] = [] // FIXME: add typings
for (const fileUrl of fileUrls) {
// Fetch associated magnet uri
const magnet = videoObject.url.find(u => {
const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[]
if (playlistUrls.length === 0) return []
- const attributes: FilteredModelAttributes<VideoStreamingPlaylistModel>[] = []
+ const attributes: object[] = [] // FIXME: add typings
for (const playlistUrlObject of playlistUrls) {
const segmentsSha256UrlObject = playlistUrlObject.tag
.find(t => {
import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub'
import { createVideoChannel } from './video-channel'
import { VideoChannelModel } from '../models/video/video-channel'
-import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
import { ActorModel } from '../models/activitypub/actor'
import { UserNotificationSettingModel } from '../models/account/user-notification-setting'
import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users'
userId,
applicationId,
actorId: actorInstanceCreated.id
- } as FilteredModelAttributes<AccountModel>)
+ })
const accountInstanceCreated = await accountInstance.save({ transaction: t })
accountInstanceCreated.Actor = actorInstanceCreated
videoId: obj.video.id,
accountId: obj.account.id,
url: 'fake url'
- }, { transaction: t, validate: false })
+ }, { transaction: t, validate: false } as any) // FIXME: sequelize typings
comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment))
import { values } from 'lodash'
-import { Transaction, Op } from 'sequelize'
+import { FindOptions, Op, Transaction } from 'sequelize'
import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
-import { IFindOptions } from 'sequelize-typescript/lib/interfaces/IFindOptions'
import { VideoRateType } from '../../../shared/models/videos'
import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants'
import { VideoModel } from '../video/video'
import { AccountModel } from './account'
import { ActorModel } from '../activitypub/actor'
-import { throwIfNotValid, getSort } from '../utils'
+import { getSort, throwIfNotValid } from '../utils'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
import { AccountVideoRate } from '../../../shared'
-import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from '../video/video-channel'
+import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from '../video/video-channel'
/*
Account rates per video.
export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
@AllowNull(false)
- @Column(DataType.ENUM(values(VIDEO_RATE_TYPES)))
+ @Column(DataType.ENUM(...values(VIDEO_RATE_TYPES)))
type: VideoRateType
@AllowNull(false)
Account: AccountModel
static load (accountId: number, videoId: number, transaction?: Transaction) {
- const options: IFindOptions<AccountVideoRateModel> = {
+ const options: FindOptions = {
where: {
accountId,
videoId
type?: string,
accountId: number
}) {
- const query: IFindOptions<AccountVideoRateModel> = {
+ const query: FindOptions = {
offset: options.start,
limit: options.count,
order: getSort(options.sort),
}
static loadLocalAndPopulateVideo (rateType: VideoRateType, accountName: string, videoId: number, transaction?: Transaction) {
- const options: IFindOptions<AccountVideoRateModel> = {
+ const options: FindOptions = {
where: {
videoId,
type: rateType
}
static loadByUrl (url: string, transaction: Transaction) {
- const options: IFindOptions<AccountVideoRateModel> = {
+ const options: FindOptions = {
where: {
url
}
-import * as Sequelize from 'sequelize'
import {
AllowNull,
BeforeDestroy,
import { AvatarModel } from '../avatar/avatar'
import { VideoPlaylistModel } from '../video/video-playlist'
import { WEBSERVER } from '../../initializers/constants'
+import { Op, Transaction, WhereOptions } from 'sequelize'
export enum ScopeNames {
SUMMARY = 'SUMMARY'
]
})
@Scopes({
- [ ScopeNames.SUMMARY ]: (whereActor?: Sequelize.WhereOptions<ActorModel>) => {
+ [ ScopeNames.SUMMARY ]: (whereActor?: WhereOptions) => {
return {
attributes: [ 'id', 'name' ],
include: [
@AllowNull(true)
@Default(null)
- @Is('AccountDescription', value => throwIfNotValid(value, isAccountDescriptionValid, 'description'))
+ @Is('AccountDescription', value => throwIfNotValid(value, isAccountDescriptionValid, 'description', true))
@Column
description: string
return undefined
}
- static load (id: number, transaction?: Sequelize.Transaction) {
+ static load (id: number, transaction?: Transaction) {
return AccountModel.findByPk(id, { transaction })
}
static loadLocalByName (name: string) {
const query = {
where: {
- [ Sequelize.Op.or ]: [
+ [ Op.or ]: [
{
userId: {
- [ Sequelize.Op.ne ]: null
+ [ Op.ne ]: null
}
},
{
applicationId: {
- [ Sequelize.Op.ne ]: null
+ [ Op.ne ]: null
}
}
]
return AccountModel.findOne(query)
}
- static loadByUrl (url: string, transaction?: Sequelize.Transaction) {
+ static loadByUrl (url: string, transaction?: Transaction) {
const query = {
include: [
{
-import {
- AllowNull,
- BelongsTo,
- Column,
- CreatedAt,
- Default,
- ForeignKey,
- IFindOptions,
- Is,
- Model,
- Scopes,
- Table,
- UpdatedAt
-} from 'sequelize-typescript'
+import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
import { UserNotification, UserNotificationType } from '../../../shared'
import { getSort, throwIfNotValid } from '../utils'
import { isBooleanValid } from '../../helpers/custom-validators/misc'
import { UserModel } from './user'
import { VideoModel } from '../video/video'
import { VideoCommentModel } from '../video/video-comment'
-import { Op } from 'sequelize'
+import { FindOptions, Op } from 'sequelize'
import { VideoChannelModel } from '../video/video-channel'
import { AccountModel } from './account'
import { VideoAbuseModel } from '../video/video-abuse'
},
buildAccountInclude(false, true)
- ]
+ ] as any // FIXME: sequelize typings
}
})
@Table({
}
}
}
- ]
+ ] as any // FIXME: sequelize typings
})
export class UserNotificationModel extends Model<UserNotificationModel> {
ActorFollow: ActorFollowModel
static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) {
- const query: IFindOptions<UserNotificationModel> = {
+ const query: FindOptions = {
offset: start,
limit: count,
order: getSort(sort),
}
if (beforeDate) {
- query.where.updatedAt = {
+ query.where['updatedAt'] = {
[Op.lt]: beforeDate
}
}
model: () => UserNotificationSettingModel,
required: true
}
- ]
+ ] as any // FIXME: sequelize typings
}
})
@Table({
@AllowNull(true)
@Default(null)
- @Is('UserEmailVerified', value => throwIfNotValid(value, isUserEmailVerifiedValid, 'email verified boolean'))
+ @Is('UserEmailVerified', value => throwIfNotValid(value, isUserEmailVerifiedValid, 'email verified boolean', true))
@Column
emailVerified: boolean
@AllowNull(false)
@Is('UserNSFWPolicy', value => throwIfNotValid(value, isUserNSFWPolicyValid, 'NSFW policy'))
- @Column(DataType.ENUM(values(NSFW_POLICY_TYPES)))
+ @Column(DataType.ENUM(...values(NSFW_POLICY_TYPES)))
nsfwPolicy: NSFWPolicyType
@AllowNull(false)
@AllowNull(true)
@Default(null)
- @Is('UserBlockedReason', value => throwIfNotValid(value, isUserBlockedReasonValid, 'blocked reason'))
+ @Is('UserBlockedReason', value => throwIfNotValid(value, isUserBlockedReasonValid, 'blocked reason', true))
@Column
blockedReason: string
notificationSettings: this.NotificationSetting ? this.NotificationSetting.toFormattedJSON() : undefined,
videoChannels: [],
videoQuotaUsed: videoQuotaUsed !== undefined
- ? parseInt(videoQuotaUsed, 10)
+ ? parseInt(videoQuotaUsed + '', 10)
: undefined,
videoQuotaUsedDaily: videoQuotaUsedDaily !== undefined
- ? parseInt(videoQuotaUsedDaily, 10)
+ ? parseInt(videoQuotaUsedDaily + '', 10)
: undefined
}
private static getTotalRawQuery (query: string, userId: number) {
const options = {
bind: { userId },
- type: Sequelize.QueryTypes.SELECT
+ type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT
}
- return UserModel.sequelize.query(query, options)
+ return UserModel.sequelize.query<{ total: number }>(query, options)
.then(([ { total } ]) => {
if (total === null) return 0
- return parseInt(total, 10)
+ return parseInt(total + '', 10)
})
}
}
import * as Bluebird from 'bluebird'
import { values } from 'lodash'
-import * as Sequelize from 'sequelize'
import {
AfterCreate,
AfterDestroy,
import { getSort } from '../utils'
import { ActorModel, unusedActorAttributesForAPI } from './actor'
import { VideoChannelModel } from '../video/video-channel'
-import { IIncludeOptions } from '../../../node_modules/sequelize-typescript/lib/interfaces/IIncludeOptions'
import { AccountModel } from '../account/account'
+import { IncludeOptions, Op, Transaction, QueryTypes } from 'sequelize'
@Table({
tableName: 'actorFollow',
export class ActorFollowModel extends Model<ActorFollowModel> {
@AllowNull(false)
- @Column(DataType.ENUM(values(FOLLOW_STATES)))
+ @Column(DataType.ENUM(...values(FOLLOW_STATES)))
state: FollowState
@AllowNull(false)
if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved)
}
- static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Sequelize.Transaction) {
+ static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Transaction) {
const query = {
where: {
actorId,
return ActorFollowModel.findOne(query)
}
- static loadByActorAndTargetNameAndHostForAPI (actorId: number, targetName: string, targetHost: string, t?: Sequelize.Transaction) {
- const actorFollowingPartInclude: IIncludeOptions = {
+ static loadByActorAndTargetNameAndHostForAPI (actorId: number, targetName: string, targetHost: string, t?: Transaction) {
+ const actorFollowingPartInclude: IncludeOptions = {
model: ActorModel,
required: true,
as: 'ActorFollowing',
.map(t => {
if (t.host) {
return {
- [ Sequelize.Op.and ]: [
+ [ Op.and ]: [
{
'$preferredUsername$': t.name
},
}
return {
- [ Sequelize.Op.and ]: [
+ [ Op.and ]: [
{
'$preferredUsername$': t.name
},
const query = {
attributes: [],
where: {
- [ Sequelize.Op.and ]: [
+ [ Op.and ]: [
{
- [ Sequelize.Op.or ]: whereTab
+ [ Op.or ]: whereTab
},
{
actorId
required: true,
where: search ? {
host: {
- [Sequelize.Op.iLike]: '%' + search + '%'
+ [Op.iLike]: '%' + search + '%'
}
} : undefined
}
required: true,
where: search ? {
host: {
- [ Sequelize.Op.iLike ]: '%' + search + '%'
+ [ Op.iLike ]: '%' + search + '%'
}
} : undefined
}
})
}
- static listAcceptedFollowerUrlsForAP (actorIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
+ static listAcceptedFollowerUrlsForAP (actorIds: number[], t: Transaction, start?: number, count?: number) {
return ActorFollowModel.createListAcceptedFollowForApiQuery('followers', actorIds, t, start, count)
}
- static listAcceptedFollowerSharedInboxUrls (actorIds: number[], t: Sequelize.Transaction) {
+ static listAcceptedFollowerSharedInboxUrls (actorIds: number[], t: Transaction) {
return ActorFollowModel.createListAcceptedFollowForApiQuery(
'followers',
actorIds,
)
}
- static listAcceptedFollowingUrlsForApi (actorIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
+ static listAcceptedFollowingUrlsForApi (actorIds: number[], t: Transaction, start?: number, count?: number) {
return ActorFollowModel.createListAcceptedFollowForApiQuery('following', actorIds, t, start, count)
}
}
}
- static updateFollowScore (inboxUrl: string, value: number, t?: Sequelize.Transaction) {
+ static updateFollowScore (inboxUrl: string, value: number, t?: Transaction) {
const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` +
'WHERE id IN (' +
'SELECT "actorFollow"."id" FROM "actorFollow" ' +
')'
const options = {
- type: Sequelize.QueryTypes.BULKUPDATE,
+ type: QueryTypes.BULKUPDATE,
transaction: t
}
private static async createListAcceptedFollowForApiQuery (
type: 'followers' | 'following',
actorIds: number[],
- t: Sequelize.Transaction,
+ t: Transaction,
start?: number,
count?: number,
columnUrl = 'url',
const options = {
bind: { actorIds },
- type: Sequelize.QueryTypes.SELECT,
+ type: QueryTypes.SELECT,
transaction: t
}
tasks.push(ActorFollowModel.sequelize.query(query, options))
const query = {
where: {
score: {
- [Sequelize.Op.lte]: 0
+ [Op.lte]: 0
}
},
logging: false
model: () => AvatarModel,
required: false
}
- ]
+ ] as any // FIXME: sequelize typings
}
})
@Table({
export class ActorModel extends Model<ActorModel> {
@AllowNull(false)
- @Column(DataType.ENUM(values(ACTIVITY_PUB_ACTOR_TYPES)))
+ @Column({ type: DataType.ENUM(...values(ACTIVITY_PUB_ACTOR_TYPES)) }) // FIXME: sequelize typings
type: ActivityPubActorType
@AllowNull(false)
url: string
@AllowNull(true)
- @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPublicKeyValid, 'public key'))
+ @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPublicKeyValid, 'public key', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.PUBLIC_KEY.max))
publicKey: string
@AllowNull(true)
- @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPrivateKeyValid, 'private key'))
+ @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPrivateKeyValid, 'private key', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY.max))
privateKey: string
-import * as Sequelize from 'sequelize'
+import { ModelAttributeColumnOptions } from 'sequelize'
declare namespace Migration {
- interface Boolean extends Sequelize.DefineAttributeColumnOptions {
+ interface Boolean extends ModelAttributeColumnOptions {
defaultValue: boolean | null
}
- interface String extends Sequelize.DefineAttributeColumnOptions {
+ interface String extends ModelAttributeColumnOptions {
defaultValue: string | null
}
- interface Integer extends Sequelize.DefineAttributeColumnOptions {
+ interface Integer extends ModelAttributeColumnOptions {
defaultValue: number | null
}
- interface BigInteger extends Sequelize.DefineAttributeColumnOptions {
- defaultValue: Sequelize.DataTypeBigInt | number | null
+ interface BigInteger extends ModelAttributeColumnOptions {
+ defaultValue: number | null
}
- interface UUID extends Sequelize.DefineAttributeColumnOptions {
- defaultValue: Sequelize.DataTypeUUIDv4 | null
+ interface UUID extends ModelAttributeColumnOptions {
+ defaultValue: null
}
}
@Column
clientSecret: string
- @Column(DataType.ARRAY(DataType.STRING))
+ @Column({ type: DataType.ARRAY(DataType.STRING) }) // FIXME: sequelize typings
grants: string[]
- @Column(DataType.ARRAY(DataType.STRING))
+ @Column({ type: DataType.ARRAY(DataType.STRING) }) // FIXME: sequelize typings
redirectUris: string[]
@CreatedAt
}
]
}
- ]
+ ] as any // FIXME: sequelize typings
}
})
@Table({
}
]
}
- ]
+ ] as any // FIXME: sequelize typings
}
})
import { Sequelize } from 'sequelize-typescript'
import * as validator from 'validator'
+import { OrderItem } from 'sequelize'
+import { Col } from 'sequelize/types/lib/utils'
type SortType = { sortModel: any, sortValue: string }
// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ]
-function getSort (value: string, lastSort: string[] = [ 'id', 'ASC' ]) {
- let { direction, field } = buildDirectionAndField(value)
+function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
+ const { direction, field } = buildDirectionAndField(value)
+
+ let finalField: string | Col
if (field.toLowerCase() === 'match') { // Search
- field = Sequelize.col('similarity')
+ finalField = Sequelize.col('similarity')
+ } else {
+ finalField = field
}
- return [ [ field, direction ], lastSort ]
+ return [ [ finalField, direction ], lastSort ]
}
-function getVideoSort (value: string, lastSort: string[] = [ 'id', 'ASC' ]) {
- let { direction, field } = buildDirectionAndField(value)
+function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
+ const { direction, field } = buildDirectionAndField(value)
- // Alias
- if (field.toLowerCase() === 'match') { // Search
- field = Sequelize.col('similarity')
- } else if (field.toLowerCase() === 'trending') { // Sort by aggregation
+ if (field.toLowerCase() === 'trending') { // Sort by aggregation
return [
[ Sequelize.fn('COALESCE', Sequelize.fn('SUM', Sequelize.col('VideoViews.views')), '0'), direction ],
]
}
- const firstSort = typeof field === 'string' ?
- field.split('.').concat([ direction ]) :
- [ field, direction ]
+ let finalField: string | Col
+
+ // Alias
+ if (field.toLowerCase() === 'match') { // Search
+ finalField = Sequelize.col('similarity')
+ } else {
+ finalField = field
+ }
+
+ const firstSort = typeof finalField === 'string'
+ ? finalField.split('.').concat([ direction ]) as any // FIXME: sequelize typings
+ : [ finalField, direction ]
return [ firstSort, lastSort ]
}
-function getSortOnModel (model: any, value: string, lastSort: string[] = [ 'id', 'ASC' ]) {
- let [ firstSort ] = getSort(value)
+function getSortOnModel (model: any, value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
+ const [ firstSort ] = getSort(value)
if (model) return [ [ model, firstSort[0], firstSort[1] ], lastSort ]
return [ firstSort, lastSort ]
return (now - createdAtTime) > refreshInterval && (now - updatedAtTime) > refreshInterval
}
-function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') {
+function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value', nullable = false) {
+ if (nullable && (value === null || value === undefined)) return
+
if (validator(value) === false) {
throw new Error(`"${value}" is not a valid ${fieldName}.`)
}
}
function buildDirectionAndField (value: string) {
- let field: any
+ let field: string
let direction: 'ASC' | 'DESC'
if (value.substring(0, 1) === '-') {
-import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Sequelize, Table, UpdatedAt } from 'sequelize-typescript'
+import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
import { ScopeNames as VideoScopeNames, VideoModel } from './video'
import { VideoPrivacy } from '../../../shared/models/videos'
-import { Transaction } from 'sequelize'
+import { Op, Transaction } from 'sequelize'
@Table({
tableName: 'scheduleVideoUpdate',
attributes: [ 'id' ],
where: {
updateAt: {
- [Sequelize.Op.lte]: new Date()
+ [Op.lte]: new Date()
}
}
}
const query = {
where: {
updateAt: {
- [Sequelize.Op.lte]: new Date()
+ [Op.lte]: new Date()
}
},
include: [
import * as Bluebird from 'bluebird'
-import * as Sequelize from 'sequelize'
+import { QueryTypes, Transaction } from 'sequelize'
import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
import { isVideoTagValid } from '../../helpers/custom-validators/videos'
import { throwIfNotValid } from '../utils'
})
Videos: VideoModel[]
- static findOrCreateTags (tags: string[], transaction: Sequelize.Transaction) {
+ static findOrCreateTags (tags: string[], transaction: Transaction) {
if (tags === null) return []
const tasks: Bluebird<TagModel>[] = []
const options = {
bind: { threshold, count, videoPrivacy: VideoPrivacy.PUBLIC, videoState: VideoState.PUBLISHED },
- type: Sequelize.QueryTypes.SELECT
+ type: QueryTypes.SELECT as QueryTypes.SELECT
}
- return TagModel.sequelize.query(query, options)
+ return TagModel.sequelize.query<{ name }>(query, options)
.then(data => data.map(d => d.name))
}
}
@AllowNull(true)
@Default(null)
- @Is('VideoAbuseModerationComment', value => throwIfNotValid(value, isVideoAbuseModerationCommentValid, 'moderationComment'))
+ @Is('VideoAbuseModerationComment', value => throwIfNotValid(value, isVideoAbuseModerationCommentValid, 'moderationComment', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_ABUSES.MODERATION_COMMENT.max))
moderationComment: string
-import {
- AllowNull,
- BelongsTo,
- Column,
- CreatedAt,
- DataType,
- Default,
- ForeignKey,
- Is, Model,
- Table,
- UpdatedAt,
- IFindOptions
-} from 'sequelize-typescript'
+import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
import { getSortOnModel, SortType, throwIfNotValid } from '../utils'
import { VideoModel } from './video'
-import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from './video-channel'
+import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from './video-channel'
import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist'
import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos'
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
+import { FindOptions } from 'sequelize'
@Table({
tableName: 'videoBlacklist',
export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
@AllowNull(true)
- @Is('VideoBlacklistReason', value => throwIfNotValid(value, isVideoBlacklistReasonValid, 'reason'))
+ @Is('VideoBlacklistReason', value => throwIfNotValid(value, isVideoBlacklistReasonValid, 'reason', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_BLACKLIST.REASON.max))
reason: string
Video: VideoModel
static listForApi (start: number, count: number, sort: SortType, type?: VideoBlacklistType) {
- const query: IFindOptions<VideoBlacklistModel> = {
+ const query: FindOptions = {
offset: start,
limit: count,
order: getSortOnModel(sort.sortModel, sort.sortValue),
-import * as Sequelize from 'sequelize'
+import { OrderItem, Transaction } from 'sequelize'
import {
AllowNull,
BeforeDestroy,
return VideoCaptionModel.findOne(query)
}
- static insertOrReplaceLanguage (videoId: number, language: string, transaction: Sequelize.Transaction) {
+ static insertOrReplaceLanguage (videoId: number, language: string, transaction: Transaction) {
const values = {
videoId,
language
}
- return VideoCaptionModel.upsert<VideoCaptionModel>(values, { transaction, returning: true })
+ return (VideoCaptionModel.upsert<VideoCaptionModel>(values, { transaction, returning: true }) as any) // FIXME: typings
.then(([ caption ]) => caption)
}
static listVideoCaptions (videoId: number) {
const query = {
- order: [ [ 'language', 'ASC' ] ],
+ order: [ [ 'language', 'ASC' ] ] as OrderItem[],
where: {
videoId
}
return VIDEO_LANGUAGES[language] || 'Unknown'
}
- static deleteAllCaptionsOfRemoteVideo (videoId: number, transaction: Sequelize.Transaction) {
+ static deleteAllCaptionsOfRemoteVideo (videoId: number, transaction: Transaction) {
const query = {
where: {
videoId
{ model: () => VideoFileModel }
]
}
- ]
+ ] as any // FIXME: sequelize typings
}
})
export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel> {
DefaultScope,
ForeignKey,
HasMany,
- IFindOptions,
Is,
Model,
Scopes,
import { VideoModel } from './video'
import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
import { ServerModel } from '../server/server'
-import { DefineIndexesOptions } from 'sequelize'
+import { FindOptions, ModelIndexesOptions, Op } from 'sequelize'
import { AvatarModel } from '../avatar/avatar'
import { VideoPlaylistModel } from './video-playlist'
// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
-const indexes: DefineIndexesOptions[] = [
+const indexes: ModelIndexesOptions[] = [
buildTrigramSearchIndex('video_channel_name_trigram', 'name'),
{
})
@Scopes({
[ScopeNames.SUMMARY]: (withAccount = false) => {
- const base: IFindOptions<VideoChannelModel> = {
+ const base: FindOptions = {
attributes: [ 'name', 'description', 'id', 'actorId' ],
include: [
{
},
model: ActorModel,
where: {
- [Sequelize.Op.or]: [
+ [Op.or]: [
{
serverId: null
},
{
serverId: {
- [ Sequelize.Op.in ]: Sequelize.literal(inQueryInstanceFollow)
+ [ Op.in ]: Sequelize.literal(inQueryInstanceFollow)
}
}
]
@AllowNull(true)
@Default(null)
- @Is('VideoChannelDescription', value => throwIfNotValid(value, isVideoChannelDescriptionValid, 'description'))
+ @Is('VideoChannelDescription', value => throwIfNotValid(value, isVideoChannelDescriptionValid, 'description', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_CHANNELS.DESCRIPTION.max))
description: string
@AllowNull(true)
@Default(null)
- @Is('VideoChannelSupport', value => throwIfNotValid(value, isVideoChannelSupportValid, 'support'))
+ @Is('VideoChannelSupport', value => throwIfNotValid(value, isVideoChannelSupportValid, 'support', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_CHANNELS.SUPPORT.max))
support: string
limit: options.count,
order: getSort(options.sort),
where: {
- [Sequelize.Op.or]: [
+ [Op.or]: [
Sequelize.literal(
'lower(immutable_unaccent("VideoChannelModel"."name")) % lower(immutable_unaccent(' + escapedSearch + '))'
),
-import * as Sequelize from 'sequelize'
import {
AllowNull,
BeforeDestroy,
CreatedAt,
DataType,
ForeignKey,
- IFindOptions,
Is,
Model,
Scopes,
import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor'
import { regexpCapture } from '../../helpers/regexp'
import { uniq } from 'lodash'
+import { FindOptions, Op, Order, Sequelize, Transaction } from 'sequelize'
enum ScopeNames {
WITH_ACCOUNT = 'WITH_ACCOUNT',
}
]
}
- ]
+ ] as any // FIXME: sequelize typings
},
[ScopeNames.WITH_IN_REPLY_TO]: {
include: [
}
]
}
- ]
+ ] as any // FIXME: sequelize typings
}
})
@Table({
}
}
- static loadById (id: number, t?: Sequelize.Transaction) {
- const query: IFindOptions<VideoCommentModel> = {
+ static loadById (id: number, t?: Transaction) {
+ const query: FindOptions = {
where: {
id
}
return VideoCommentModel.findOne(query)
}
- static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Sequelize.Transaction) {
- const query: IFindOptions<VideoCommentModel> = {
+ static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Transaction) {
+ const query: FindOptions = {
where: {
id
}
.findOne(query)
}
- static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
- const query: IFindOptions<VideoCommentModel> = {
+ static loadByUrlAndPopulateAccount (url: string, t?: Transaction) {
+ const query: FindOptions = {
where: {
url
}
return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query)
}
- static loadByUrlAndPopulateReplyAndVideo (url: string, t?: Sequelize.Transaction) {
- const query: IFindOptions<VideoCommentModel> = {
+ static loadByUrlAndPopulateReplyAndVideo (url: string, t?: Transaction) {
+ const query: FindOptions = {
where: {
url
}
videoId,
inReplyToCommentId: null,
accountId: {
- [Sequelize.Op.notIn]: Sequelize.literal(
+ [Op.notIn]: Sequelize.literal(
'(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')'
)
}
const userAccountId = user ? user.Account.id : undefined
const query = {
- order: [ [ 'createdAt', 'ASC' ], [ 'updatedAt', 'ASC' ] ],
+ order: [ [ 'createdAt', 'ASC' ], [ 'updatedAt', 'ASC' ] ] as Order,
where: {
videoId,
- [ Sequelize.Op.or ]: [
+ [ Op.or ]: [
{ id: threadId },
{ originCommentId: threadId }
],
accountId: {
- [Sequelize.Op.notIn]: Sequelize.literal(
+ [Op.notIn]: Sequelize.literal(
'(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')'
)
}
})
}
- static listThreadParentComments (comment: VideoCommentModel, t: Sequelize.Transaction, order: 'ASC' | 'DESC' = 'ASC') {
+ static listThreadParentComments (comment: VideoCommentModel, t: Transaction, order: 'ASC' | 'DESC' = 'ASC') {
const query = {
- order: [ [ 'createdAt', order ] ],
+ order: [ [ 'createdAt', order ] ] as Order,
where: {
id: {
- [ Sequelize.Op.in ]: Sequelize.literal('(' +
+ [ Op.in ]: Sequelize.literal('(' +
'WITH RECURSIVE children (id, "inReplyToCommentId") AS ( ' +
`SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ${comment.id} ` +
'UNION ' +
') ' +
'SELECT id FROM children' +
')'),
- [ Sequelize.Op.ne ]: comment.id
+ [ Op.ne ]: comment.id
}
},
transaction: t
.findAll(query)
}
- static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Sequelize.Transaction, order: 'ASC' | 'DESC' = 'ASC') {
+ static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Transaction, order: 'ASC' | 'DESC' = 'ASC') {
const query = {
- order: [ [ 'createdAt', order ] ],
+ order: [ [ 'createdAt', order ] ] as Order,
offset: start,
limit: count,
where: {
static listForFeed (start: number, count: number, videoId?: number) {
const query = {
- order: [ [ 'createdAt', 'DESC' ] ],
+ order: [ [ 'createdAt', 'DESC' ] ] as Order,
offset: start,
limit: count,
where: {},
const query = {
where: {
updatedAt: {
- [Sequelize.Op.lt]: beforeUpdatedAt
+ [Op.lt]: beforeUpdatedAt
},
videoId
}
@AllowNull(true)
@Default(null)
- @Is('VideoImportTargetUrl', value => throwIfNotValid(value, isVideoImportTargetUrlValid, 'targetUrl'))
+ @Is('VideoImportTargetUrl', value => throwIfNotValid(value, isVideoImportTargetUrlValid, 'targetUrl', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_IMPORTS.URL.max))
targetUrl: string
@AllowNull(true)
@Default(null)
- @Is('VideoImportMagnetUri', value => throwIfNotValid(value, isVideoMagnetUriValid, 'magnetUri'))
+ @Is('VideoImportMagnetUri', value => throwIfNotValid(value, isVideoMagnetUriValid, 'magnetUri', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_IMPORTS.URL.max)) // Use the same constraints than URLs
magnetUri: string
} from 'sequelize-typescript'
import { VideoModel } from './video'
import { VideoPlaylistModel } from './video-playlist'
-import * as Sequelize from 'sequelize'
import { getSort, throwIfNotValid } from '../utils'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object'
import * as validator from 'validator'
+import { AggregateOptions, Op, Sequelize, Transaction } from 'sequelize'
@Table({
tableName: 'videoPlaylistElement',
})
Video: VideoModel
- static deleteAllOf (videoPlaylistId: number, transaction?: Sequelize.Transaction) {
+ static deleteAllOf (videoPlaylistId: number, transaction?: Transaction) {
const query = {
where: {
videoPlaylistId
return VideoPlaylistElementModel.findOne(query)
}
- static listUrlsOfForAP (videoPlaylistId: number, start: number, count: number, t?: Sequelize.Transaction) {
+ static listUrlsOfForAP (videoPlaylistId: number, start: number, count: number, t?: Transaction) {
const query = {
attributes: [ 'url' ],
offset: start,
})
}
- static getNextPositionOf (videoPlaylistId: number, transaction?: Sequelize.Transaction) {
- const query = {
+ static getNextPositionOf (videoPlaylistId: number, transaction?: Transaction) {
+ const query: AggregateOptions<number> = {
where: {
videoPlaylistId
},
firstPosition: number,
endPosition: number,
newPosition: number,
- transaction?: Sequelize.Transaction
+ transaction?: Transaction
) {
const query = {
where: {
videoPlaylistId,
position: {
- [Sequelize.Op.gte]: firstPosition,
- [Sequelize.Op.lte]: endPosition
+ [Op.gte]: firstPosition,
+ [Op.lte]: endPosition
}
},
transaction,
fromPosition: number,
toPosition?: number,
by = 1,
- transaction?: Sequelize.Transaction
+ transaction?: Transaction
) {
const query = {
where: {
videoPlaylistId,
position: {
- [Sequelize.Op.gte]: fromPosition
+ [Op.gte]: fromPosition
}
},
transaction
Table,
UpdatedAt
} from 'sequelize-typescript'
-import * as Sequelize from 'sequelize'
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils'
import {
import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model'
import { ThumbnailModel } from './thumbnail'
import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
+import { fn, literal, Op, Transaction } from 'sequelize'
enum ScopeNames {
AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
attributes: {
include: [
[
- Sequelize.literal('(SELECT COUNT("id") FROM "videoPlaylistElement" WHERE "videoPlaylistId" = "VideoPlaylistModel"."id")'),
+ fn('COUNT', 'toto'),
+ 'coucou'
+ ],
+ [
+ literal('(SELECT COUNT("id") FROM "videoPlaylistElement" WHERE "videoPlaylistId" = "VideoPlaylistModel"."id")'),
'videosLength'
]
]
// Only list local playlists OR playlists that are on an instance followed by actorId
const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId)
const actorWhere = {
- [ Sequelize.Op.or ]: [
+ [ Op.or ]: [
{
serverId: null
},
{
serverId: {
- [ Sequelize.Op.in ]: Sequelize.literal(inQueryInstanceFollow)
+ [ Op.in ]: literal(inQueryInstanceFollow)
}
}
]
}
const where = {
- [Sequelize.Op.and]: whereAnd
+ [Op.and]: whereAnd
}
const accountScope = {
name: string
@AllowNull(true)
- @Is('VideoPlaylistDescription', value => throwIfNotValid(value, isVideoPlaylistDescriptionValid, 'description'))
+ @Is('VideoPlaylistDescription', value => throwIfNotValid(value, isVideoPlaylistDescriptionValid, 'description', true))
@Column
description: string
model: VideoPlaylistElementModel.unscoped(),
where: {
videoId: {
- [Sequelize.Op.any]: videoIds
+ [Op.any]: videoIds
}
},
required: true
.then(e => !!e)
}
- static loadWithAccountAndChannelSummary (id: number | string, transaction: Sequelize.Transaction) {
+ static loadWithAccountAndChannelSummary (id: number | string, transaction: Transaction) {
const where = buildWhereIdOrUUID(id)
const query = {
.findOne(query)
}
- static loadWithAccountAndChannel (id: number | string, transaction: Sequelize.Transaction) {
+ static loadWithAccountAndChannel (id: number | string, transaction: Transaction) {
const where = buildWhereIdOrUUID(id)
const query = {
return VIDEO_PLAYLIST_TYPES[type] || 'Unknown'
}
- static resetPlaylistsOfChannel (videoChannelId: number, transaction: Sequelize.Transaction) {
+ static resetPlaylistsOfChannel (videoChannelId: number, transaction: Transaction) {
const query = {
where: {
videoChannelId
label: VideoPlaylistModel.getTypeLabel(this.type)
},
- videosLength: this.get('videosLength'),
+ videosLength: this.get('videosLength') as number,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
}
}
- toActivityPubObject (page: number, t: Sequelize.Transaction): Promise<PlaylistObject> {
+ toActivityPubObject (page: number, t: Transaction): Promise<PlaylistObject> {
const handler = (start: number, count: number) => {
return VideoPlaylistElementModel.listUrlsOfForAP(this.id, start, count, t)
}
-import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
+import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, HasMany, Is, Model, Table, UpdatedAt, DataType } from 'sequelize-typescript'
import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos'
import { throwIfNotValid } from '../utils'
import { VideoModel } from './video'
-import * as Sequelize from 'sequelize'
import { VideoRedundancyModel } from '../redundancy/video-redundancy'
import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
import { join } from 'path'
import { sha1 } from '../../helpers/core-utils'
import { isArrayOf } from '../../helpers/custom-validators/misc'
+import { QueryTypes, Op } from 'sequelize'
@Table({
tableName: 'videoStreamingPlaylist',
fields: [ 'p2pMediaLoaderInfohashes' ],
using: 'gin'
}
- ]
+ ] as any // FIXME: sequelize typings
})
export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistModel> {
@CreatedAt
@AllowNull(false)
@Is('VideoStreamingPlaylistInfoHashes', value => throwIfNotValid(value, v => isArrayOf(v, isVideoFileInfoHashValid), 'info hashes'))
- @Column(DataType.ARRAY(DataType.STRING))
+ @Column({ type: DataType.ARRAY(DataType.STRING) }) // FIXME: typings
p2pMediaLoaderInfohashes: string[]
@AllowNull(false)
static doesInfohashExist (infoHash: string) {
const query = 'SELECT 1 FROM "videoStreamingPlaylist" WHERE $infoHash = ANY("p2pMediaLoaderInfohashes") LIMIT 1'
const options = {
- type: Sequelize.QueryTypes.SELECT,
+ type: QueryTypes.SELECT as QueryTypes.SELECT,
bind: { infoHash },
raw: true
}
- return VideoModel.sequelize.query(query, options)
- .then(results => {
- return results.length === 1
- })
+ return VideoModel.sequelize.query<any>(query, options)
+ .then(results => results.length === 1)
}
static buildP2PMediaLoaderInfoHashes (playlistUrl: string, videoFiles: VideoFileModel[]) {
const query = {
where: {
p2pMediaLoaderPeerVersion: {
- [Sequelize.Op.ne]: P2P_MEDIA_LOADER_PEER_VERSION
+ [Op.ne]: P2P_MEDIA_LOADER_PEER_VERSION
}
}
}
import * as magnetUtil from 'magnet-uri'
import * as parseTorrent from 'parse-torrent'
import { join } from 'path'
-import * as Sequelize from 'sequelize'
+import {
+ CountOptions,
+ FindOptions,
+ IncludeOptions,
+ ModelIndexesOptions,
+ Op,
+ QueryTypes,
+ ScopeOptions,
+ Sequelize,
+ Transaction,
+ WhereOptions
+} from 'sequelize'
import {
AllowNull,
BeforeDestroy,
ForeignKey,
HasMany,
HasOne,
- IFindOptions,
- IIncludeOptions,
Is,
IsInt,
IsUUID,
isVideoStateValid,
isVideoSupportValid
} from '../../helpers/custom-validators/videos'
-import { generateImageFromVideoFile, getVideoFileResolution } from '../../helpers/ffmpeg-utils'
+import { getVideoFileResolution } from '../../helpers/ffmpeg-utils'
import { logger } from '../../helpers/logger'
import { getServerActor } from '../../helpers/utils'
import {
CONSTRAINTS_FIELDS,
HLS_REDUNDANCY_DIRECTORY,
HLS_STREAMING_PLAYLIST_DIRECTORY,
- PREVIEWS_SIZE,
REMOTE_SCHEME,
STATIC_DOWNLOAD_PATHS,
STATIC_PATHS,
- THUMBNAILS_SIZE,
VIDEO_CATEGORIES,
VIDEO_LANGUAGES,
VIDEO_LICENCES,
import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
-const indexes: Sequelize.DefineIndexesOptions[] = [
+const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [
buildTrigramSearchIndex('video_name_trigram', 'name'),
{ fields: [ 'createdAt' ] },
fields: [ 'originallyPublishedAt' ],
where: {
originallyPublishedAt: {
- [Sequelize.Op.ne]: null
+ [Op.ne]: null
}
}
},
fields: [ 'category' ], // We don't care videos with an unknown category
where: {
category: {
- [Sequelize.Op.ne]: null
+ [Op.ne]: null
}
}
},
fields: [ 'licence' ], // We don't care videos with an unknown licence
where: {
licence: {
- [Sequelize.Op.ne]: null
+ [Op.ne]: null
}
}
},
fields: [ 'language' ], // We don't care videos with an unknown language
where: {
language: {
- [Sequelize.Op.ne]: null
+ [Op.ne]: null
}
}
},
@Scopes({
[ ScopeNames.FOR_API ]: (options: ForAPIOptions) => {
- const query: IFindOptions<VideoModel> = {
+ const query: FindOptions = {
where: {
id: {
- [ Sequelize.Op.any ]: options.ids
+ [ Op.in ]: options.ids // FIXME: sequelize any seems broken
}
},
include: [
return query
},
[ ScopeNames.AVAILABLE_FOR_LIST_IDS ]: (options: AvailableForListIDsOptions) => {
- const query: IFindOptions<VideoModel> = {
+ const query: FindOptions = {
raw: true,
attributes: [ 'id' ],
where: {
id: {
- [ Sequelize.Op.and ]: [
+ [ Op.and ]: [
{
- [ Sequelize.Op.notIn ]: Sequelize.literal(
+ [ Op.notIn ]: Sequelize.literal(
'(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")'
)
}
]
},
channelId: {
- [ Sequelize.Op.notIn ]: Sequelize.literal(
+ [ Op.notIn ]: Sequelize.literal(
'(' +
'SELECT id FROM "videoChannel" WHERE "accountId" IN (' +
buildBlockedAccountSQL(options.serverAccountId, options.user ? options.user.Account.id : undefined) +
// Always list public videos
privacy: VideoPrivacy.PUBLIC,
// Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding
- [ Sequelize.Op.or ]: [
+ [ Op.or ]: [
{
state: VideoState.PUBLISHED
},
{
- [ Sequelize.Op.and ]: {
+ [ Op.and ]: {
state: VideoState.TO_TRANSCODE,
waitTranscoding: false
}
}
if (options.filter || options.accountId || options.videoChannelId) {
- const videoChannelInclude: IIncludeOptions = {
+ const videoChannelInclude: IncludeOptions = {
attributes: [],
model: VideoChannelModel.unscoped(),
required: true
}
if (options.filter || options.accountId) {
- const accountInclude: IIncludeOptions = {
+ const accountInclude: IncludeOptions = {
attributes: [],
model: AccountModel.unscoped(),
required: true
// Force actorId to be a number to avoid SQL injections
const actorIdNumber = parseInt(options.followerActorId.toString(), 10)
- query.where[ 'id' ][ Sequelize.Op.and ].push({
- [ Sequelize.Op.in ]: Sequelize.literal(
+ query.where[ 'id' ][ Op.and ].push({
+ [ Op.in ]: Sequelize.literal(
'(' +
'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' +
'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
}
if (options.withFiles === true) {
- query.where[ 'id' ][ Sequelize.Op.and ].push({
- [ Sequelize.Op.in ]: Sequelize.literal(
+ query.where[ 'id' ][ Op.and ].push({
+ [ Op.in ]: Sequelize.literal(
'(SELECT "videoId" FROM "videoFile")'
)
})
}
if (options.tagsOneOf) {
- query.where[ 'id' ][ Sequelize.Op.and ].push({
- [ Sequelize.Op.in ]: Sequelize.literal(
+ query.where[ 'id' ][ Op.and ].push({
+ [ Op.in ]: Sequelize.literal(
'(' +
'SELECT "videoId" FROM "videoTag" ' +
'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
}
if (options.tagsAllOf) {
- query.where[ 'id' ][ Sequelize.Op.and ].push({
- [ Sequelize.Op.in ]: Sequelize.literal(
+ query.where[ 'id' ][ Op.and ].push({
+ [ Op.in ]: Sequelize.literal(
'(' +
'SELECT "videoId" FROM "videoTag" ' +
'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
if (options.categoryOneOf) {
query.where[ 'category' ] = {
- [ Sequelize.Op.or ]: options.categoryOneOf
+ [ Op.or ]: options.categoryOneOf
}
}
if (options.licenceOneOf) {
query.where[ 'licence' ] = {
- [ Sequelize.Op.or ]: options.licenceOneOf
+ [ Op.or ]: options.licenceOneOf
}
}
if (options.languageOneOf) {
query.where[ 'language' ] = {
- [ Sequelize.Op.or ]: options.languageOneOf
+ [ Op.or ]: options.languageOneOf
}
}
}
]
}
- ]
+ ] as any // FIXME: sequelize typings
},
[ ScopeNames.WITH_ACCOUNT_DETAILS ]: {
include: [
}
]
}
- ]
+ ] as any // FIXME: sequelize typings
},
[ ScopeNames.WITH_TAGS ]: {
include: [ () => TagModel ]
@AllowNull(true)
@Default(null)
- @Is('VideoCategory', value => throwIfNotValid(value, isVideoCategoryValid, 'category'))
+ @Is('VideoCategory', value => throwIfNotValid(value, isVideoCategoryValid, 'category', true))
@Column
category: number
@AllowNull(true)
@Default(null)
- @Is('VideoLicence', value => throwIfNotValid(value, isVideoLicenceValid, 'licence'))
+ @Is('VideoLicence', value => throwIfNotValid(value, isVideoLicenceValid, 'licence', true))
@Column
licence: number
@AllowNull(true)
@Default(null)
- @Is('VideoLanguage', value => throwIfNotValid(value, isVideoLanguageValid, 'language'))
+ @Is('VideoLanguage', value => throwIfNotValid(value, isVideoLanguageValid, 'language', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.LANGUAGE.max))
language: string
@AllowNull(true)
@Default(null)
- @Is('VideoDescription', value => throwIfNotValid(value, isVideoDescriptionValid, 'description'))
+ @Is('VideoDescription', value => throwIfNotValid(value, isVideoDescriptionValid, 'description', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max))
description: string
@AllowNull(true)
@Default(null)
- @Is('VideoSupport', value => throwIfNotValid(value, isVideoSupportValid, 'support'))
+ @Is('VideoSupport', value => throwIfNotValid(value, isVideoSupportValid, 'support', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.SUPPORT.max))
support: string
updatedAt: Date
@AllowNull(false)
- @Default(Sequelize.NOW)
+ @Default(DataType.NOW)
@Column
publishedAt: Date
distinct: true,
offset: start,
limit: count,
- order: getVideoSort('createdAt', [ 'Tags', 'name', 'ASC' ]),
+ order: getVideoSort('createdAt', [ 'Tags', 'name', 'ASC' ] as any), // FIXME: sequelize typings
where: {
id: {
- [ Sequelize.Op.in ]: Sequelize.literal('(' + rawQuery + ')')
+ [ Op.in ]: Sequelize.literal('(' + rawQuery + ')')
},
- [ Sequelize.Op.or ]: [
+ [ Op.or ]: [
{ privacy: VideoPrivacy.PUBLIC },
{ privacy: VideoPrivacy.UNLISTED }
]
required: false,
// We only want videos shared by this actor
where: {
- [ Sequelize.Op.and ]: [
+ [ Op.and ]: [
{
id: {
- [ Sequelize.Op.not ]: null
+ [ Op.not ]: null
}
},
{
return Bluebird.all([
// FIXME: typing issue
VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findAll(query as any),
- VideoModel.sequelize.query(rawCountQuery, { type: Sequelize.QueryTypes.SELECT })
+ VideoModel.sequelize.query<{ total: number }>(rawCountQuery, { type: QueryTypes.SELECT })
]).then(([ rows, totals ]) => {
// totals: totalVideos + totalVideoShares
let totalVideos = 0
let totalVideoShares = 0
- if (totals[ 0 ]) totalVideos = parseInt(totals[ 0 ].total, 10)
- if (totals[ 1 ]) totalVideoShares = parseInt(totals[ 1 ].total, 10)
+ if (totals[ 0 ]) totalVideos = parseInt(totals[ 0 ].total + '', 10)
+ if (totals[ 1 ]) totalVideoShares = parseInt(totals[ 1 ].total + '', 10)
const total = totalVideos + totalVideoShares
return {
}
static listUserVideosForApi (accountId: number, start: number, count: number, sort: string, withFiles = false) {
- const query: IFindOptions<VideoModel> = {
+ const query: FindOptions = {
offset: start,
limit: count,
order: getVideoSort(sort),
throw new Error('Try to filter all-local but no user has not the see all videos right')
}
- const query: IFindOptions<VideoModel> = {
+ const query: FindOptions = {
offset: options.start,
limit: options.count,
order: getVideoSort(options.sort)
if (options.startDate || options.endDate) {
const publishedAtRange = {}
- if (options.startDate) publishedAtRange[ Sequelize.Op.gte ] = options.startDate
- if (options.endDate) publishedAtRange[ Sequelize.Op.lte ] = options.endDate
+ if (options.startDate) publishedAtRange[ Op.gte ] = options.startDate
+ if (options.endDate) publishedAtRange[ Op.lte ] = options.endDate
whereAnd.push({ publishedAt: publishedAtRange })
}
if (options.originallyPublishedStartDate || options.originallyPublishedEndDate) {
const originallyPublishedAtRange = {}
- if (options.originallyPublishedStartDate) originallyPublishedAtRange[ Sequelize.Op.gte ] = options.originallyPublishedStartDate
- if (options.originallyPublishedEndDate) originallyPublishedAtRange[ Sequelize.Op.lte ] = options.originallyPublishedEndDate
+ if (options.originallyPublishedStartDate) originallyPublishedAtRange[ Op.gte ] = options.originallyPublishedStartDate
+ if (options.originallyPublishedEndDate) originallyPublishedAtRange[ Op.lte ] = options.originallyPublishedEndDate
whereAnd.push({ originallyPublishedAt: originallyPublishedAtRange })
}
if (options.durationMin || options.durationMax) {
const durationRange = {}
- if (options.durationMin) durationRange[ Sequelize.Op.gte ] = options.durationMin
- if (options.durationMax) durationRange[ Sequelize.Op.lte ] = options.durationMax
+ if (options.durationMin) durationRange[ Op.gte ] = options.durationMin
+ if (options.durationMax) durationRange[ Op.lte ] = options.durationMax
whereAnd.push({ duration: durationRange })
}
whereAnd.push(
{
id: {
- [ Sequelize.Op.in ]: Sequelize.literal(
+ [ Op.in ]: Sequelize.literal(
'(' +
'SELECT "video"."id" FROM "video" ' +
'WHERE ' +
)
}
- const query: IFindOptions<VideoModel> = {
+ const query: FindOptions = {
attributes: {
include: attributesInclude
},
limit: options.count,
order: getVideoSort(options.sort),
where: {
- [ Sequelize.Op.and ]: whereAnd
+ [ Op.and ]: whereAnd
}
}
return VideoModel.getAvailableForApi(query, queryOptions)
}
- static load (id: number | string, t?: Sequelize.Transaction) {
+ static load (id: number | string, t?: Transaction) {
const where = buildWhereIdOrUUID(id)
const options = {
where,
return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
}
- static loadWithRights (id: number | string, t?: Sequelize.Transaction) {
+ static loadWithRights (id: number | string, t?: Transaction) {
const where = buildWhereIdOrUUID(id)
const options = {
where,
]).findOne(options)
}
- static loadOnlyId (id: number | string, t?: Sequelize.Transaction) {
+ static loadOnlyId (id: number | string, t?: Transaction) {
const where = buildWhereIdOrUUID(id)
const options = {
return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
}
- static loadWithFiles (id: number, t?: Sequelize.Transaction, logging?: boolean) {
+ static loadWithFiles (id: number, t?: Transaction, logging?: boolean) {
return VideoModel.scope([
ScopeNames.WITH_FILES,
ScopeNames.WITH_STREAMING_PLAYLISTS,
return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
}
- static loadByUrl (url: string, transaction?: Sequelize.Transaction) {
- const query: IFindOptions<VideoModel> = {
+ static loadByUrl (url: string, transaction?: Transaction) {
+ const query: FindOptions = {
where: {
url
},
return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query)
}
- static loadByUrlAndPopulateAccount (url: string, transaction?: Sequelize.Transaction) {
- const query: IFindOptions<VideoModel> = {
+ static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction) {
+ const query: FindOptions = {
where: {
url
},
]).findOne(query)
}
- static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Sequelize.Transaction, userId?: number) {
+ static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number) {
const where = buildWhereIdOrUUID(id)
const options = {
- order: [ [ 'Tags', 'name', 'ASC' ] ],
+ order: [ [ 'Tags', 'name', 'ASC' ] ] as any, // FIXME: sequelize typings
where,
transaction: t
}
.findOne(options)
}
- static loadForGetAPI (id: number | string, t?: Sequelize.Transaction, userId?: number) {
+ static loadForGetAPI (id: number | string, t?: Transaction, userId?: number) {
const where = buildWhereIdOrUUID(id)
const options = {
- order: [ [ 'Tags', 'name', 'ASC' ] ],
+ order: [ [ 'Tags', 'name', 'ASC' ] ] as any, // FIXME: sequelize typings
where,
transaction: t
}
'LIMIT 1'
const options = {
- type: Sequelize.QueryTypes.SELECT,
+ type: QueryTypes.SELECT,
bind: { followerActorId, videoId },
raw: true
}
includeLocalVideos: true
}
- const query: IFindOptions<VideoModel> = {
+ const query: FindOptions = {
attributes: [ field ],
limit: count,
group: field,
having: Sequelize.where(Sequelize.fn('COUNT', Sequelize.col(field)), {
- [ Sequelize.Op.gte ]: threshold
+ [ Op.gte ]: threshold
}) as any, // FIXME: typings
- order: [ this.sequelize.random() ]
+ order: [ (this.sequelize as any).random() ]
}
return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST_IDS, scopeOptions ] })
required: false,
where: {
startDate: {
- [ Sequelize.Op.gte ]: new Date(new Date().getTime() - (24 * 3600 * 1000) * trendingDays)
+ [ Op.gte ]: new Date(new Date().getTime() - (24 * 3600 * 1000) * trendingDays)
}
}
}
}
private static async getAvailableForApi (
- query: IFindOptions<VideoModel>,
+ query: FindOptions,
options: AvailableForListIDsOptions,
countVideos = true
) {
- const idsScope = {
+ const idsScope: ScopeOptions = {
method: [
ScopeNames.AVAILABLE_FOR_LIST_IDS, options
]
// Remove trending sort on count, because it uses a group by
const countOptions = Object.assign({}, options, { trendingDays: undefined })
- const countQuery = Object.assign({}, query, { attributes: undefined, group: undefined })
- const countScope = {
+ const countQuery: CountOptions = Object.assign({}, query, { attributes: undefined, group: undefined })
+ const countScope: ScopeOptions = {
method: [
ScopeNames.AVAILABLE_FOR_LIST_IDS, countOptions
]
if (ids.length === 0) return { data: [], total: count }
- const secondQuery: IFindOptions<VideoModel> = {
+ const secondQuery: FindOptions = {
offset: 0,
limit: query.limit,
attributes: query.attributes,
-import * as Sequelize from 'sequelize'
+import { QueryTypes, Sequelize } from 'sequelize'
-let sequelizes: { [ id: number ]: Sequelize.Sequelize } = {}
+let sequelizes: { [ id: number ]: Sequelize } = {}
function getSequelize (serverNumber: number) {
if (sequelizes[serverNumber]) return sequelizes[serverNumber]
function setActorField (serverNumber: number, to: string, field: string, value: string) {
const seq = getSequelize(serverNumber)
- const options = { type: Sequelize.QueryTypes.UPDATE }
+ const options = { type: QueryTypes.UPDATE }
return seq.query(`UPDATE actor SET "${field}" = '${value}' WHERE url = '${to}'`, options)
}
function setVideoField (serverNumber: number, uuid: string, field: string, value: string) {
const seq = getSequelize(serverNumber)
- const options = { type: Sequelize.QueryTypes.UPDATE }
+ const options = { type: QueryTypes.UPDATE }
return seq.query(`UPDATE video SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options)
}
function setPlaylistField (serverNumber: number, uuid: string, field: string, value: string) {
const seq = getSequelize(serverNumber)
- const options = { type: Sequelize.QueryTypes.UPDATE }
+ const options = { type: QueryTypes.UPDATE }
return seq.query(`UPDATE "videoPlaylist" SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options)
}
// tslint:disable
const query = `SELECT SUM("videoView"."views") AS "total" FROM "videoView" INNER JOIN "video" ON "video"."id" = "videoView"."videoId" WHERE "video"."uuid" = '${uuid}'`
- const options = { type: Sequelize.QueryTypes.SELECT }
- const [ { total } ] = await seq.query(query, options)
+ const options = { type: QueryTypes.SELECT as QueryTypes.SELECT }
+ const [ { total } ] = await seq.query<{ total: number }>(query, options)
if (!total) return 0
- return parseInt(total, 10)
+ // FIXME: check if we really need parseInt
+ return parseInt(total + '', 10)
}
async function closeAllSequelize (servers: any[]) {
dependencies:
"@types/node" "*"
-"@types/bluebird@*", "@types/bluebird@3.5.18", "@types/bluebird@3.5.21":
+"@types/bluebird@*", "@types/bluebird@3.5.21":
version "3.5.21"
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.21.tgz#567615589cc913e84a28ecf9edb031732bdf2634"
integrity sha512-6UNEwyw+6SGMC/WMI0ld0PS4st7Qq51qgguFrFizOSpGvZiqe9iswztFSdZvwJBEhLOy2JaxNE6VC7yMAlbfyQ==
dependencies:
"@types/node" "*"
-"@types/continuation-local-storage@*":
- version "3.2.1"
- resolved "https://registry.yarnpkg.com/@types/continuation-local-storage/-/continuation-local-storage-3.2.1.tgz#a33e0df9dce9b424d1c98fc4fdebd8578dceec7e"
- integrity sha1-oz4N+dzptCTRyY/E/evYV43O7H4=
- dependencies:
- "@types/node" "*"
-
"@types/cookiejar@*":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@types/cookiejar/-/cookiejar-2.1.1.tgz#90b68446364baf9efd8e8349bb36bd3852b75b80"
dependencies:
"@types/node" "*"
-"@types/geojson@^1.0.0":
- version "1.0.6"
- resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-1.0.6.tgz#3e02972728c69248c2af08d60a48cbb8680fffdf"
- integrity sha512-Xqg/lIZMrUd0VRmSRbCAewtwGZiAk3mEUDvV4op1tGl+LvyPcb/MIOSxTl9z+9+J+R4/vpjiCAT4xeKzH9ji1w==
-
"@types/ioredis@*":
version "4.0.10"
resolved "https://registry.yarnpkg.com/@types/ioredis/-/ioredis-4.0.10.tgz#ca8bd95ca7d5fee32cbc5a0bf92fc29264bee237"
dependencies:
"@types/node" "*"
-"@types/lodash@*", "@types/lodash@^4.14.64":
+"@types/lodash@^4.14.64":
version "4.14.123"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.123.tgz#39be5d211478c8dd3bdae98ee75bb7efe4abfe4d"
integrity sha512-pQvPkc4Nltyx7G1Ww45OjVqUsJP4UsZm+GWJpigXgkikZqJgRm4c48g027o6tdgubWHwFRF15iFd+Y4Pmqv6+Q==
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.13.0.tgz#b0df8d6ef9b5001b2be3a94d909ce3c29a80f9e1"
integrity sha512-rx29MMkRdVmzunmiA4lzBYJNnXsW/PhG4kMBy2ATsYaDjGGR75dCFEVVROKpNwlVdcUX3xxlghKQOeDPBJobng==
-"@types/node@6.0.41":
- version "6.0.41"
- resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.41.tgz#578cf53aaec65887bcaf16792f8722932e8ff8ea"
- integrity sha1-V4z1Oq7GWIe8rxZ5L4ciky6P+Oo=
-
"@types/node@^10.0.8":
version "10.14.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.4.tgz#1c586b991457cbb58fef51bc4e0cfcfa347714b5"
"@types/node" "*"
"@types/tough-cookie" "*"
-"@types/sequelize@4.27.24":
- version "4.27.24"
- resolved "https://registry.yarnpkg.com/@types/sequelize/-/sequelize-4.27.24.tgz#7d593c062c368f570c68b0217f5c1d4c892ead48"
- integrity sha512-5uMFsMa/0hU/7/8znyfBKSJy2Mbd57uRpYk5X1+Phz9dN0MRZLbTbj1JMeB3CJ4R9b1coNQGfp2kXh4OjI9UyA==
- dependencies:
- "@types/bluebird" "*"
- "@types/continuation-local-storage" "*"
- "@types/lodash" "*"
- "@types/validator" "*"
-
"@types/serve-static@*":
version "1.13.2"
resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.2.tgz#f5ac4d7a6420a99a6a45af4719f4dcd8cd907a48"
resolved "https://registry.yarnpkg.com/@types/tv4/-/tv4-1.2.29.tgz#4c6d2222b03245dd2104f4fd67f54d1658985911"
integrity sha512-NtJmi+XbYocrLb5Au4Q64srX4FlCPDvrSF/OnK3H0QJwrw40tIUoQPDoUHnZ5wpAB2KThtVyeS+kOEQyZabORg==
-"@types/validator@*", "@types/validator@^10.9.0":
+"@types/validator@^10.9.0":
version "10.11.0"
resolved "https://registry.yarnpkg.com/@types/validator/-/validator-10.11.0.tgz#aae9009ce28cc4f878e32c34d3900a81193c98d5"
integrity sha512-i1aY7RKb6HmQIEnK0cBmUZUp1URx0riIHw/GYNoZ46Su0GWfLiDmMI8zMRmaauMnOTg2bQag0qfwcyUFC9Tn+A==
resolved "https://registry.yarnpkg.com/any-observable/-/any-observable-0.3.0.tgz#af933475e5806a67d0d7df090dd5e8bef65d119b"
integrity sha512-/FQM1EDkTsf63Ub2C6O7GuYFDsSXUwsaZDurV0np41ocwq0jthUAYCmhBX9f+KwlaCgIuWyr/4WlUQUBfKfZog==
+any-promise@^1.3.0:
+ version "1.3.0"
+ resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"
+ integrity sha1-q8av7tzqUugJzcA3au0845Y10X8=
+
anymatch@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-2.0.0.tgz#bcb24b4f37934d9aa7ac17b4adaf89e7c76ef2eb"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1"
integrity sha1-U0uQM8AiyVecVro7Plpcqvu2UOE=
-bluebird@^3.0.5, bluebird@^3.4.6, bluebird@^3.5.0, bluebird@^3.5.1, bluebird@^3.5.3:
+bluebird@^3.0.5, bluebird@^3.5.0, bluebird@^3.5.1, bluebird@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7"
integrity sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==
dependencies:
ms "0.7.2"
-debug@2.6.9, debug@^2.1.1, debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
+debug@2.6.9, debug@^2.1.1, debug@^2.1.2, debug@^2.2.0, debug@^2.3.3:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
dependencies:
ms "^2.1.1"
-debug@^4.0.1, debug@^4.1.0, debug@~4.1.0:
+debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@~4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df"
integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==
-depd@^1.1.0, depd@~1.1.0, depd@~1.1.2:
+depd@~1.1.0, depd@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9"
integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=
es6-symbol "3.1.1"
event-emitter "~0.3.5"
-es6-shim@0.35.3:
- version "0.35.3"
- resolved "https://registry.yarnpkg.com/es6-shim/-/es6-shim-0.35.3.tgz#9bfb7363feffff87a6cdb6cd93e405ec3c4b6f26"
- integrity sha1-m/tzY/7//4emzbbNk+QF7DxLbyY=
-
es6-symbol@3.1.1, es6-symbol@^3.1.1, es6-symbol@~3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.1.tgz#bf00ef4fdab6ba1b46ecb7b629b4c7ed5715cc77"
dependencies:
is-property "^1.0.0"
-generic-pool@^3.4.0:
- version "3.7.1"
- resolved "https://registry.yarnpkg.com/generic-pool/-/generic-pool-3.7.1.tgz#36fe5bb83e7e0e032e5d32cd05dc00f5ff119aa8"
- integrity sha512-ug6DAZoNgWm6q5KhPFA+hzXfBLFQu5sTXxPpv44DmE0A2g+CiHoq9LTVdkXpZMkYVMoGw83F6W+WT0h0MFMK/w==
-
genfun@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/genfun/-/genfun-5.0.0.tgz#9dd9710a06900a5c4a5bf57aca5da4e52fe76537"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
integrity sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=
-lodash@^4.0.0, lodash@^4.17.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.3.0, lodash@~4.17.10:
+lodash@^4.0.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.3.0, lodash@~4.17.10:
version "4.17.11"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==
yargs-parser "11.1.1"
yargs-unparser "1.5.0"
-moment-timezone@^0.5.14, moment-timezone@^0.5.23:
+moment-timezone@^0.5.21, moment-timezone@^0.5.23:
version "0.5.23"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.23.tgz#7cbb00db2c14c71b19303cb47b0fb0a6d8651463"
integrity sha512-WHFH85DkCfiNMDX5D3X7hpNH3/PUhjTGcD0U1SgfBGZxJ3qUmJh5FdvaFjcClxOvB3rzdfj4oRffbI38jEnC1w==
dependencies:
moment ">= 2.9.0"
-"moment@>= 2.9.0", moment@^2.20.0:
+"moment@>= 2.9.0", moment@^2.24.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==
resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc"
integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==
-retry-as-promised@^2.3.2:
- version "2.3.2"
- resolved "https://registry.yarnpkg.com/retry-as-promised/-/retry-as-promised-2.3.2.tgz#cd974ee4fd9b5fe03cbf31871ee48221c07737b7"
- integrity sha1-zZdO5P2bX+A8vzGHHuSCIcB3N7c=
+retry-as-promised@^3.1.0:
+ version "3.2.0"
+ resolved "https://registry.yarnpkg.com/retry-as-promised/-/retry-as-promised-3.2.0.tgz#769f63d536bec4783549db0777cb56dadd9d8543"
+ integrity sha512-CybGs60B7oYU/qSQ6kuaFmRd9sTZ6oXSc0toqePvV74Ac6/IFZSI1ReFQmtCN+uvW1Mtqdwpvt/LGOiCBAY2Mg==
dependencies:
- bluebird "^3.4.6"
- debug "^2.6.9"
+ any-promise "^1.3.0"
retry@^0.10.0:
version "0.10.1"
range-parser "~1.2.0"
statuses "~1.4.0"
-sequelize-typescript@0.6.7:
- version "0.6.7"
- resolved "https://registry.yarnpkg.com/sequelize-typescript/-/sequelize-typescript-0.6.7.tgz#372be979cbae060c554fdbaf2c2d8c93a0283303"
- integrity sha512-ae21Gq9VOVXlIjnh2vLdL42Kev6r4LC82xOQ2fXo0lHzQvjFeH8/GaWUlpvYv57AOgc+ZnElbYFbSLKdT9ue0w==
+sequelize-pool@^1.0.2:
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/sequelize-pool/-/sequelize-pool-1.0.2.tgz#89c767882bbdb8a41dac66922ed9820939a5401e"
+ integrity sha512-VMKl/gCCdIvB1gFZ7p+oqLFEyZEz3oMMYjkKvfEC7GoO9bBcxmfOOU9RdkoltfXGgBZFigSChihRly2gKtsh2w==
+ dependencies:
+ bluebird "^3.5.3"
+
+sequelize-typescript@^1.0.0-beta.1:
+ version "1.0.0-beta.1"
+ resolved "https://registry.yarnpkg.com/sequelize-typescript/-/sequelize-typescript-1.0.0-beta.1.tgz#402279fec52669cbd78ecbf50e189638483a7360"
+ integrity sha512-xD28kqa1rIKujlmgA4hWQgtwFfRM6tLv1/mnZOrOFEZxvSWazUbTzqGB7OZydZDNj3iJnyrV1l6i6HOfvrpvEw==
dependencies:
- "@types/bluebird" "3.5.18"
- "@types/node" "6.0.41"
- "@types/sequelize" "4.27.24"
- es6-shim "0.35.3"
glob "7.1.2"
-sequelize@4.42.0:
- version "4.42.0"
- resolved "https://registry.yarnpkg.com/sequelize/-/sequelize-4.42.0.tgz#439467ba7bfe7d5afcc56d62b3e091860fbf18f3"
- integrity sha512-qxAYnX4rcv7PbNtEidb56REpxNJCdbN0qyk1jb3+e6sE7OrmS0nYMU+MFVbNTJtZfSpOEEL1TX0TkMw+wzZBxg==
+sequelize@5.6.1:
+ version "5.6.1"
+ resolved "https://registry.yarnpkg.com/sequelize/-/sequelize-5.6.1.tgz#fc22306109fb2504a6573edfb3c469ec86fae873"
+ integrity sha512-QsXUDar6ow0HrF9BtnHRaNumu6qRYb97dfwvez/Z5guH3i6w6k8+bp6gP3VCiDC+2qX+jQIyrYohKg9evy8GFg==
dependencies:
bluebird "^3.5.0"
cls-bluebird "^2.1.0"
- debug "^3.1.0"
- depd "^1.1.0"
+ debug "^4.1.1"
dottie "^2.0.0"
- generic-pool "^3.4.0"
inflection "1.12.0"
- lodash "^4.17.1"
- moment "^2.20.0"
- moment-timezone "^0.5.14"
- retry-as-promised "^2.3.2"
- semver "^5.5.0"
- terraformer-wkt-parser "^1.1.2"
+ lodash "^4.17.11"
+ moment "^2.24.0"
+ moment-timezone "^0.5.21"
+ retry-as-promised "^3.1.0"
+ semver "^5.6.0"
+ sequelize-pool "^1.0.2"
toposort-class "^1.0.1"
uuid "^3.2.1"
- validator "^10.4.0"
- wkx "^0.4.1"
+ validator "^10.11.0"
+ wkx "^0.4.6"
serve-static@1.13.2:
version "1.13.2"
dependencies:
execa "^0.7.0"
-terraformer-wkt-parser@^1.1.2:
- version "1.2.0"
- resolved "https://registry.yarnpkg.com/terraformer-wkt-parser/-/terraformer-wkt-parser-1.2.0.tgz#c9d6ac3dff25f4c0bd344e961f42694961834c34"
- integrity sha512-QU3iA54St5lF8Za1jg1oj4NYc8sn5tCZ08aNSWDeGzrsaV48eZk1iAVWasxhNspYBoCqdHuoot1pUTUrE1AJ4w==
- dependencies:
- "@types/geojson" "^1.0.0"
- terraformer "~1.0.5"
-
-terraformer@~1.0.5:
- version "1.0.9"
- resolved "https://registry.yarnpkg.com/terraformer/-/terraformer-1.0.9.tgz#77851fef4a49c90b345dc53cf26809fdf29dcda6"
- integrity sha512-YlmQ1fsMWTkKGDGibCRWgmLzrpDRUr63Q025LJ/taYQ6j1Yb8q9McKF7NBi6ACAyUXO6F/bl9w6v4MY307y5Ag==
- optionalDependencies:
- "@types/geojson" "^1.0.0"
-
text-hex@1.0.x:
version "1.0.0"
resolved "https://registry.yarnpkg.com/text-hex/-/text-hex-1.0.0.tgz#69dc9c1b17446ee79a92bf5b884bb4b9127506f5"
dependencies:
builtins "^1.0.3"
-validator@^10.0.0, validator@^10.2.0, validator@^10.4.0:
+validator@^10.0.0, validator@^10.11.0, validator@^10.2.0, validator@^10.4.0:
version "10.11.0"
resolved "https://registry.yarnpkg.com/validator/-/validator-10.11.0.tgz#003108ea6e9a9874d31ccc9e5006856ccd76b228"
integrity sha512-X/p3UZerAIsbBfN/IwahhYaBbY68EN/UQBWHtsbXGT5bfrH/p4NQzUCG1kF/rtKaNpnJ7jAu6NGTdSNtyNIXMw==
triple-beam "^1.3.0"
winston-transport "^4.3.0"
-wkx@^0.4.1:
+wkx@^0.4.6:
version "0.4.6"
resolved "https://registry.yarnpkg.com/wkx/-/wkx-0.4.6.tgz#228ab592e6457382ea6fb79fc825058d07fce523"
integrity sha512-LHxXlzRCYQXA9ZHgs8r7Gafh0gVOE8o3QmudM1PIkOdkXXjW7Thcl+gb2P2dRuKgW8cqkitCRZkkjtmWzpHi7A==