import { y as defineEventHandler, aC as publicSettings, aD as publicSettingsLastModified, aW as setHeader, af as handleCache } from '../nitro/nitro.mjs';
import fs from 'fs/promises';
import path from 'path';
import 'luxon';
import '@sequelize/core';
import 'html-to-text';
import 'zod';
import 'crypto';
import 'node:fs';
import 'sharp';
import 'node:stream';
import 'jsdom';
import 'dompurify';
import 'mime-types';
import 'fs';
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 custom_js = defineEventHandler(async (event) => {
  let custom_js = publicSettings.custom_js;
  let stat = null;
  let lastModified = publicSettingsLastModified.custom_js || /* @__PURE__ */ new Date(0);
  try {
    const filePath = path.resolve("./custom.js");
    stat = await fs.stat(filePath);
    custom_js += await fs.readFile(filePath, "utf8");
    if (stat.mtime > lastModified) {
      lastModified = stat.mtime;
    }
  } catch {
    custom_js += "\n/** no custom.js file **/";
  }
  setHeader(event, "Content-Type", "application/javascript");
  if (await handleCache(event, lastModified)) return;
  return custom_js;
});

export { custom_js as default };
