Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix video files duplicated when fps is null

Chocobozzz2e7cf5ae0cf8
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index de426c16e0..09ecedfa5b 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -16,7 +16,7 @@ let config: IConfig = require('config')
// ---------------------------------------------------------------------------
-const LAST_MIGRATION_VERSION = 270
+const LAST_MIGRATION_VERSION = 275
// ---------------------------------------------------------------------------
diff --git a/server/initializers/migrations/0260-upload_quota_daily.ts b/server/initializers/migrations/0260-upload-quota-daily.ts
similarity index 100%
rename from server/initializers/migrations/0260-upload_quota_daily.ts
rename to server/initializers/migrations/0260-upload-quota-daily.ts
diff --git a/server/initializers/migrations/0275-video-file-unique.ts b/server/initializers/migrations/0275-video-file-unique.ts
new file mode 100644
index 0000000000..fd89188c0e
--- /dev/null
+++ b/server/initializers/migrations/0275-video-file-unique.ts
@@ -0,0 +1,34 @@
+import * as Sequelize from 'sequelize'
+
+async function up (utils: {
+ transaction: Sequelize.Transaction
+ queryInterface: Sequelize.QueryInterface
+ sequelize: Sequelize.Sequelize
+}): Promise<any> {
+ {
+ const query = 'DELETE FROM "videoFile" vf1 USING "videoFile" vf2 WHERE vf1.id < vf2.id ' +
+ 'AND vf1."videoId" = vf2."videoId" AND vf1.resolution = vf2.resolution AND vf1.fps IS NULL'
+ await utils.sequelize.query(query)
+ }
+
+ {
+ const query = 'UPDATE "videoFile" SET fps = -1 WHERE fps IS NULL;'
+ await utils.sequelize.query(query)
+ }
+
+ {
+ const data = {
+ type: Sequelize.INTEGER,
+ allowNull: false,
+ defaultValue: -1
+ }
+ await utils.queryInterface.changeColumn('videoFile', 'fps', data)
+ }
+
+}
+
+function down (options) {
+ throw new Error('Not implemented.')
+}
+
+export { up, down }
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index db72ef23c5..3dccabe120 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -478,7 +478,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje
resolution: fileUrl.height,
size: fileUrl.size,
videoId: videoCreated.id,
- fps: fileUrl.fps
+ fps: fileUrl.fps || -1
} as VideoFileModel
attributes.push(attribute)
}
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 580d920ced..27c75d8861 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -19,7 +19,6 @@ import { isAccountDescriptionValid } from '../../helpers/custom-validators/accou
import { sendDeleteActor } from '../../lib/activitypub/send'
import { ActorModel } from '../activitypub/actor'
import { ApplicationModel } from '../application/application'
-import { AvatarModel } from '../avatar/avatar'
import { ServerModel } from '../server/server'
import { getSort, throwIfNotValid } from '../utils'
import { VideoChannelModel } from '../video/video-channel'
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index 0887a37384..f040803b9a 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -66,8 +66,8 @@ export class VideoFileModel extends Model<VideoFileModel> {
@Column
infoHash: string
- @AllowNull(true)
- @Default(null)
+ @AllowNull(false)
+ @Default(-1)
@Is('VideoFileFPS', value => throwIfNotValid(value, isVideoFPSResolutionValid, 'fps'))
@Column
fps: number