import { d as defineEventHandler, r as requireAuth, bT as requirePermission, c as createError, G as createContentManager, bo as getStorageProvider } from '../../../../nitro/nitro.mjs';
import { i as isCloudStorageProvider, r as resolveSignedVariantFormats, p as parseMediaFormats, a as resolveMediaUrl } from '../../../../_/media-delivery.mjs';
import { a as isProcessableImage, p as parseFocalPoint } from '../../../../_/media-variants.mjs';
import 'node:crypto';
import 'jsonwebtoken';
import 'node:fs';
import 'node:module';
import 'node:path';
import 'node:url';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'pino';
import 'drizzle-orm/better-sqlite3';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/mysql2';
import 'better-sqlite3';
import 'pg';
import 'mysql2/promise';
import 'drizzle-orm';
import 'fs';
import 'path';
import 'prom-client';
import 'bcryptjs';
import '@node-rs/argon2';
import 'node:async_hooks';
import 'crypto';
import 'node:dns';
import 'node:util';
import 'node:net';
import 'fs/promises';
import 'url';
import 'semver';
import 'sharp';

const variants_get = defineEventHandler(async (event) => {
  var _a, _b, _c, _d, _e, _f;
  await requireAuth(event);
  await requirePermission(
    event.context.user,
    "media",
    "read",
    event.context.adminUser,
    event.context.apiToken
  );
  const id = Number((_a = event.context.params) == null ? void 0 : _a.id);
  if (!Number.isFinite(id) || id < 1) {
    throw createError({
      statusCode: 400,
      statusMessage: "Bad Request",
      message: "Invalid media ID"
    });
  }
  const media = await createContentManager("media").findOne(id);
  if (!media) {
    throw createError({
      statusCode: 404,
      statusMessage: "Not Found",
      message: `Media file with ID ${id} not found`
    });
  }
  const storage = getStorageProvider();
  const mimeType = typeof media.mimeType === "string" ? media.mimeType : "";
  const storageType = typeof media.storageProvider === "string" && media.storageProvider.trim() !== "" ? media.storageProvider : storage.getType();
  const supportsSignedUrls = isCloudStorageProvider(storageType) && storage.supportsSignedUrls();
  const formats = supportsSignedUrls ? await resolveSignedVariantFormats(media.formats) : parseMediaFormats(media.formats);
  return {
    data: {
      id,
      original: {
        width: (_b = media.width) != null ? _b : null,
        height: (_c = media.height) != null ? _c : null,
        mimeType,
        size: Number((_d = media.size) != null ? _d : 0),
        url: resolveMediaUrl(id, storageType, media.url)
      },
      focalPoint: (_e = parseFocalPoint(media.focalPoint)) != null ? _e : null,
      variants: (_f = formats == null ? void 0 : formats.variants) != null ? _f : {},
      storage: {
        type: storageType,
        supportsSignedUrls
      },
      processable: isProcessableImage(mimeType)
    }
  };
});

export { variants_get as default };
//# sourceMappingURL=variants.get.mjs.map
