diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-24 10:28:57 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-24 16:26:22 +0200 |
commit | 9cc8d43e37a61709e7275c2a799bdf976dd940ca (patch) | |
tree | 0d8d8967d39d6ecebbc480be53c528e696ce30e7 /server | |
parent | 2fb5b3a55aeebcc77f4b3a0c029bbf0738ef0063 (diff) | |
download | PeerTube-9cc8d43e37a61709e7275c2a799bdf976dd940ca.tar.gz PeerTube-9cc8d43e37a61709e7275c2a799bdf976dd940ca.tar.zst PeerTube-9cc8d43e37a61709e7275c2a799bdf976dd940ca.zip |
Add migrations
Diffstat (limited to 'server')
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0370-thumbnail.ts | 50 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 5 | ||||
-rw-r--r-- | server/lib/thumbnail.ts | 22 | ||||
-rw-r--r-- | server/models/video/thumbnail.ts | 6 | ||||
-rw-r--r-- | server/models/video/video-format-utils.ts | 2 |
6 files changed, 70 insertions, 17 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 50a437b3d..2be364cc8 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' | |||
14 | 14 | ||
15 | // --------------------------------------------------------------------------- | 15 | // --------------------------------------------------------------------------- |
16 | 16 | ||
17 | const LAST_MIGRATION_VERSION = 365 | 17 | const LAST_MIGRATION_VERSION = 370 |
18 | 18 | ||
19 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
20 | 20 | ||
diff --git a/server/initializers/migrations/0370-thumbnail.ts b/server/initializers/migrations/0370-thumbnail.ts new file mode 100644 index 000000000..384ca1a15 --- /dev/null +++ b/server/initializers/migrations/0370-thumbnail.ts | |||
@@ -0,0 +1,50 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | async function up (utils: { | ||
4 | transaction: Sequelize.Transaction, | ||
5 | queryInterface: Sequelize.QueryInterface, | ||
6 | sequelize: Sequelize.Sequelize, | ||
7 | db: any | ||
8 | }): Promise<void> { | ||
9 | { | ||
10 | const query = ` | ||
11 | CREATE TABLE IF NOT EXISTS "thumbnail" | ||
12 | ( | ||
13 | "id" SERIAL, | ||
14 | "filename" VARCHAR(255) NOT NULL, | ||
15 | "height" INTEGER DEFAULT NULL, | ||
16 | "width" INTEGER DEFAULT NULL, | ||
17 | "type" INTEGER NOT NULL, | ||
18 | "fileUrl" VARCHAR(255), | ||
19 | "videoId" INTEGER REFERENCES "video" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
20 | "videoPlaylistId" INTEGER REFERENCES "videoPlaylist" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
21 | "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, | ||
22 | "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, | ||
23 | PRIMARY KEY ("id") | ||
24 | );` | ||
25 | await utils.sequelize.query(query) | ||
26 | } | ||
27 | |||
28 | { | ||
29 | // All video thumbnails | ||
30 | const query = 'INSERT INTO "thumbnail" ("filename", "type", "videoId", "height", "width", "createdAt", "updatedAt")' + | ||
31 | 'SELECT uuid || \'.jpg\', 1, id, 110, 200, NOW(), NOW() FROM "video"' | ||
32 | await utils.sequelize.query(query) | ||
33 | } | ||
34 | |||
35 | { | ||
36 | // All video previews | ||
37 | const query = 'INSERT INTO "thumbnail" ("filename", "type", "videoId", "height", "width", "createdAt", "updatedAt")' + | ||
38 | 'SELECT uuid || \'.jpg\', 2, id, 315, 560, NOW(), NOW() FROM "video"' | ||
39 | await utils.sequelize.query(query) | ||
40 | } | ||
41 | } | ||
42 | |||
43 | function down (options) { | ||
44 | throw new Error('Not implemented.') | ||
45 | } | ||
46 | |||
47 | export { | ||
48 | up, | ||
49 | down | ||
50 | } | ||
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index ed0177a67..2d48848fe 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -108,7 +108,10 @@ async function processUndoCacheFile (byActor: ActorModel, activity: ActivityUndo | |||
108 | 108 | ||
109 | return sequelizeTypescript.transaction(async t => { | 109 | return sequelizeTypescript.transaction(async t => { |
110 | const cacheFile = await VideoRedundancyModel.loadByUrl(cacheFileObject.id) | 110 | const cacheFile = await VideoRedundancyModel.loadByUrl(cacheFileObject.id) |
111 | if (!cacheFile) throw new Error('Unknown video cache ' + cacheFileObject.id) | 111 | if (!cacheFile) { |
112 | logger.debug('Cannot undo unknown video cache %s.', cacheFileObject.id) | ||
113 | return | ||
114 | } | ||
112 | 115 | ||
113 | if (cacheFile.actorId !== byActor.id) throw new Error('Cannot delete redundancy ' + cacheFile.url + ' of another actor.') | 116 | if (cacheFile.actorId !== byActor.id) throw new Error('Cannot delete redundancy ' + cacheFile.url + ' of another actor.') |
114 | 117 | ||
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index 4ba521b97..950b14c3b 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts | |||
@@ -20,19 +20,19 @@ function createPlaylistMiniatureFromExisting (inputPath: string, playlist: Video | |||
20 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) | 20 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) |
21 | } | 21 | } |
22 | 22 | ||
23 | function createPlaylistMiniatureFromUrl (url: string, playlist: VideoPlaylistModel, size?: ImageSize) { | 23 | function createPlaylistMiniatureFromUrl (fileUrl: string, playlist: VideoPlaylistModel, size?: ImageSize) { |
24 | const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) | 24 | const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) |
25 | const type = ThumbnailType.MINIATURE | 25 | const type = ThumbnailType.MINIATURE |
26 | 26 | ||
27 | const thumbnailCreator = () => downloadImage(url, basePath, filename, { width, height }) | 27 | const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height }) |
28 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, url }) | 28 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) |
29 | } | 29 | } |
30 | 30 | ||
31 | function createVideoMiniatureFromUrl (url: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) { | 31 | function createVideoMiniatureFromUrl (fileUrl: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) { |
32 | const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) | 32 | const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) |
33 | const thumbnailCreator = () => downloadImage(url, basePath, filename, { width, height }) | 33 | const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height }) |
34 | 34 | ||
35 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, url }) | 35 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) |
36 | } | 36 | } |
37 | 37 | ||
38 | function createVideoMiniatureFromExisting (inputPath: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) { | 38 | function createVideoMiniatureFromExisting (inputPath: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) { |
@@ -51,7 +51,7 @@ function generateVideoMiniature (video: VideoModel, videoFile: VideoFileModel, t | |||
51 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) | 51 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) |
52 | } | 52 | } |
53 | 53 | ||
54 | function createPlaceholderThumbnail (url: string, video: VideoModel, type: ThumbnailType, size: ImageSize) { | 54 | function createPlaceholderThumbnail (fileUrl: string, video: VideoModel, type: ThumbnailType, size: ImageSize) { |
55 | const { filename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) | 55 | const { filename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) |
56 | 56 | ||
57 | const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel() | 57 | const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel() |
@@ -60,7 +60,7 @@ function createPlaceholderThumbnail (url: string, video: VideoModel, type: Thumb | |||
60 | thumbnail.height = height | 60 | thumbnail.height = height |
61 | thumbnail.width = width | 61 | thumbnail.width = width |
62 | thumbnail.type = type | 62 | thumbnail.type = type |
63 | thumbnail.url = url | 63 | thumbnail.fileUrl = fileUrl |
64 | 64 | ||
65 | return thumbnail | 65 | return thumbnail |
66 | } | 66 | } |
@@ -132,10 +132,10 @@ async function createThumbnailFromFunction (parameters: { | |||
132 | height: number, | 132 | height: number, |
133 | width: number, | 133 | width: number, |
134 | type: ThumbnailType, | 134 | type: ThumbnailType, |
135 | url?: string, | 135 | fileUrl?: string, |
136 | existingThumbnail?: ThumbnailModel | 136 | existingThumbnail?: ThumbnailModel |
137 | }) { | 137 | }) { |
138 | const { thumbnailCreator, filename, width, height, type, existingThumbnail, url = null } = parameters | 138 | const { thumbnailCreator, filename, width, height, type, existingThumbnail, fileUrl = null } = parameters |
139 | 139 | ||
140 | const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel() | 140 | const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel() |
141 | 141 | ||
@@ -143,7 +143,7 @@ async function createThumbnailFromFunction (parameters: { | |||
143 | thumbnail.height = height | 143 | thumbnail.height = height |
144 | thumbnail.width = width | 144 | thumbnail.width = width |
145 | thumbnail.type = type | 145 | thumbnail.type = type |
146 | thumbnail.url = url | 146 | thumbnail.fileUrl = fileUrl |
147 | 147 | ||
148 | await thumbnailCreator() | 148 | await thumbnailCreator() |
149 | 149 | ||
diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts index ec945893f..206e9a3d6 100644 --- a/server/models/video/thumbnail.ts +++ b/server/models/video/thumbnail.ts | |||
@@ -42,7 +42,7 @@ export class ThumbnailModel extends Model<ThumbnailModel> { | |||
42 | 42 | ||
43 | @AllowNull(true) | 43 | @AllowNull(true) |
44 | @Column | 44 | @Column |
45 | url: string | 45 | fileUrl: string |
46 | 46 | ||
47 | @ForeignKey(() => VideoModel) | 47 | @ForeignKey(() => VideoModel) |
48 | @Column | 48 | @Column |
@@ -100,8 +100,8 @@ export class ThumbnailModel extends Model<ThumbnailModel> { | |||
100 | return videoUUID + '.jpg' | 100 | return videoUUID + '.jpg' |
101 | } | 101 | } |
102 | 102 | ||
103 | getUrl () { | 103 | getFileUrl () { |
104 | if (this.url) return this.url | 104 | if (this.fileUrl) return this.fileUrl |
105 | 105 | ||
106 | const staticPath = ThumbnailModel.types[this.type].staticPath | 106 | const staticPath = ThumbnailModel.types[this.type].staticPath |
107 | return WEBSERVER.URL + staticPath + this.filename | 107 | return WEBSERVER.URL + staticPath + this.filename |
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index 877fcbc57..b947eb16f 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts | |||
@@ -328,7 +328,7 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject { | |||
328 | subtitleLanguage, | 328 | subtitleLanguage, |
329 | icon: { | 329 | icon: { |
330 | type: 'Image', | 330 | type: 'Image', |
331 | url: miniature.getUrl(), | 331 | url: miniature.getFileUrl(), |
332 | mediaType: 'image/jpeg', | 332 | mediaType: 'image/jpeg', |
333 | width: miniature.width, | 333 | width: miniature.width, |
334 | height: miniature.height | 334 | height: miniature.height |