import { d as defineEventHandler, w as publicSettings, c as createError, u as useLogger, t as setHeader, aj as getRouterParams } from '../../../nitro/nitro.mjs';
import 'luxon';
import '@sequelize/core';
import 'html-to-text';
import 'zod';
import 'crypto';
import 'node:fs';
import 'sharp';
import 'path';
import 'node:stream';
import 'jsdom';
import 'dompurify';
import 'mime-types';
import 'fs';
import 'fs/promises';
import 'linkify-html';
import '@peertube/http-signature';
import 'jsonld';
import 'lodash.intersection';
import 'email-templates';
import 'node:http';
import 'node:https';
import 'node:crypto';
import 'node:events';
import 'node:buffer';
import 'node:path';
import 'vue';
import 'vue-router';
import 'dotenv';
import 'url';
import 'bcryptjs';
import 'slugify';
import 'umzug';
import 'consola';
import '@sequelize/core/decorators-legacy';
import 'util';
import 'mitt';
import 'ical.js';
import 'node:url';
import 'fast-xml-parser';

const _stamp_ = defineEventHandler(async (evt) => {
  if (!publicSettings.enable_federation || !publicSettings.enable_federation_quoting) {
    throw createError({ statusCode: 404, message: "Federation quoting is not enabled" });
  }
  const log = useLogger("Quote Auth");
  setHeader(evt, "Content-Type", "application/activity+json");
  const { stamp } = getRouterParams(evt);
  if (!stamp) {
    throw createError({ statusCode: 400, message: "stamp is required" });
  }
  try {
    const { eventId, quoterPostId } = JSON.parse(Buffer.from(stamp, "base64url").toString());
    log.debug(`eventId: ${eventId}, quoterPostId: ${quoterPostId}`);
    return {
      "@context": [
        "https://www.w3.org/ns/activitystreams",
        {
          gts: "https://gotosocial.org/ns#",
          QuoteAuthorization: "https://w3id.org/fep/044f#QuoteAuthorization",
          interactingObject: "gts:interactingObject",
          interactionTarget: "gts:interactionTarget"
        }
      ],
      "id": `https://${publicSettings.baseurl}/federation/q/${stamp}`,
      "type": "QuoteAuthorization",
      "attributedTo": `${publicSettings.baseurl}/federation/u/${publicSettings.instance_name}`,
      "interactingObject": quoterPostId,
      "interactionTarget": eventId
    };
  } catch {
    log.error("Failed to parse stamp", stamp);
    throw createError({ statusCode: 500, message: "Failed to parse stamp" });
  }
});

export { _stamp_ as default };
