import { d as defineEventHandler, g as getCookie, c as createError } from '../../nitro/nitro.mjs';
import { b as verifyToken } from '../../_/auth.mjs';
import { r as readNews } from '../../_/news.mjs';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import 'bcryptjs';
import 'jsonwebtoken';
import 'fs';
import 'path';
import '../../_/encryption.mjs';
import 'crypto';

const news_get = defineEventHandler(async (event) => {
  try {
    const token = getCookie(event, "auth_token");
    if (!token) {
      throw createError({
        statusCode: 401,
        message: "Nicht authentifiziert."
      });
    }
    const decoded = verifyToken(token);
    if (!decoded) {
      throw createError({
        statusCode: 401,
        message: "Ung\xFCltiges Token."
      });
    }
    const news = await readNews();
    news.sort((a, b) => new Date(b.created) - new Date(a.created));
    return {
      success: true,
      news
    };
  } catch (error) {
    console.error("Fehler beim Abrufen der News:", error);
    throw error;
  }
});

export { news_get as default };
//# sourceMappingURL=news.get.mjs.map
