mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Use got instead of request
This commit is contained in:
parent
71926aae07
commit
db4b15f21f
32 changed files with 346 additions and 328 deletions
|
@ -7,7 +7,7 @@ import {
|
|||
isLikeActivityValid
|
||||
} from '@server/helpers/custom-validators/activitypub/activity'
|
||||
import { sanitizeAndCheckVideoCommentObject } from '@server/helpers/custom-validators/activitypub/video-comments'
|
||||
import { doRequest } from '@server/helpers/requests'
|
||||
import { doJSONRequest } from '@server/helpers/requests'
|
||||
import { AP_CLEANER_CONCURRENCY } from '@server/initializers/constants'
|
||||
import { VideoModel } from '@server/models/video/video'
|
||||
import { VideoCommentModel } from '@server/models/video/video-comment'
|
||||
|
@ -81,15 +81,10 @@ async function updateObjectIfNeeded <T> (
|
|||
updater: (url: string, newUrl: string) => Promise<T>,
|
||||
deleter: (url: string) => Promise<T>
|
||||
): Promise<{ data: T, status: 'deleted' | 'updated' } | null> {
|
||||
// Fetch url
|
||||
const { response, body } = await doRequest<any>({
|
||||
uri: url,
|
||||
json: true,
|
||||
activityPub: true
|
||||
})
|
||||
const { statusCode, body } = await doJSONRequest<any>(url, { activityPub: true })
|
||||
|
||||
// Does not exist anymore, remove entry
|
||||
if (response.statusCode === HttpStatusCode.NOT_FOUND_404) {
|
||||
if (statusCode === HttpStatusCode.NOT_FOUND_404) {
|
||||
logger.info('Removing remote AP object %s.', url)
|
||||
const data = await deleter(url)
|
||||
|
||||
|
|
|
@ -16,8 +16,7 @@ async function processActivityPubHttpBroadcast (job: Bull.Job) {
|
|||
const httpSignatureOptions = await buildSignedRequestOptions(payload)
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
uri: '',
|
||||
method: 'POST' as 'POST',
|
||||
json: body,
|
||||
httpSignature: httpSignatureOptions,
|
||||
timeout: REQUEST_TIMEOUT,
|
||||
|
@ -28,7 +27,7 @@ async function processActivityPubHttpBroadcast (job: Bull.Job) {
|
|||
const goodUrls: string[] = []
|
||||
|
||||
await Bluebird.map(payload.uris, uri => {
|
||||
return doRequest(Object.assign({}, options, { uri }))
|
||||
return doRequest(uri, options)
|
||||
.then(() => goodUrls.push(uri))
|
||||
.catch(() => badUrls.push(uri))
|
||||
}, { concurrency: BROADCAST_CONCURRENCY })
|
||||
|
|
|
@ -16,8 +16,7 @@ async function processActivityPubHttpUnicast (job: Bull.Job) {
|
|||
const httpSignatureOptions = await buildSignedRequestOptions(payload)
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
uri,
|
||||
method: 'POST' as 'POST',
|
||||
json: body,
|
||||
httpSignature: httpSignatureOptions,
|
||||
timeout: REQUEST_TIMEOUT,
|
||||
|
@ -25,7 +24,7 @@ async function processActivityPubHttpUnicast (job: Bull.Job) {
|
|||
}
|
||||
|
||||
try {
|
||||
await doRequest(options)
|
||||
await doRequest(uri, options)
|
||||
ActorFollowScoreCache.Instance.updateActorFollowsScore([ uri ], [])
|
||||
} catch (err) {
|
||||
ActorFollowScoreCache.Instance.updateActorFollowsScore([], [ uri ])
|
||||
|
|
|
@ -6,21 +6,24 @@ import { getServerActor } from '@server/models/application/application'
|
|||
import { buildDigest } from '@server/helpers/peertube-crypto'
|
||||
import { ContextType } from '@shared/models/activitypub/context'
|
||||
|
||||
type Payload = { body: any, contextType?: ContextType, signatureActorId?: number }
|
||||
type Payload <T> = { body: T, contextType?: ContextType, signatureActorId?: number }
|
||||
|
||||
async function computeBody (payload: Payload) {
|
||||
async function computeBody <T> (
|
||||
payload: Payload<T>
|
||||
): Promise<T | T & { type: 'RsaSignature2017', creator: string, created: string }> {
|
||||
let body = payload.body
|
||||
|
||||
if (payload.signatureActorId) {
|
||||
const actorSignature = await ActorModel.load(payload.signatureActorId)
|
||||
if (!actorSignature) throw new Error('Unknown signature actor id.')
|
||||
|
||||
body = await buildSignedActivity(actorSignature, payload.body, payload.contextType)
|
||||
}
|
||||
|
||||
return body
|
||||
}
|
||||
|
||||
async function buildSignedRequestOptions (payload: Payload) {
|
||||
async function buildSignedRequestOptions (payload: Payload<any>) {
|
||||
let actor: MActor | null
|
||||
|
||||
if (payload.signatureActorId) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue