diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/account.ts | 21 | ||||
-rw-r--r-- | server/models/redundancy/video-redundancy.ts | 4 | ||||
-rw-r--r-- | server/models/video/video-channel.ts | 21 | ||||
-rw-r--r-- | server/models/video/video.ts | 36 |
4 files changed, 68 insertions, 14 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 5a237d733..a99e9b1ad 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts | |||
@@ -241,6 +241,27 @@ export class AccountModel extends Model<AccountModel> { | |||
241 | }) | 241 | }) |
242 | } | 242 | } |
243 | 243 | ||
244 | static listLocalsForSitemap (sort: string) { | ||
245 | const query = { | ||
246 | attributes: [ ], | ||
247 | offset: 0, | ||
248 | order: getSort(sort), | ||
249 | include: [ | ||
250 | { | ||
251 | attributes: [ 'preferredUsername', 'serverId' ], | ||
252 | model: ActorModel.unscoped(), | ||
253 | where: { | ||
254 | serverId: null | ||
255 | } | ||
256 | } | ||
257 | ] | ||
258 | } | ||
259 | |||
260 | return AccountModel | ||
261 | .unscoped() | ||
262 | .findAll(query) | ||
263 | } | ||
264 | |||
244 | toFormattedJSON (): Account { | 265 | toFormattedJSON (): Account { |
245 | const actor = this.Actor.toFormattedJSON() | 266 | const actor = this.Actor.toFormattedJSON() |
246 | const account = { | 267 | const account = { |
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index 9de4356b4..dd37dad22 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts | |||
@@ -15,7 +15,7 @@ import { | |||
15 | import { ActorModel } from '../activitypub/actor' | 15 | import { ActorModel } from '../activitypub/actor' |
16 | import { getVideoSort, throwIfNotValid } from '../utils' | 16 | import { getVideoSort, throwIfNotValid } from '../utils' |
17 | import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 17 | import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
18 | import { CONFIG, CONSTRAINTS_FIELDS, VIDEO_EXT_MIMETYPE } from '../../initializers' | 18 | import { CONFIG, CONSTRAINTS_FIELDS, STATIC_PATHS, VIDEO_EXT_MIMETYPE } from '../../initializers' |
19 | import { VideoFileModel } from '../video/video-file' | 19 | import { VideoFileModel } from '../video/video-file' |
20 | import { getServerActor } from '../../helpers/utils' | 20 | import { getServerActor } from '../../helpers/utils' |
21 | import { VideoModel } from '../video/video' | 21 | import { VideoModel } from '../video/video' |
@@ -124,7 +124,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | |||
124 | const logIdentifier = `${videoFile.Video.uuid}-${videoFile.resolution}` | 124 | const logIdentifier = `${videoFile.Video.uuid}-${videoFile.resolution}` |
125 | logger.info('Removing duplicated video file %s.', logIdentifier) | 125 | logger.info('Removing duplicated video file %s.', logIdentifier) |
126 | 126 | ||
127 | videoFile.Video.removeFile(videoFile) | 127 | videoFile.Video.removeFile(videoFile, true) |
128 | .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err })) | 128 | .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err })) |
129 | 129 | ||
130 | return undefined | 130 | return undefined |
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index f4586917e..86bf0461a 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -233,6 +233,27 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
233 | }) | 233 | }) |
234 | } | 234 | } |
235 | 235 | ||
236 | static listLocalsForSitemap (sort: string) { | ||
237 | const query = { | ||
238 | attributes: [ ], | ||
239 | offset: 0, | ||
240 | order: getSort(sort), | ||
241 | include: [ | ||
242 | { | ||
243 | attributes: [ 'preferredUsername', 'serverId' ], | ||
244 | model: ActorModel.unscoped(), | ||
245 | where: { | ||
246 | serverId: null | ||
247 | } | ||
248 | } | ||
249 | ] | ||
250 | } | ||
251 | |||
252 | return VideoChannelModel | ||
253 | .unscoped() | ||
254 | .findAll(query) | ||
255 | } | ||
256 | |||
236 | static searchForApi (options: { | 257 | static searchForApi (options: { |
237 | actorId: number | 258 | actorId: number |
238 | search: string | 259 | search: string |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 1e68b380c..adef37937 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -140,7 +140,7 @@ type ForAPIOptions = { | |||
140 | 140 | ||
141 | type AvailableForListIDsOptions = { | 141 | type AvailableForListIDsOptions = { |
142 | serverAccountId: number | 142 | serverAccountId: number |
143 | actorId: number | 143 | followerActorId: number |
144 | includeLocalVideos: boolean | 144 | includeLocalVideos: boolean |
145 | filter?: VideoFilter | 145 | filter?: VideoFilter |
146 | categoryOneOf?: number[] | 146 | categoryOneOf?: number[] |
@@ -315,7 +315,7 @@ type AvailableForListIDsOptions = { | |||
315 | query.include.push(videoChannelInclude) | 315 | query.include.push(videoChannelInclude) |
316 | } | 316 | } |
317 | 317 | ||
318 | if (options.actorId) { | 318 | if (options.followerActorId) { |
319 | let localVideosReq = '' | 319 | let localVideosReq = '' |
320 | if (options.includeLocalVideos === true) { | 320 | if (options.includeLocalVideos === true) { |
321 | localVideosReq = ' UNION ALL ' + | 321 | localVideosReq = ' UNION ALL ' + |
@@ -327,7 +327,7 @@ type AvailableForListIDsOptions = { | |||
327 | } | 327 | } |
328 | 328 | ||
329 | // Force actorId to be a number to avoid SQL injections | 329 | // Force actorId to be a number to avoid SQL injections |
330 | const actorIdNumber = parseInt(options.actorId.toString(), 10) | 330 | const actorIdNumber = parseInt(options.followerActorId.toString(), 10) |
331 | query.where[ 'id' ][ Sequelize.Op.and ].push({ | 331 | query.where[ 'id' ][ Sequelize.Op.and ].push({ |
332 | [ Sequelize.Op.in ]: Sequelize.literal( | 332 | [ Sequelize.Op.in ]: Sequelize.literal( |
333 | '(' + | 333 | '(' + |
@@ -985,7 +985,7 @@ export class VideoModel extends Model<VideoModel> { | |||
985 | filter?: VideoFilter, | 985 | filter?: VideoFilter, |
986 | accountId?: number, | 986 | accountId?: number, |
987 | videoChannelId?: number, | 987 | videoChannelId?: number, |
988 | actorId?: number | 988 | followerActorId?: number |
989 | trendingDays?: number, | 989 | trendingDays?: number, |
990 | user?: UserModel | 990 | user?: UserModel |
991 | }, countVideos = true) { | 991 | }, countVideos = true) { |
@@ -1008,11 +1008,11 @@ export class VideoModel extends Model<VideoModel> { | |||
1008 | 1008 | ||
1009 | const serverActor = await getServerActor() | 1009 | const serverActor = await getServerActor() |
1010 | 1010 | ||
1011 | // actorId === null has a meaning, so just check undefined | 1011 | // followerActorId === null has a meaning, so just check undefined |
1012 | const actorId = options.actorId !== undefined ? options.actorId : serverActor.id | 1012 | const followerActorId = options.followerActorId !== undefined ? options.followerActorId : serverActor.id |
1013 | 1013 | ||
1014 | const queryOptions = { | 1014 | const queryOptions = { |
1015 | actorId, | 1015 | followerActorId, |
1016 | serverAccountId: serverActor.Account.id, | 1016 | serverAccountId: serverActor.Account.id, |
1017 | nsfw: options.nsfw, | 1017 | nsfw: options.nsfw, |
1018 | categoryOneOf: options.categoryOneOf, | 1018 | categoryOneOf: options.categoryOneOf, |
@@ -1118,7 +1118,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1118 | 1118 | ||
1119 | const serverActor = await getServerActor() | 1119 | const serverActor = await getServerActor() |
1120 | const queryOptions = { | 1120 | const queryOptions = { |
1121 | actorId: serverActor.id, | 1121 | followerActorId: serverActor.id, |
1122 | serverAccountId: serverActor.Account.id, | 1122 | serverAccountId: serverActor.Account.id, |
1123 | includeLocalVideos: options.includeLocalVideos, | 1123 | includeLocalVideos: options.includeLocalVideos, |
1124 | nsfw: options.nsfw, | 1124 | nsfw: options.nsfw, |
@@ -1273,11 +1273,11 @@ export class VideoModel extends Model<VideoModel> { | |||
1273 | // threshold corresponds to how many video the field should have to be returned | 1273 | // threshold corresponds to how many video the field should have to be returned |
1274 | static async getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) { | 1274 | static async getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) { |
1275 | const serverActor = await getServerActor() | 1275 | const serverActor = await getServerActor() |
1276 | const actorId = serverActor.id | 1276 | const followerActorId = serverActor.id |
1277 | 1277 | ||
1278 | const scopeOptions: AvailableForListIDsOptions = { | 1278 | const scopeOptions: AvailableForListIDsOptions = { |
1279 | serverAccountId: serverActor.Account.id, | 1279 | serverAccountId: serverActor.Account.id, |
1280 | actorId, | 1280 | followerActorId, |
1281 | includeLocalVideos: true | 1281 | includeLocalVideos: true |
1282 | } | 1282 | } |
1283 | 1283 | ||
@@ -1538,8 +1538,10 @@ export class VideoModel extends Model<VideoModel> { | |||
1538 | .catch(err => logger.warn('Cannot delete preview %s.', previewPath, { err })) | 1538 | .catch(err => logger.warn('Cannot delete preview %s.', previewPath, { err })) |
1539 | } | 1539 | } |
1540 | 1540 | ||
1541 | removeFile (videoFile: VideoFileModel) { | 1541 | removeFile (videoFile: VideoFileModel, isRedundancy = false) { |
1542 | const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) | 1542 | const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR |
1543 | |||
1544 | const filePath = join(baseDir, this.getVideoFilename(videoFile)) | ||
1543 | return remove(filePath) | 1545 | return remove(filePath) |
1544 | .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) | 1546 | .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) |
1545 | } | 1547 | } |
@@ -1561,6 +1563,12 @@ export class VideoModel extends Model<VideoModel> { | |||
1561 | (now - updatedAtTime) > ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL | 1563 | (now - updatedAtTime) > ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL |
1562 | } | 1564 | } |
1563 | 1565 | ||
1566 | setAsRefreshed () { | ||
1567 | this.changed('updatedAt', true) | ||
1568 | |||
1569 | return this.save() | ||
1570 | } | ||
1571 | |||
1564 | getBaseUrls () { | 1572 | getBaseUrls () { |
1565 | let baseUrlHttp | 1573 | let baseUrlHttp |
1566 | let baseUrlWs | 1574 | let baseUrlWs |
@@ -1611,6 +1619,10 @@ export class VideoModel extends Model<VideoModel> { | |||
1611 | return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) | 1619 | return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) |
1612 | } | 1620 | } |
1613 | 1621 | ||
1622 | getVideoRedundancyUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | ||
1623 | return baseUrlHttp + STATIC_PATHS.REDUNDANCY + this.getVideoFilename(videoFile) | ||
1624 | } | ||
1625 | |||
1614 | getVideoFileDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 1626 | getVideoFileDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) { |
1615 | return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + this.getVideoFilename(videoFile) | 1627 | return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + this.getVideoFilename(videoFile) |
1616 | } | 1628 | } |