mirror of https://github.com/Chocobozzz/PeerTube
Add publishedAt field for video model.
* New field added in the `video` table + migration script * `publishedAt` updated to NOW when privacy changes from private to public/unlisted (default = NOW) * Models updated to handle the new attribute * Client interface updated to use `publishedAt` instead of `createdAt` except in My Account > My Videos viewpull/447/head
parent
2920281946
commit
2922e048de
|
@ -11,7 +11,7 @@
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span class="video-miniature-created-at-views">{{ video.createdAt | myFromNow }} - {{ video.views | myNumberFormatter }} views</span>
|
<span class="video-miniature-created-at-views">{{ video.publishedAt | myFromNow }} - {{ video.views | myNumberFormatter }} views</span>
|
||||||
<span class="video-miniature-account">{{ video.by }}</span>
|
<span class="video-miniature-account">{{ video.by }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -9,6 +9,7 @@ export class Video implements VideoServerModel {
|
||||||
by: string
|
by: string
|
||||||
createdAt: Date
|
createdAt: Date
|
||||||
updatedAt: Date
|
updatedAt: Date
|
||||||
|
publishedAt: Date
|
||||||
category: VideoConstant<number>
|
category: VideoConstant<number>
|
||||||
licence: VideoConstant<number>
|
licence: VideoConstant<number>
|
||||||
language: VideoConstant<number>
|
language: VideoConstant<number>
|
||||||
|
@ -56,6 +57,7 @@ export class Video implements VideoServerModel {
|
||||||
const absoluteAPIUrl = getAbsoluteAPIUrl()
|
const absoluteAPIUrl = getAbsoluteAPIUrl()
|
||||||
|
|
||||||
this.createdAt = new Date(hash.createdAt.toString())
|
this.createdAt = new Date(hash.createdAt.toString())
|
||||||
|
this.publishedAt = new Date(hash.publishedAt.toString())
|
||||||
this.category = hash.category
|
this.category = hash.category
|
||||||
this.licence = hash.licence
|
this.licence = hash.licence
|
||||||
this.language = hash.language
|
this.language = hash.language
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<div class="video-info-name">{{ video.name }}</div>
|
<div class="video-info-name">{{ video.name }}</div>
|
||||||
|
|
||||||
<div class="video-info-date-views">
|
<div class="video-info-date-views">
|
||||||
{{ video.createdAt | myFromNow }} - {{ video.views | myNumberFormatter }} views
|
{{ video.publishedAt | myFromNow }} - {{ video.views | myNumberFormatter }} views
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="video-info-channel">
|
<div class="video-info-channel">
|
||||||
|
|
|
@ -307,10 +307,17 @@ async function updateVideo (req: express.Request, res: express.Response) {
|
||||||
if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
|
if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
|
||||||
if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
|
if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
|
||||||
if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
|
if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
|
||||||
if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', parseInt(videoInfoToUpdate.privacy.toString(), 10))
|
|
||||||
if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support)
|
if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support)
|
||||||
if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
|
if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
|
||||||
if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled)
|
if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled)
|
||||||
|
if (videoInfoToUpdate.privacy !== undefined) {
|
||||||
|
const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
|
||||||
|
videoInstance.set('privacy', newPrivacy)
|
||||||
|
|
||||||
|
if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) {
|
||||||
|
videoInstance.set('publishedAt', new Date())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
|
const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ let config: IConfig = require('config')
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const LAST_MIGRATION_VERSION = 195
|
const LAST_MIGRATION_VERSION = 200
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import * as Sequelize from 'sequelize'
|
||||||
|
|
||||||
|
async function up (utils: {
|
||||||
|
transaction: Sequelize.Transaction,
|
||||||
|
queryInterface: Sequelize.QueryInterface,
|
||||||
|
sequelize: Sequelize.Sequelize
|
||||||
|
}): Promise<void> {
|
||||||
|
|
||||||
|
{
|
||||||
|
const data = {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: Sequelize.NOW
|
||||||
|
}
|
||||||
|
await utils.queryInterface.addColumn('video', 'publishedAt', data)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const query = 'UPDATE video SET "publishedAt" = video."createdAt"'
|
||||||
|
await utils.sequelize.query(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function down (options) {
|
||||||
|
throw new Error('Not implemented.')
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
up,
|
||||||
|
down
|
||||||
|
}
|
|
@ -376,6 +376,11 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
@UpdatedAt
|
@UpdatedAt
|
||||||
updatedAt: Date
|
updatedAt: Date
|
||||||
|
|
||||||
|
@AllowNull(false)
|
||||||
|
@Default(Sequelize.NOW)
|
||||||
|
@Column
|
||||||
|
publishedAt: Date
|
||||||
|
|
||||||
@ForeignKey(() => VideoChannelModel)
|
@ForeignKey(() => VideoChannelModel)
|
||||||
@Column
|
@Column
|
||||||
channelId: number
|
channelId: number
|
||||||
|
@ -968,6 +973,7 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
embedPath: this.getEmbedPath(),
|
embedPath: this.getEmbedPath(),
|
||||||
createdAt: this.createdAt,
|
createdAt: this.createdAt,
|
||||||
updatedAt: this.updatedAt,
|
updatedAt: this.updatedAt,
|
||||||
|
publishedAt: this.publishedAt,
|
||||||
account: {
|
account: {
|
||||||
name: formattedAccount.name,
|
name: formattedAccount.name,
|
||||||
displayName: formattedAccount.displayName,
|
displayName: formattedAccount.displayName,
|
||||||
|
@ -1122,7 +1128,7 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
views: this.views,
|
views: this.views,
|
||||||
sensitive: this.nsfw,
|
sensitive: this.nsfw,
|
||||||
commentsEnabled: this.commentsEnabled,
|
commentsEnabled: this.commentsEnabled,
|
||||||
published: this.createdAt.toISOString(),
|
published: this.publishedAt.toISOString(),
|
||||||
updated: this.updatedAt.toISOString(),
|
updated: this.updatedAt.toISOString(),
|
||||||
mediaType: 'text/markdown',
|
mediaType: 'text/markdown',
|
||||||
content: this.getTruncatedDescription(),
|
content: this.getTruncatedDescription(),
|
||||||
|
|
|
@ -22,6 +22,7 @@ export interface Video {
|
||||||
uuid: string
|
uuid: string
|
||||||
createdAt: Date | string
|
createdAt: Date | string
|
||||||
updatedAt: Date | string
|
updatedAt: Date | string
|
||||||
|
publishedAt: Date | string
|
||||||
category: VideoConstant<number>
|
category: VideoConstant<number>
|
||||||
licence: VideoConstant<number>
|
licence: VideoConstant<number>
|
||||||
language: VideoConstant<number>
|
language: VideoConstant<number>
|
||||||
|
|
Loading…
Reference in New Issue