Change models

This commit is contained in:
clementbrizard 2019-01-12 13:41:45 +00:00
parent 94a680c095
commit c80341655f
8 changed files with 26 additions and 1 deletions

View File

@ -25,6 +25,7 @@ export class VideoEdit implements VideoUpdate {
uuid?: string uuid?: string
id?: number id?: number
scheduleUpdate?: VideoScheduleUpdate scheduleUpdate?: VideoScheduleUpdate
originallyPublishedAt?: Date | string
constructor (video?: Video & { tags: string[], commentsEnabled: boolean, support: string, thumbnailUrl: string, previewUrl: string }) { constructor (video?: Video & { tags: string[], commentsEnabled: boolean, support: string, thumbnailUrl: string, previewUrl: string }) {
if (video) { if (video) {
@ -46,6 +47,7 @@ export class VideoEdit implements VideoUpdate {
this.previewUrl = video.previewUrl this.previewUrl = video.previewUrl
this.scheduleUpdate = video.scheduledUpdate this.scheduleUpdate = video.scheduledUpdate
this.originallyPublishedAt = new Date(video.originallyPublishedAt)
} }
} }
@ -67,6 +69,12 @@ export class VideoEdit implements VideoUpdate {
} else { } else {
this.scheduleUpdate = null this.scheduleUpdate = null
} }
// Convert originallyPublishedAt to string so that function objectToFormData() works correctly
if (this.originallyPublishedAt) {
const originallyPublishedAt = new Date(values['originallyPublishedAt'])
this.originallyPublishedAt = originallyPublishedAt.toISOString()
}
} }
toFormPatch () { toFormPatch () {
@ -82,7 +90,8 @@ export class VideoEdit implements VideoUpdate {
commentsEnabled: this.commentsEnabled, commentsEnabled: this.commentsEnabled,
waitTranscoding: this.waitTranscoding, waitTranscoding: this.waitTranscoding,
channelId: this.channelId, channelId: this.channelId,
privacy: this.privacy privacy: this.privacy,
originallyPublishedAt: this.originallyPublishedAt
} }
// Special case if we scheduled an update // Special case if we scheduled an update

View File

@ -17,6 +17,7 @@ export class Video implements VideoServerModel {
createdAt: Date createdAt: Date
updatedAt: Date updatedAt: Date
publishedAt: Date publishedAt: Date
originallyPublishedAt: Date | string
category: VideoConstant<number> category: VideoConstant<number>
licence: VideoConstant<number> licence: VideoConstant<number>
language: VideoConstant<string> language: VideoConstant<string>
@ -116,6 +117,9 @@ export class Video implements VideoServerModel {
this.privacy.label = peertubeTranslate(this.privacy.label, translations) this.privacy.label = peertubeTranslate(this.privacy.label, translations)
this.scheduledUpdate = hash.scheduledUpdate this.scheduledUpdate = hash.scheduledUpdate
this.originallyPublishedAt = hash.originallyPublishedAt ?
new Date(hash.originallyPublishedAt.toString())
: null
if (this.state) this.state.label = peertubeTranslate(this.state.label, translations) if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
this.blacklisted = hash.blacklisted this.blacklisted = hash.blacklisted

View File

@ -60,6 +60,7 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
createdAt: video.createdAt, createdAt: video.createdAt,
updatedAt: video.updatedAt, updatedAt: video.updatedAt,
publishedAt: video.publishedAt, publishedAt: video.publishedAt,
originallyPublishedAt: video.originallyPublishedAt,
account: { account: {
id: formattedAccount.id, id: formattedAccount.id,
uuid: formattedAccount.uuid, uuid: formattedAccount.uuid,
@ -264,6 +265,9 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
state: video.state, state: video.state,
commentsEnabled: video.commentsEnabled, commentsEnabled: video.commentsEnabled,
published: video.publishedAt.toISOString(), published: video.publishedAt.toISOString(),
originallyPublishedAt: video.originallyPublishedAt ?
video.originallyPublishedAt.toISOString() :
null,
updated: video.updatedAt.toISOString(), updated: video.updatedAt.toISOString(),
mediaType: 'text/markdown', mediaType: 'text/markdown',
content: video.getTruncatedDescription(), content: video.getTruncatedDescription(),

View File

@ -102,6 +102,7 @@ const indexes: Sequelize.DefineIndexesOptions[] = [
{ fields: [ 'createdAt' ] }, { fields: [ 'createdAt' ] },
{ fields: [ 'publishedAt' ] }, { fields: [ 'publishedAt' ] },
{ fields: [ 'originallyPublishedAt' ] },
{ fields: [ 'duration' ] }, { fields: [ 'duration' ] },
{ fields: [ 'views' ] }, { fields: [ 'views' ] },
{ fields: [ 'channelId' ] }, { fields: [ 'channelId' ] },
@ -684,6 +685,9 @@ export class VideoModel extends Model<VideoModel> {
@Column @Column
publishedAt: Date publishedAt: Date
@Column
originallyPublishedAt: Date
@ForeignKey(() => VideoChannelModel) @ForeignKey(() => VideoChannelModel)
@Column @Column
channelId: number channelId: number

View File

@ -24,6 +24,7 @@ export interface VideoTorrentObject {
waitTranscoding: boolean waitTranscoding: boolean
state: VideoState state: VideoState
published: string published: string
originallyPublishedAt: string
updated: string updated: string
mediaType: 'text/markdown' mediaType: 'text/markdown'
content: string content: string

View File

@ -15,4 +15,5 @@ export interface VideoCreate {
commentsEnabled?: boolean commentsEnabled?: boolean
privacy: VideoPrivacy privacy: VideoPrivacy
scheduleUpdate?: VideoScheduleUpdate scheduleUpdate?: VideoScheduleUpdate
originallyPublishedAt: Date | string
} }

View File

@ -17,4 +17,5 @@ export interface VideoUpdate {
thumbnailfile?: Blob thumbnailfile?: Blob
previewfile?: Blob previewfile?: Blob
scheduleUpdate?: VideoScheduleUpdate scheduleUpdate?: VideoScheduleUpdate
originallyPublishedAt?: Date | string
} }

View File

@ -43,6 +43,7 @@ export interface Video {
createdAt: Date | string createdAt: Date | string
updatedAt: Date | string updatedAt: Date | string
publishedAt: Date | string publishedAt: Date | string
originallyPublishedAt: Date | string
category: VideoConstant<number> category: VideoConstant<number>
licence: VideoConstant<number> licence: VideoConstant<number>
language: VideoConstant<string> language: VideoConstant<string>