import { f as defineAdminEventHandler, aA as requireSuperAdmin, q as readBody, c as createError, a as getSchemaManager } from '../../../../nitro/nitro.mjs';
import { getSearchService } from '../../../../_/index.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';

const reindex_post = defineAdminEventHandler("admin:delivery:reindex", async (event) => {
  var _a, _b;
  await requireSuperAdmin(event);
  const body = (_a = await readBody(event)) != null ? _a : {};
  const indexName = typeof body.index === "string" ? body.index.trim() : "";
  if (!indexName) {
    throw createError({
      statusCode: 400,
      statusMessage: "Bad Request",
      message: "`index` (string) is required"
    });
  }
  const batchSizeRaw = Number((_b = body.batchSize) != null ? _b : 100);
  const batchSize = Number.isFinite(batchSizeRaw) && batchSizeRaw > 0 ? Math.min(Math.floor(batchSizeRaw), 500) : 100;
  if (indexName !== "media") {
    const schemaManager = getSchemaManager();
    if (!schemaManager.getSchema(indexName)) {
      throw createError({
        statusCode: 404,
        statusMessage: "Not Found",
        message: `Index '${indexName}' is not a known content type or media`
      });
    }
  }
  const service = getSearchService();
  const result = await service.reindex(indexName, batchSize);
  return {
    success: true,
    data: {
      index: indexName,
      batchSize,
      ...result
    }
  };
});

export { reindex_post as default };
//# sourceMappingURL=reindex.post.mjs.map
