"use strict";var d=Object.defineProperty;var i=(r,t)=>d(r,"name",{value:t,configurable:true});const{timingSafeEqual:u}=require("node:crypto");const e=use("Route");const{API_VERSION:c}=require("../../environment-remote");const g=require("./migrate");g();async function l(r,t,n){const o=process.env.FERDIUM_LOCAL_TOKEN;const s=o&&r&&u(Buffer.from(r,"utf8"),Buffer.from(o,"utf8"));if(s){await n();return true}return t.forbidden()}i(l,"validateToken");const p=i(async({request:r,response:t},n)=>{const o=r.header("X-Franz-Version");if(!o){return t.forbidden()}const s=r.header("X-Ferdium-Local-Token");return l(s,t,n)},"OnlyAllowFerdium");const C=i(async({request:r,response:t},n)=>{const o=r.get().token;return l(o,t,n)},"RequireTokenInQS");const a="ferdium-local-token";const m=i(async({request:r,response:t},n)=>{const o=r.cookie(a);return l(o,t,n)},"RequireAuthenticatedBrowser");e.get("health",({response:r})=>r.send({api:"success",db:"success"})).middleware(p);e.group(()=>{e.post("auth/signup","UserController.signup");e.post("auth/login","UserController.login");e.get("me","UserController.me");e.put("me","UserController.updateMe");e.post("service","ServiceController.create");e.put("service/reorder","ServiceController.reorder");e.put("service/:id","ServiceController.edit");e.delete("service/:id","ServiceController.delete");e.get("me/services","ServiceController.list");e.get("recipes","RecipeController.list");e.get("recipes/search","RecipeController.search");e.get("recipes/popular","RecipeController.popularRecipes");e.get("recipes/download/:recipe","RecipeController.download");e.post("recipes/update","RecipeController.update");e.put("workspace/:id","WorkspaceController.edit");e.delete("workspace/:id","WorkspaceController.delete");e.post("workspace","WorkspaceController.create");e.get("workspace","WorkspaceController.list")}).prefix(c).middleware(p);e.group(()=>{e.get("icon/:id","ImageController.icon")}).prefix(c).middleware(C);e.group(()=>{e.post("import","UserController.import");e.get("import",({view:r})=>r.render("import"));e.get("export","UserController.export");e.post("transfer","UserController.importFerdium");e.get("transfer",({view:r})=>r.render("transfer"));e.get("/",({view:r})=>r.render("index"))}).middleware(m);e.get("token/:token",({params:{token:r},response:t})=>{if(l(r)){t.cookie(a,r,{httpOnly:true,sameSite:true,path:"/"});return t.redirect("/")}return t.forbidden()});
