"use strict";(()=>{var e={};e.id=9036,e.ids=[9036],e.modules={85890:e=>{e.exports=require("better-sqlite3")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},84770:e=>{e.exports=require("crypto")},92048:e=>{e.exports=require("fs")},19801:e=>{e.exports=require("os")},55315:e=>{e.exports=require("path")},1724:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>E,patchFetch:()=>_,requestAsyncStorage:()=>m,routeModule:()=>c,serverHooks:()=>g,staticGenerationAsyncStorage:()=>h});var o={};t.r(o),t.d(o,{GET:()=>p});var n=t(49303),a=t(88716),l=t(60670),i=t(87070),s=t(94925),d=t(4709);let u=(0,t(43895).h)("api/repositories-excluded");async function p(){try{let e=(0,s.getDbInstance)(),r=(0,d.Bj)(e);return i.NextResponse.json({success:!0,repositories:r})}catch(e){return u.error("error:",{error:e instanceof Error?e.message:String(e)}),i.NextResponse.json({success:!1,error:"Failed to get excluded repositories"},{status:500})}}let c=new n.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/repositories/excluded/route",pathname:"/api/repositories/excluded",filename:"route",bundlePath:"app/api/repositories/excluded/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/repositories/excluded/route.ts",nextConfigOutput:"",userland:o}),{requestAsyncStorage:m,staticGenerationAsyncStorage:h,serverHooks:g}=c,E="/api/repositories/excluded/route";function _(){return(0,l.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:h})}},4709:(e,r,t)=>{t.d(r,{Bj:()=>o.Bj,RT:()=>o.RT,VZ:()=>o.VZ,j$:()=>o.j$,mm:()=>o.mm,nJ:()=>o.nJ});var o=t(95280)},95280:(e,r,t)=>{t.d(r,{Bj:()=>v,Bm:()=>C,L_:()=>R,RT:()=>f,VZ:()=>g,fC:()=>b,h4:()=>d,j$:()=>m,mm:()=>_,nJ:()=>E,nb:()=>u,sN:()=>U});var o=t(84770),n=t(55315),a=t.n(n),l=t(43753);function i(e){return{id:e.id,name:e.name,path:e.path,enabled:1===e.enabled,cloneUrl:e.clone_url||void 0,normalizedCloneUrl:e.normalized_clone_url||void 0,cloneSource:e.clone_source,isEnvManaged:1===e.is_env_managed,createdAt:new Date(e.created_at),updatedAt:new Date(e.updated_at)}}function s(e){return{id:e.id,cloneUrl:e.clone_url,normalizedCloneUrl:e.normalized_clone_url,targetPath:e.target_path,repositoryId:e.repository_id||void 0,status:e.status,pid:e.pid||void 0,progress:e.progress,errorCategory:e.error_category||void 0,errorCode:e.error_code||void 0,errorMessage:e.error_message||void 0,startedAt:e.started_at?new Date(e.started_at):void 0,completedAt:e.completed_at?new Date(e.completed_at):void 0,createdAt:new Date(e.created_at)}}function d(e,r){let t=(0,o.randomUUID)(),n=Date.now();return e.prepare(`
    INSERT INTO repositories (
      id, name, path, enabled, clone_url, normalized_clone_url,
      clone_source, is_env_managed, created_at, updated_at
    )
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  `).run(t,r.name,r.path,!1!==r.enabled?1:0,r.cloneUrl||null,r.normalizedCloneUrl||null,r.cloneSource,r.isEnvManaged?1:0,n,n),{id:t,name:r.name,path:r.path,enabled:!1!==r.enabled,cloneUrl:r.cloneUrl,normalizedCloneUrl:r.normalizedCloneUrl,cloneSource:r.cloneSource,isEnvManaged:r.isEnvManaged||!1,createdAt:new Date(n),updatedAt:new Date(n)}}function u(e,r){let t=e.prepare(`
    SELECT * FROM repositories
    WHERE normalized_clone_url = ?
  `).get(r);return t?i(t):null}function p(e,r){let t=e.prepare(`
    SELECT * FROM repositories
    WHERE path = ?
  `).get(r);return t?i(t):null}function c(e,r,t){let o=Date.now(),n=["updated_at = ?"],a=[o];void 0!==t.name&&(n.push("name = ?"),a.push(t.name)),void 0!==t.enabled&&(n.push("enabled = ?"),a.push(t.enabled?1:0)),void 0!==t.cloneUrl&&(n.push("clone_url = ?"),a.push(t.cloneUrl||null)),void 0!==t.normalizedCloneUrl&&(n.push("normalized_clone_url = ?"),a.push(t.normalizedCloneUrl||null)),a.push(r),e.prepare(`
    UPDATE repositories
    SET ${n.join(", ")}
    WHERE id = ?
  `).run(...a)}function m(e){return e.prepare(`
    SELECT * FROM repositories
    ORDER BY name ASC
  `).all().map(i)}function h(e){return a().resolve(e)}function g(e){if(!e||"string"!=typeof e)return{valid:!1,error:"repositoryPath is required"};if(e.includes("\0"))return{valid:!1,error:"Invalid repository path"};let r=h(e);return(0,l.F)(r)?{valid:!1,error:"Invalid repository path"}:{valid:!0,resolvedPath:r}}function E(e,r){!function(e,r){for(let t of r){let r=h(t);p(e,r)||d(e,{name:a().basename(r),path:r,cloneSource:"local",isEnvManaged:!0,enabled:!0})}}(e,r);let t=function(e,r){let t=e.prepare("SELECT path FROM repositories WHERE enabled = 0").all().map(e=>e.path);return r.filter(e=>!t.includes(h(e)))}(e,r),o=r.filter(e=>!t.includes(e));return{filteredPaths:t,excludedPaths:o,excludedCount:o.length}}function _(e,r){let t=h(r),o=p(e,t);if(o)c(e,o.id,{enabled:!1});else{if(e.prepare("SELECT COUNT(*) as count FROM repositories WHERE enabled = 0").get().count>=1e3)throw Error("Disabled repository limit exceeded");d(e,{name:a().basename(t),path:t,cloneSource:"local",isEnvManaged:!1,enabled:!1})}}function v(e){return e.prepare("SELECT * FROM repositories WHERE enabled = 0 ORDER BY name ASC").all().map(i)}function f(e,r){let t=p(e,h(r));return t?(c(e,t.id,{enabled:!0}),{...t,enabled:!0}):null}function C(e,r){let t=(0,o.randomUUID)(),n=Date.now();return e.prepare(`
    INSERT INTO clone_jobs (
      id, clone_url, normalized_clone_url, target_path,
      status, progress, created_at
    )
    VALUES (?, ?, ?, ?, 'pending', 0, ?)
  `).run(t,r.cloneUrl,r.normalizedCloneUrl,r.targetPath,n),{id:t,cloneUrl:r.cloneUrl,normalizedCloneUrl:r.normalizedCloneUrl,targetPath:r.targetPath,status:"pending",progress:0,createdAt:new Date(n)}}function R(e,r){let t=e.prepare(`
    SELECT * FROM clone_jobs
    WHERE id = ?
  `).get(r);return t?s(t):null}function U(e,r,t){let o=[],n=[];void 0!==t.status&&(o.push("status = ?"),n.push(t.status)),void 0!==t.pid&&(o.push("pid = ?"),n.push(t.pid)),void 0!==t.progress&&(o.push("progress = ?"),n.push(t.progress)),void 0!==t.repositoryId&&(o.push("repository_id = ?"),n.push(t.repositoryId)),void 0!==t.errorCategory&&(o.push("error_category = ?"),n.push(t.errorCategory)),void 0!==t.errorCode&&(o.push("error_code = ?"),n.push(t.errorCode)),void 0!==t.errorMessage&&(o.push("error_message = ?"),n.push(t.errorMessage)),void 0!==t.startedAt&&(o.push("started_at = ?"),n.push(t.startedAt.getTime())),void 0!==t.completedAt&&(o.push("completed_at = ?"),n.push(t.completedAt.getTime())),0!==o.length&&(n.push(r),e.prepare(`
    UPDATE clone_jobs
    SET ${o.join(", ")}
    WHERE id = ?
  `).run(...n))}function b(e,r){let t=e.prepare(`
    SELECT * FROM clone_jobs
    WHERE normalized_clone_url = ?
      AND status IN ('pending', 'running')
    ORDER BY created_at DESC
    LIMIT 1
  `).get(r);return t?s(t):null}}};var r=require("../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),o=r.X(0,[8948,5972,3895,4925],()=>t(1724));module.exports=o})();