"use strict";(()=>{var e={};e.id=355,e.ids=[355],e.modules={3524:e=>{e.exports=require("@prisma/client")},7096:e=>{e.exports=require("bcrypt")},9344:e=>{e.exports=require("jsonwebtoken")},145:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},6249:(e,t)=>{Object.defineProperty(t,"l",{enumerable:!0,get:function(){return function e(t,r){return r in t?t[r]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,r)):"function"==typeof t&&"default"===r?t:void 0}}})},4585:(e,t,r)=>{r.r(t),r.d(t,{config:()=>f,default:()=>l,routeModule:()=>p});var a={};r.r(a),r.d(a,{default:()=>c});var n=r(1802),s=r(7153),u=r(6249),o=r(2944),i=r(9036);let d={maintenanceMode:!1,apiVersion:"1.0.0",maxUploadMB:(0,i.I)().uploadMaxMB};async function c(e,t){if(await (0,o.k)(e,t)){if("GET"===e.method)return t.status(200).json({success:!0,data:d});if("PUT"===e.method){let{maxUploadMB:r}=e.body||{};return"number"==typeof r&&((0,i.A)({uploadMaxMB:r}),d.maxUploadMB=r),t.status(200).json({success:!0,message:"Configuration updated successfully",data:e.body})}return t.status(405).json({success:!1,error:"Method not allowed"})}}let l=(0,u.l)(a,"default"),f=(0,u.l)(a,"config"),p=new n.PagesAPIRouteModule({definition:{kind:s.x.PAGES_API,page:"/api/v1/admin/config",pathname:"/api/v1/admin/config",bundlePath:"",filename:""},userland:a})},3481:(e,t,r)=>{r.d(t,{K:()=>s});var a=r(1450),n=r(1026);let s={async getUserById(e){let t=await a.Z.user.findUnique({where:{id:e},select:{id:!0,username:!0,avatarUrl:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0}});return t?{...t,role:t.role,createdAt:t.createdAt.toISOString(),lastLogin:t.lastLogin?.toISOString()||new Date().toISOString(),avatarUrl:t.avatarUrl||""}:null},getUserByUsername:async e=>a.Z.user.findUnique({where:{username:e}}),async createUser(e,t,r){let s=await (0,n.c_)(t),u=`https://api.dicebear.com/7.x/avataaars/svg?seed=${e}`;return a.Z.user.create({data:{username:e,password:s,avatarUrl:u,role:"CREATOR",status:"ACTIVE"}})},async authenticateUser(e,t){let r=await this.getUserByUsername(e);return r&&r.password&&await (0,n.Gv)(t,r.password)?(await a.Z.user.update({where:{id:r.id},data:{lastLogin:new Date}}),{id:r.id,username:r.username,avatarUrl:r.avatarUrl||"",role:r.role,status:r.status,createdAt:r.createdAt.toISOString(),lastLogin:new Date().toISOString()}):null},getAllUsers:async()=>a.Z.user.findMany({orderBy:{createdAt:"desc"}}),updateUser:async(e,t)=>a.Z.user.update({where:{id:e},data:{username:t.username,avatarUrl:t.avatarUrl}}),updateUserRole:async(e,t)=>a.Z.user.update({where:{id:e},data:{role:t}}),async toggleUserStatus(e){let t=await a.Z.user.findUnique({where:{id:e}});if(!t)throw Error("User not found");let r="ACTIVE"===t.status?"BANNED":"ACTIVE";return a.Z.user.update({where:{id:e},data:{status:r}})}}},1026:(e,t,r)=>{r.d(t,{Gv:()=>d,RA:()=>c,WX:()=>l,c_:()=>i});var a=r(7096),n=r.n(a),s=r(9344),u=r.n(s);function o(){let e=process.env.JWT_SECRET;if(!e)throw Error("JWT_SECRET is not set");return e}async function i(e){return n().hash(e,10)}async function d(e,t){return n().compare(e,t)}function c(e){return u().sign({userId:e},o(),{expiresIn:"7d"})}function l(e){try{return u().verify(e,o())}catch(e){return null}}},2944:(e,t,r)=>{r.d(t,{k:()=>s});var a=r(8103),n=r(7556);async function s(e,t){return!!await (0,a.m)(e,t)&&(e.user?.role===n.i.ADMIN||(t.status(403).json({success:!1,error:"Admin access required"}),!1))}},8103:(e,t,r)=>{r.d(t,{R:()=>u,m:()=>s});var a=r(1026),n=r(3481);async function s(e,t){let r=o(e);if(!r)return t.status(401).json({success:!1,error:"Authentication required"}),!1;let s=(0,a.WX)(r);if(!s)return t.status(401).json({success:!1,error:"Invalid or expired token"}),!1;let u=await n.K.getUserById(s.userId);return u?"BANNED"===u.status?(t.status(403).json({success:!1,error:"Account has been banned"}),!1):(e.user=u,!0):(t.status(401).json({success:!1,error:"User not found"}),!1)}async function u(e){let t=o(e);if(!t)return;let r=(0,a.WX)(t);if(!r)return;let s=await n.K.getUserById(r.userId);s&&"BANNED"!==s.status&&(e.user=s)}function o(e){if(e.cookies.token)return e.cookies.token;let t=e.headers.authorization;return t&&t.startsWith("Bearer ")?t.substring(7):null}},1450:(e,t,r)=>{r.d(t,{Z:()=>n});var a=r(3524);let n=globalThis.prisma??new a.PrismaClient},9036:(e,t,r)=>{r.d(t,{A:()=>s,I:()=>n});let a={uploadMaxMB:3},n=()=>a,s=e=>("number"==typeof e.uploadMaxMB&&(a.uploadMaxMB=e.uploadMaxMB),a)},7556:(e,t,r)=>{var a,n;r.d(t,{i:()=>a}),function(e){e.USER="USER",e.ADMIN="ADMIN",e.CREATOR="CREATOR",e.MANAGER="MANAGER"}(a||(a={})),function(e){e.CODE="CODE",e.ASSET_ZIP="ASSET_ZIP",e.VIDEO="VIDEO"}(n||(n={}))},7153:(e,t)=>{var r;Object.defineProperty(t,"x",{enumerable:!0,get:function(){return r}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE"}(r||(r={}))},1802:(e,t,r)=>{e.exports=r(145)}};var t=require("../../../../webpack-api-runtime.js");t.C(e);var r=t(t.s=4585);module.exports=r})();