-import * as Sequelize from 'sequelize'
-import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers'
-import { isVideoChannelUrlValid } from '../../helpers/custom-validators/video-channels'
-import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
-import { sendDeleteVideoChannel } from '../../lib/activitypub/send/send-delete'
-
-import { addMethodsToModel, getSort } from '../utils'
-import { VideoChannelAttributes, VideoChannelInstance, VideoChannelMethods } from './video-channel-interface'
-
-let VideoChannel: Sequelize.Model<VideoChannelInstance, VideoChannelAttributes>
-let toFormattedJSON: VideoChannelMethods.ToFormattedJSON
-let toActivityPubObject: VideoChannelMethods.ToActivityPubObject
-let isOwned: VideoChannelMethods.IsOwned
-let countByAccount: VideoChannelMethods.CountByAccount
-let listForApi: VideoChannelMethods.ListForApi
-let listByAccount: VideoChannelMethods.ListByAccount
-let loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount
-let loadByUUID: VideoChannelMethods.LoadByUUID
-let loadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccount
-let loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount
-let loadByHostAndUUID: VideoChannelMethods.LoadByHostAndUUID
-let loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos
-let loadByUrl: VideoChannelMethods.LoadByUrl
-let loadByUUIDOrUrl: VideoChannelMethods.LoadByUUIDOrUrl
-
-export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
- VideoChannel = sequelize.define<VideoChannelInstance, VideoChannelAttributes>('VideoChannel',
- {
- uuid: {
- type: DataTypes.UUID,
- defaultValue: DataTypes.UUIDV4,
- allowNull: false,
- validate: {
- isUUID: 4
- }
- },
- name: {
- type: DataTypes.STRING,
- allowNull: false,
- validate: {
- nameValid: value => {
- const res = isVideoChannelNameValid(value)
- if (res === false) throw new Error('Video channel name is not valid.')
- }
- }
- },
- description: {
- type: DataTypes.STRING,
- allowNull: true,
- validate: {
- descriptionValid: value => {
- const res = isVideoChannelDescriptionValid(value)
- if (res === false) throw new Error('Video channel description is not valid.')
- }
- }
- },
- remote: {
- type: DataTypes.BOOLEAN,
- allowNull: false,
- defaultValue: false
- },
- url: {
- type: DataTypes.STRING(CONSTRAINTS_FIELDS.VIDEO_CHANNELS.URL.max),
- allowNull: false,
- validate: {
- urlValid: value => {
- const res = isVideoChannelUrlValid(value)
- if (res === false) throw new Error('Video channel URL is not valid.')
- }
- }
- }
- },
- {
- indexes: [
- {
- fields: [ 'accountId' ]
- }
- ],
- hooks: {
- afterDestroy
- }
- }
- )
-
- const classMethods = [
- associate,
-
- listForApi,
- listByAccount,
- loadByIdAndAccount,
- loadAndPopulateAccount,
- loadByUUIDAndPopulateAccount,
- loadByUUID,
- loadByHostAndUUID,
- loadAndPopulateAccountAndVideos,
- countByAccount,
- loadByUrl,
- loadByUUIDOrUrl
- ]
- const instanceMethods = [
- isOwned,
- toFormattedJSON,
- toActivityPubObject
- ]
- addMethodsToModel(VideoChannel, classMethods, instanceMethods)
+import {
+ AllowNull,
+ BeforeDestroy,
+ BelongsTo,
+ Column,
+ CreatedAt,
+ DataType,
+ Default,
+ DefaultScope,
+ ForeignKey,
+ HasMany,
+ Is,
+ Model,
+ Scopes,
+ Sequelize,
+ Table,
+ UpdatedAt
+} from 'sequelize-typescript'
+import { ActivityPubActor } from '../../../shared/models/activitypub'
+import { VideoChannel } from '../../../shared/models/videos'
+import {
+ isVideoChannelDescriptionValid,
+ isVideoChannelNameValid,
+ isVideoChannelSupportValid
+} from '../../helpers/custom-validators/video-channels'
+import { sendDeleteActor } from '../../lib/activitypub/send'
+import { AccountModel } from '../account/account'
+import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor'
+import { buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils'
+import { VideoModel } from './video'
+import { CONSTRAINTS_FIELDS } from '../../initializers'
+import { ServerModel } from '../server/server'
+import { DefineIndexesOptions } from 'sequelize'
+
+// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
+const indexes: DefineIndexesOptions[] = [
+ buildTrigramSearchIndex('video_channel_name_trigram', 'name'),
+
+ {
+ fields: [ 'accountId' ]
+ },
+ {
+ fields: [ 'actorId' ]
+ }
+]