import { y as defineEventHandler, aa as getRouterParam, v as createError, aA as pluginController, aE as readBody, aZ as setSetting } from '../../../../nitro/nitro.mjs';
import { r as requireAdminSession } from '../../../../_/session.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';
import '../../../../_/getUser.mjs';
import '../../../../_/jwt.mjs';
import 'jose';

const settings_put = defineEventHandler(async (event) => {
  await requireAdminSession(event);
  const pluginName = getRouterParam(event, "name");
  if (!pluginName) {
    throw createError({ statusCode: 400, message: "Plugin name is required" });
  }
  const plugin = pluginController.getPlugin(pluginName);
  if (!plugin) {
    throw createError({ statusCode: 404, message: "Plugin not found" });
  }
  const body = await readBody(event);
  const settingKey = `plugin_${pluginName}`;
  await setSetting(settingKey, body);
  plugin.settings = body;
  await plugin.unload?.();
  if (plugin.settings.enable) {
    await plugin.load();
  }
  return { success: true };
});

export { settings_put as default };
