diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/thumbnail.ts | 31 | ||||
-rw-r--r-- | server/models/video/video.ts | 5 |
2 files changed, 22 insertions, 14 deletions
diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts index 6878a3155..3cad6c668 100644 --- a/server/models/video/thumbnail.ts +++ b/server/models/video/thumbnail.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import { remove } from 'fs-extra' | ||
1 | import { join } from 'path' | 2 | import { join } from 'path' |
2 | import { | 3 | import { |
3 | AfterDestroy, | 4 | AfterDestroy, |
@@ -12,15 +13,14 @@ import { | |||
12 | Table, | 13 | Table, |
13 | UpdatedAt | 14 | UpdatedAt |
14 | } from 'sequelize-typescript' | 15 | } from 'sequelize-typescript' |
15 | import { CONSTRAINTS_FIELDS, LAZY_STATIC_PATHS, STATIC_PATHS, WEBSERVER } from '../../initializers/constants' | 16 | import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' |
17 | import { MThumbnailVideo, MVideoAccountLight } from '@server/types/models' | ||
18 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | ||
16 | import { logger } from '../../helpers/logger' | 19 | import { logger } from '../../helpers/logger' |
17 | import { remove } from 'fs-extra' | ||
18 | import { CONFIG } from '../../initializers/config' | 20 | import { CONFIG } from '../../initializers/config' |
21 | import { CONSTRAINTS_FIELDS, LAZY_STATIC_PATHS, STATIC_PATHS, WEBSERVER } from '../../initializers/constants' | ||
19 | import { VideoModel } from './video' | 22 | import { VideoModel } from './video' |
20 | import { VideoPlaylistModel } from './video-playlist' | 23 | import { VideoPlaylistModel } from './video-playlist' |
21 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | ||
22 | import { MVideoAccountLight } from '@server/types/models' | ||
23 | import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' | ||
24 | 24 | ||
25 | @Table({ | 25 | @Table({ |
26 | tableName: 'thumbnail', | 26 | tableName: 'thumbnail', |
@@ -31,6 +31,10 @@ import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' | |||
31 | { | 31 | { |
32 | fields: [ 'videoPlaylistId' ], | 32 | fields: [ 'videoPlaylistId' ], |
33 | unique: true | 33 | unique: true |
34 | }, | ||
35 | { | ||
36 | fields: [ 'filename', 'type' ], | ||
37 | unique: true | ||
34 | } | 38 | } |
35 | ] | 39 | ] |
36 | }) | 40 | }) |
@@ -114,20 +118,23 @@ export class ThumbnailModel extends Model { | |||
114 | .catch(err => logger.error('Cannot remove thumbnail file %s.', instance.filename, err)) | 118 | .catch(err => logger.error('Cannot remove thumbnail file %s.', instance.filename, err)) |
115 | } | 119 | } |
116 | 120 | ||
117 | static loadByName (filename: string) { | 121 | static loadWithVideoByName (filename: string, thumbnailType: ThumbnailType): Promise<MThumbnailVideo> { |
118 | const query = { | 122 | const query = { |
119 | where: { | 123 | where: { |
120 | filename | 124 | filename, |
121 | } | 125 | type: thumbnailType |
126 | }, | ||
127 | include: [ | ||
128 | { | ||
129 | model: VideoModel.unscoped(), | ||
130 | required: true | ||
131 | } | ||
132 | ] | ||
122 | } | 133 | } |
123 | 134 | ||
124 | return ThumbnailModel.findOne(query) | 135 | return ThumbnailModel.findOne(query) |
125 | } | 136 | } |
126 | 137 | ||
127 | static generateDefaultPreviewName (videoUUID: string) { | ||
128 | return videoUUID + '.jpg' | ||
129 | } | ||
130 | |||
131 | getFileUrl (video: MVideoAccountLight) { | 138 | getFileUrl (video: MVideoAccountLight) { |
132 | const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename | 139 | const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename |
133 | 140 | ||
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 14e80a3ba..3321deed3 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -130,6 +130,7 @@ import { VideoShareModel } from './video-share' | |||
130 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' | 130 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' |
131 | import { VideoTagModel } from './video-tag' | 131 | import { VideoTagModel } from './video-tag' |
132 | import { VideoViewModel } from './video-view' | 132 | import { VideoViewModel } from './video-view' |
133 | import { v4 as uuidv4 } from 'uuid' | ||
133 | 134 | ||
134 | export enum ScopeNames { | 135 | export enum ScopeNames { |
135 | AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', | 136 | AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', |
@@ -1827,7 +1828,7 @@ export class VideoModel extends Model { | |||
1827 | } | 1828 | } |
1828 | 1829 | ||
1829 | generateThumbnailName () { | 1830 | generateThumbnailName () { |
1830 | return this.uuid + '.jpg' | 1831 | return uuidv4() + '.jpg' |
1831 | } | 1832 | } |
1832 | 1833 | ||
1833 | getMiniature () { | 1834 | getMiniature () { |
@@ -1837,7 +1838,7 @@ export class VideoModel extends Model { | |||
1837 | } | 1838 | } |
1838 | 1839 | ||
1839 | generatePreviewName () { | 1840 | generatePreviewName () { |
1840 | return this.uuid + '.jpg' | 1841 | return uuidv4() + '.jpg' |
1841 | } | 1842 | } |
1842 | 1843 | ||
1843 | hasPreview () { | 1844 | hasPreview () { |