+import { remove } from 'fs-extra'
import { join } from 'path'
import {
AfterDestroy,
Table,
UpdatedAt
} from 'sequelize-typescript'
-import { CONSTRAINTS_FIELDS, LAZY_STATIC_PATHS, STATIC_PATHS, WEBSERVER } from '../../initializers/constants'
+import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub'
+import { MThumbnailVideo, MVideoAccountLight } from '@server/types/models'
+import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
import { logger } from '../../helpers/logger'
-import { remove } from 'fs-extra'
import { CONFIG } from '../../initializers/config'
+import { CONSTRAINTS_FIELDS, LAZY_STATIC_PATHS, STATIC_PATHS, WEBSERVER } from '../../initializers/constants'
import { VideoModel } from './video'
import { VideoPlaylistModel } from './video-playlist'
-import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
-import { MVideoAccountLight } from '@server/typings/models'
-import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub'
@Table({
tableName: 'thumbnail',
{
fields: [ 'videoPlaylistId' ],
unique: true
+ },
+ {
+ fields: [ 'filename', 'type' ],
+ unique: true
}
]
})
-export class ThumbnailModel extends Model<ThumbnailModel> {
+export class ThumbnailModel extends Model {
@AllowNull(false)
@Column
@UpdatedAt
updatedAt: Date
- private static types: { [ id in ThumbnailType ]: { label: string, directory: string, staticPath: string } } = {
+ private static readonly types: { [ id in ThumbnailType ]: { label: string, directory: string, staticPath: string } } = {
[ThumbnailType.MINIATURE]: {
label: 'miniature',
directory: CONFIG.STORAGE.THUMBNAILS_DIR,
.catch(err => logger.error('Cannot remove thumbnail file %s.', instance.filename, err))
}
- static loadByName (filename: string) {
+ static loadWithVideoByName (filename: string, thumbnailType: ThumbnailType): Promise<MThumbnailVideo> {
const query = {
where: {
- filename
- }
+ filename,
+ type: thumbnailType
+ },
+ include: [
+ {
+ model: VideoModel.unscoped(),
+ required: true
+ }
+ ]
}
return ThumbnailModel.findOne(query)
}
- static generateDefaultPreviewName (videoUUID: string) {
- return videoUUID + '.jpg'
- }
-
getFileUrl (video: MVideoAccountLight) {
const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename