Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : SPB Private Cloud8 * File : app/api/ai/tag/route.ts9 * Module : app10 * Repository : https://git.spboucher.ai/spb-cloud11 * Project Website : https://cloud.spboucher.ai12 * Created : 2026-02-1813 * Last Modified : 2026-02-1814 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { NextRequest, NextResponse } from "next/server";43import { getIronSession } from "iron-session";44import { SessionData, sessionOptions } from "@/lib/session";45import { aiAutoTag } from "@/lib/ai";4647export async function POST(request: NextRequest) {48 const response = NextResponse.next();49 const session = await getIronSession<SessionData>(request, response, sessionOptions);50 if (!session.isLoggedIn) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });5152 const { fileId } = await request.json();53 if (!fileId) return NextResponse.json({ error: "fileId required" }, { status: 400 });5455 try {56 const tags = await aiAutoTag(fileId);57 return NextResponse.json({ tags });58 } catch (error) {59 return NextResponse.json({ error: "Auto-tag failed", details: (error as Error).message }, { status: 500 });60 }61}62