aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-19 16:02:49 +0200
committerChocobozzz <me@florianbigard.com>2023-07-21 17:38:13 +0200
commit12dc3a942a13c7f1489822dae052da197ef15905 (patch)
tree7b87b6be692af0b62ebac17e720c80244fd8a7ec /server/models/video
parentc6867725fb8e3dfbc2018a37ed5a963103587cb6 (diff)
downloadPeerTube-12dc3a942a13c7f1489822dae052da197ef15905.tar.gz
PeerTube-12dc3a942a13c7f1489822dae052da197ef15905.tar.zst
PeerTube-12dc3a942a13c7f1489822dae052da197ef15905.zip
Implement replace file in server side
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/formatter/video-activity-pub-format.ts2
-rw-r--r--server/models/video/formatter/video-api-format.ts1
-rw-r--r--server/models/video/sql/video/shared/video-table-attributes.ts1
-rw-r--r--server/models/video/video-source.ts45
-rw-r--r--server/models/video/video.ts8
5 files changed, 34 insertions, 23 deletions
diff --git a/server/models/video/formatter/video-activity-pub-format.ts b/server/models/video/formatter/video-activity-pub-format.ts
index c0d3d5f3e..a5b3e9ca6 100644
--- a/server/models/video/formatter/video-activity-pub-format.ts
+++ b/server/models/video/formatter/video-activity-pub-format.ts
@@ -76,6 +76,8 @@ export function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
76 76
77 updated: video.updatedAt.toISOString(), 77 updated: video.updatedAt.toISOString(),
78 78
79 uploadDate: video.inputFileUpdatedAt?.toISOString(),
80
79 tag: buildTags(video), 81 tag: buildTags(video),
80 82
81 mediaType: 'text/markdown', 83 mediaType: 'text/markdown',
diff --git a/server/models/video/formatter/video-api-format.ts b/server/models/video/formatter/video-api-format.ts
index 1af51d132..7a58f5d3c 100644
--- a/server/models/video/formatter/video-api-format.ts
+++ b/server/models/video/formatter/video-api-format.ts
@@ -149,6 +149,7 @@ export function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetail
149 commentsEnabled: video.commentsEnabled, 149 commentsEnabled: video.commentsEnabled,
150 downloadEnabled: video.downloadEnabled, 150 downloadEnabled: video.downloadEnabled,
151 waitTranscoding: video.waitTranscoding, 151 waitTranscoding: video.waitTranscoding,
152 inputFileUpdatedAt: video.inputFileUpdatedAt,
152 state: { 153 state: {
153 id: video.state, 154 id: video.state,
154 label: getStateLabel(video.state) 155 label: getStateLabel(video.state)
diff --git a/server/models/video/sql/video/shared/video-table-attributes.ts b/server/models/video/sql/video/shared/video-table-attributes.ts
index e0fa9d7c1..ef625c57b 100644
--- a/server/models/video/sql/video/shared/video-table-attributes.ts
+++ b/server/models/video/sql/video/shared/video-table-attributes.ts
@@ -263,6 +263,7 @@ export class VideoTableAttributes {
263 'state', 263 'state',
264 'publishedAt', 264 'publishedAt',
265 'originallyPublishedAt', 265 'originallyPublishedAt',
266 'inputFileUpdatedAt',
266 'channelId', 267 'channelId',
267 'createdAt', 268 'createdAt',
268 'updatedAt', 269 'updatedAt',
diff --git a/server/models/video/video-source.ts b/server/models/video/video-source.ts
index e306b160d..1b6868b85 100644
--- a/server/models/video/video-source.ts
+++ b/server/models/video/video-source.ts
@@ -1,27 +1,18 @@
1import { Op } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { 2import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
3 AllowNull, 3import { VideoSource } from '@shared/models/videos/video-source'
4 BelongsTo,
5 Column,
6 CreatedAt,
7 ForeignKey,
8 Model,
9 Table,
10 UpdatedAt
11} from 'sequelize-typescript'
12import { AttributesOnly } from '@shared/typescript-utils' 4import { AttributesOnly } from '@shared/typescript-utils'
5import { getSort } from '../shared'
13import { VideoModel } from './video' 6import { VideoModel } from './video'
14 7
15@Table({ 8@Table({
16 tableName: 'videoSource', 9 tableName: 'videoSource',
17 indexes: [ 10 indexes: [
18 { 11 {
19 fields: [ 'videoId' ], 12 fields: [ 'videoId' ]
20 where: { 13 },
21 videoId: { 14 {
22 [Op.ne]: null 15 fields: [ { name: 'createdAt', order: 'DESC' } ]
23 }
24 }
25 } 16 }
26 ] 17 ]
27}) 18})
@@ -40,16 +31,26 @@ export class VideoSourceModel extends Model<Partial<AttributesOnly<VideoSourceMo
40 @Column 31 @Column
41 videoId: number 32 videoId: number
42 33
43 @BelongsTo(() => VideoModel) 34 @BelongsTo(() => VideoModel, {
35 foreignKey: {
36 allowNull: false
37 },
38 onDelete: 'cascade'
39 })
44 Video: VideoModel 40 Video: VideoModel
45 41
46 static loadByVideoId (videoId) { 42 static loadLatest (videoId: number, transaction?: Transaction) {
47 return VideoSourceModel.findOne({ where: { videoId } }) 43 return VideoSourceModel.findOne({
44 where: { videoId },
45 order: getSort('-createdAt'),
46 transaction
47 })
48 } 48 }
49 49
50 toFormattedJSON () { 50 toFormattedJSON (): VideoSource {
51 return { 51 return {
52 filename: this.filename 52 filename: this.filename,
53 createdAt: this.createdAt.toISOString()
53 } 54 }
54 } 55 }
55} 56}
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 4c6297243..2fe701436 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -546,6 +546,12 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
546 @Column 546 @Column
547 state: VideoState 547 state: VideoState
548 548
549 // We already have the information in videoSource table for local videos, but we prefer to normalize it for performance
550 // And also to store the info from remote instances
551 @AllowNull(true)
552 @Column
553 inputFileUpdatedAt: Date
554
549 @CreatedAt 555 @CreatedAt
550 createdAt: Date 556 createdAt: Date
551 557
@@ -610,7 +616,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
610 @HasOne(() => VideoSourceModel, { 616 @HasOne(() => VideoSourceModel, {
611 foreignKey: { 617 foreignKey: {
612 name: 'videoId', 618 name: 'videoId',
613 allowNull: true 619 allowNull: false
614 }, 620 },
615 onDelete: 'CASCADE' 621 onDelete: 'CASCADE'
616 }) 622 })