"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.webfingerValidator = void 0;
const tslib_1 = require("tslib");
const express_validator_1 = require("express-validator");
const webfinger_1 = require("../../helpers/custom-validators/webfinger");
const express_utils_1 = require("../../helpers/express-utils");
const actor_1 = require("../../models/actor/actor");
const shared_1 = require("./shared");
const webfingerValidator = [
    (0, express_validator_1.query)('resource')
        .custom(webfinger_1.isWebfingerLocalResourceValid),
    (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        if ((0, shared_1.areValidationErrors)(req, res))
            return;
        const nameWithHost = (0, express_utils_1.getHostWithPort)(req.query.resource.substr(5));
        const [name] = nameWithHost.split('@');
        const actor = yield actor_1.ActorModel.loadLocalUrlByName(name);
        if (!actor) {
            return res.fail({
                status: 404,
                message: 'Actor not found'
            });
        }
        res.locals.actorUrl = actor;
        return next();
    })
];
exports.webfingerValidator = webfingerValidator;
//# sourceMappingURL=webfinger.js.map