aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/activitypub/actor.ts9
-rw-r--r--server/models/utils.ts12
-rw-r--r--server/models/video/video-playlist.ts15
-rw-r--r--server/models/video/video.ts11
4 files changed, 30 insertions, 17 deletions
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 2fceb21dd..7d91e8a4a 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -34,7 +34,7 @@ import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONFIG, CONSTRAINTS_FIELDS } fr
34import { AccountModel } from '../account/account' 34import { AccountModel } from '../account/account'
35import { AvatarModel } from '../avatar/avatar' 35import { AvatarModel } from '../avatar/avatar'
36import { ServerModel } from '../server/server' 36import { ServerModel } from '../server/server'
37import { throwIfNotValid } from '../utils' 37import { isOutdated, throwIfNotValid } from '../utils'
38import { VideoChannelModel } from '../video/video-channel' 38import { VideoChannelModel } from '../video/video-channel'
39import { ActorFollowModel } from './actor-follow' 39import { ActorFollowModel } from './actor-follow'
40import { VideoModel } from '../video/video' 40import { VideoModel } from '../video/video'
@@ -532,11 +532,6 @@ export class ActorModel extends Model<ActorModel> {
532 isOutdated () { 532 isOutdated () {
533 if (this.isOwned()) return false 533 if (this.isOwned()) return false
534 534
535 const now = Date.now() 535 return isOutdated(this, ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL)
536 const createdAtTime = this.createdAt.getTime()
537 const updatedAtTime = this.updatedAt.getTime()
538
539 return (now - createdAtTime) > ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL &&
540 (now - updatedAtTime) > ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL
541 } 536 }
542} 537}
diff --git a/server/models/utils.ts b/server/models/utils.ts
index 4ebd07dab..f8a71b270 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -1,5 +1,6 @@
1import { Sequelize } from 'sequelize-typescript' 1import { Sequelize } from 'sequelize-typescript'
2import * as validator from 'validator' 2import * as validator from 'validator'
3import { ACTIVITY_PUB } from '../initializers'
3 4
4type SortType = { sortModel: any, sortValue: string } 5type SortType = { sortModel: any, sortValue: string }
5 6
@@ -44,6 +45,14 @@ function getSortOnModel (model: any, value: string, lastSort: string[] = [ 'id',
44 return [ firstSort, lastSort ] 45 return [ firstSort, lastSort ]
45} 46}
46 47
48function isOutdated (model: { createdAt: Date, updatedAt: Date }, refreshInterval: number) {
49 const now = Date.now()
50 const createdAtTime = model.createdAt.getTime()
51 const updatedAtTime = model.updatedAt.getTime()
52
53 return (now - createdAtTime) > refreshInterval && (now - updatedAtTime) > refreshInterval
54}
55
47function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') { 56function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') {
48 if (validator(value) === false) { 57 if (validator(value) === false) {
49 throw new Error(`"${value}" is not a valid ${fieldName}.`) 58 throw new Error(`"${value}" is not a valid ${fieldName}.`)
@@ -108,7 +117,8 @@ export {
108 throwIfNotValid, 117 throwIfNotValid,
109 buildServerIdsFollowedBy, 118 buildServerIdsFollowedBy,
110 buildTrigramSearchIndex, 119 buildTrigramSearchIndex,
111 buildWhereIdOrUUID 120 buildWhereIdOrUUID,
121 isOutdated
112} 122}
113 123
114// --------------------------------------------------------------------------- 124// ---------------------------------------------------------------------------
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts
index 7dbe4ce8d..08e4d32c8 100644
--- a/server/models/video/video-playlist.ts
+++ b/server/models/video/video-playlist.ts
@@ -17,7 +17,7 @@ import {
17} from 'sequelize-typescript' 17} from 'sequelize-typescript'
18import * as Sequelize from 'sequelize' 18import * as Sequelize from 'sequelize'
19import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' 19import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
20import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, throwIfNotValid } from '../utils' 20import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils'
21import { 21import {
22 isVideoPlaylistDescriptionValid, 22 isVideoPlaylistDescriptionValid,
23 isVideoPlaylistNameValid, 23 isVideoPlaylistNameValid,
@@ -25,6 +25,7 @@ import {
25} from '../../helpers/custom-validators/video-playlists' 25} from '../../helpers/custom-validators/video-playlists'
26import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 26import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
27import { 27import {
28 ACTIVITY_PUB,
28 CONFIG, 29 CONFIG,
29 CONSTRAINTS_FIELDS, 30 CONSTRAINTS_FIELDS,
30 STATIC_PATHS, 31 STATIC_PATHS,
@@ -429,10 +430,22 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
429 .catch(err => logger.warn('Cannot delete thumbnail %s.', thumbnailPath, { err })) 430 .catch(err => logger.warn('Cannot delete thumbnail %s.', thumbnailPath, { err }))
430 } 431 }
431 432
433 setAsRefreshed () {
434 this.changed('updatedAt', true)
435
436 return this.save()
437 }
438
432 isOwned () { 439 isOwned () {
433 return this.OwnerAccount.isOwned() 440 return this.OwnerAccount.isOwned()
434 } 441 }
435 442
443 isOutdated () {
444 if (this.isOwned()) return false
445
446 return isOutdated(this, ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL)
447 }
448
436 toFormattedJSON (): VideoPlaylist { 449 toFormattedJSON (): VideoPlaylist {
437 return { 450 return {
438 id: this.id, 451 id: this.id,
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 946be6095..fb037c21a 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -77,7 +77,7 @@ import {
77 buildTrigramSearchIndex, 77 buildTrigramSearchIndex,
78 buildWhereIdOrUUID, 78 buildWhereIdOrUUID,
79 createSimilarityAttribute, 79 createSimilarityAttribute,
80 getVideoSort, 80 getVideoSort, isOutdated,
81 throwIfNotValid 81 throwIfNotValid
82} from '../utils' 82} from '../utils'
83import { TagModel } from './tag' 83import { TagModel } from './tag'
@@ -1547,7 +1547,7 @@ export class VideoModel extends Model<VideoModel> {
1547 attributes: query.attributes, 1547 attributes: query.attributes,
1548 order: [ // Keep original order 1548 order: [ // Keep original order
1549 Sequelize.literal( 1549 Sequelize.literal(
1550 ids.map(id => `"VideoModel".id = ${id} DESC`).join(', ') 1550 ids.map(id => `"VideoModel".id = ${id}`).join(', ')
1551 ) 1551 )
1552 ] 1552 ]
1553 } 1553 }
@@ -1767,12 +1767,7 @@ export class VideoModel extends Model<VideoModel> {
1767 isOutdated () { 1767 isOutdated () {
1768 if (this.isOwned()) return false 1768 if (this.isOwned()) return false
1769 1769
1770 const now = Date.now() 1770 return isOutdated(this, ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL)
1771 const createdAtTime = this.createdAt.getTime()
1772 const updatedAtTime = this.updatedAt.getTime()
1773
1774 return (now - createdAtTime) > ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL &&
1775 (now - updatedAtTime) > ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL
1776 } 1771 }
1777 1772
1778 setAsRefreshed () { 1773 setAsRefreshed () {