"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getActorDisplayNameFromObject = exports.getImageInfoFromObject = exports.getActorAttributesFromObject = void 0;
const misc_1 = require("../../../../helpers/custom-validators/activitypub/misc");
const constants_1 = require("../../../../initializers/constants");
const core_utils_1 = require("../../../../../shared/core-utils");
const extra_utils_1 = require("../../../../../shared/extra-utils");
function getActorAttributesFromObject(actorObject, followersCount, followingCount) {
    var _a;
    return {
        type: actorObject.type,
        preferredUsername: actorObject.preferredUsername,
        url: actorObject.id,
        publicKey: actorObject.publicKey.publicKeyPem,
        privateKey: null,
        followersCount,
        followingCount,
        inboxUrl: actorObject.inbox,
        outboxUrl: actorObject.outbox,
        followersUrl: actorObject.followers,
        followingUrl: actorObject.following,
        sharedInboxUrl: ((_a = actorObject.endpoints) === null || _a === void 0 ? void 0 : _a.sharedInbox)
            ? actorObject.endpoints.sharedInbox
            : null
    };
}
exports.getActorAttributesFromObject = getActorAttributesFromObject;
function getImageInfoFromObject(actorObject, type) {
    const mimetypes = constants_1.MIMETYPES.IMAGE;
    const icon = type === 1
        ? actorObject.icon
        : actorObject.image;
    if (!icon || icon.type !== 'Image' || !(0, misc_1.isActivityPubUrlValid)(icon.url))
        return undefined;
    let extension;
    if (icon.mediaType) {
        extension = mimetypes.MIMETYPE_EXT[icon.mediaType];
    }
    else {
        const tmp = (0, core_utils_1.getLowercaseExtension)(icon.url);
        if (mimetypes.EXT_MIMETYPE[tmp] !== undefined)
            extension = tmp;
    }
    if (!extension)
        return undefined;
    return {
        name: (0, extra_utils_1.buildUUID)() + extension,
        fileUrl: icon.url,
        height: icon.height,
        width: icon.width,
        type
    };
}
exports.getImageInfoFromObject = getImageInfoFromObject;
function getActorDisplayNameFromObject(actorObject) {
    return actorObject.name || actorObject.preferredUsername;
}
exports.getActorDisplayNameFromObject = getActorDisplayNameFromObject;
//# sourceMappingURL=object-to-model-attributes.js.map