"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.processActivityPubHttpUnicast = void 0;
const tslib_1 = require("tslib");
const logger_1 = require("../../../helpers/logger");
const requests_1 = require("../../../helpers/requests");
const actor_follow_health_cache_1 = require("../../actor-follow-health-cache");
const activitypub_http_utils_1 = require("./utils/activitypub-http-utils");
function processActivityPubHttpUnicast(job) {
    return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
        logger_1.logger.info('Processing ActivityPub unicast in job %d.', job.id);
        const payload = job.data;
        const uri = payload.uri;
        const body = yield (0, activitypub_http_utils_1.computeBody)(payload);
        const httpSignatureOptions = yield (0, activitypub_http_utils_1.buildSignedRequestOptions)(payload);
        const options = {
            method: 'POST',
            json: body,
            httpSignature: httpSignatureOptions,
            headers: (0, activitypub_http_utils_1.buildGlobalHeaders)(body)
        };
        try {
            yield (0, requests_1.doRequest)(uri, options);
            actor_follow_health_cache_1.ActorFollowHealthCache.Instance.updateActorFollowsHealth([uri], []);
        }
        catch (err) {
            actor_follow_health_cache_1.ActorFollowHealthCache.Instance.updateActorFollowsHealth([], [uri]);
            throw err;
        }
    });
}
exports.processActivityPubHttpUnicast = processActivityPubHttpUnicast;
//# sourceMappingURL=activitypub-http-unicast.js.map