diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-19 16:02:49 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-07-21 17:38:13 +0200 |
commit | 12dc3a942a13c7f1489822dae052da197ef15905 (patch) | |
tree | 7b87b6be692af0b62ebac17e720c80244fd8a7ec /server/models/video/video-source.ts | |
parent | c6867725fb8e3dfbc2018a37ed5a963103587cb6 (diff) | |
download | PeerTube-12dc3a942a13c7f1489822dae052da197ef15905.tar.gz PeerTube-12dc3a942a13c7f1489822dae052da197ef15905.tar.zst PeerTube-12dc3a942a13c7f1489822dae052da197ef15905.zip |
Implement replace file in server side
Diffstat (limited to 'server/models/video/video-source.ts')
-rw-r--r-- | server/models/video/video-source.ts | 45 |
1 files changed, 23 insertions, 22 deletions
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 @@ | |||
1 | import { Op } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | AllowNull, | 3 | import { 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' | ||
12 | import { AttributesOnly } from '@shared/typescript-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { getSort } from '../shared' | ||
13 | import { VideoModel } from './video' | 6 | import { 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 | } |