PeerTube/server/lib/job-queue/handlers/activitypub-refresher.ts

55 lines
1.5 KiB
TypeScript
Raw Normal View History

import * as Bull from 'bull'
import { logger } from '../../../helpers/logger'
import { fetchVideoByUrl } from '../../../helpers/video'
2019-01-14 11:30:15 +01:00
import { refreshVideoIfNeeded, refreshActorIfNeeded } from '../../activitypub'
import { ActorModel } from '../../../models/activitypub/actor'
export type RefreshPayload = {
2019-01-14 11:30:15 +01:00
type: 'video' | 'actor'
url: string
}
async function refreshAPObject (job: Bull.Job) {
const payload = job.data as RefreshPayload
2018-12-04 15:12:54 +01:00
2019-01-14 11:30:15 +01:00
logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url)
2019-01-14 11:30:15 +01:00
if (payload.type === 'video') return refreshVideo(payload.url)
if (payload.type === 'actor') return refreshActor(payload.url)
}
// ---------------------------------------------------------------------------
export {
2019-01-14 11:30:15 +01:00
refreshActor,
refreshAPObject
}
// ---------------------------------------------------------------------------
2019-01-14 11:30:15 +01:00
async function refreshVideo (videoUrl: string) {
const fetchType = 'all' as 'all'
const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true }
const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
if (videoFromDatabase) {
const refreshOptions = {
video: videoFromDatabase,
fetchedType: fetchType,
syncParam
}
await refreshVideoIfNeeded(refreshOptions)
}
}
2019-01-14 11:30:15 +01:00
async function refreshActor (actorUrl: string) {
const fetchType = 'all' as 'all'
const actor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(actorUrl)
if (actor) {
await refreshActorIfNeeded(actor, fetchType)
}
}