1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Refresh remote actors on GET enpoints

This commit is contained in:
Chocobozzz 2019-01-14 11:30:15 +01:00
parent bb8f7872f5
commit 744d0eca19
No known key found for this signature in database
GPG key ID: 583A612D890159BE
8 changed files with 99 additions and 62 deletions

View file

@ -1,30 +1,33 @@
import * as Bull from 'bull'
import { logger } from '../../../helpers/logger'
import { fetchVideoByUrl } from '../../../helpers/video'
import { refreshVideoIfNeeded } from '../../activitypub'
import { refreshVideoIfNeeded, refreshActorIfNeeded } from '../../activitypub'
import { ActorModel } from '../../../models/activitypub/actor'
export type RefreshPayload = {
videoUrl: string
type: 'video'
type: 'video' | 'actor'
url: string
}
async function refreshAPObject (job: Bull.Job) {
const payload = job.data as RefreshPayload
logger.info('Processing AP refresher in job %d for video %s.', job.id, payload.videoUrl)
logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url)
if (payload.type === 'video') return refreshAPVideo(payload.videoUrl)
if (payload.type === 'video') return refreshVideo(payload.url)
if (payload.type === 'actor') return refreshActor(payload.url)
}
// ---------------------------------------------------------------------------
export {
refreshActor,
refreshAPObject
}
// ---------------------------------------------------------------------------
async function refreshAPVideo (videoUrl: string) {
async function refreshVideo (videoUrl: string) {
const fetchType = 'all' as 'all'
const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true }
@ -39,3 +42,13 @@ async function refreshAPVideo (videoUrl: string) {
await refreshVideoIfNeeded(refreshOptions)
}
}
async function refreshActor (actorUrl: string) {
const fetchType = 'all' as 'all'
const actor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(actorUrl)
if (actor) {
await refreshActorIfNeeded(actor, fetchType)
}
}