"use strict";(()=>{var e={};e.id=955,e.ids=[955],e.modules={846:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},4870:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},3295:e=>{e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},9294:e=>{e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},3033:e=>{e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},9646:e=>{e.exports=require("child_process")},9021:e=>{e.exports=require("fs")},9748:e=>{e.exports=require("fs/promises")},3873:e=>{e.exports=require("path")},8354:e=>{e.exports=require("util")},452:(e,t,r)=>{r.r(t),r.d(t,{patchFetch:()=>j,routeModule:()=>g,serverHooks:()=>w,workAsyncStorage:()=>v,workUnitAsyncStorage:()=>m});var s={};r.r(s),r.d(s,{GET:()=>f,POST:()=>x});var a=r(2706),i=r(8203),n=r(5994),o=r(9187),c=r(9269),p=r(2021),u=r(9748),d=r(9021),l=r(3873);class h{constructor(){this.cacheDir=(0,l.join)(process.cwd(),".cache"),this.ttl=864e5,this.initializeCache()}static getInstance(){return h.instance||(h.instance=new h),h.instance}async initializeCache(){(0,d.existsSync)(this.cacheDir)||await (0,u.mkdir)(this.cacheDir,{recursive:!0})}getCacheFilePath(e){return(0,l.join)(this.cacheDir,`${Buffer.from(e).toString("base64")}.json`)}async set(e,t){let r={data:t,timestamp:Date.now()},s=this.getCacheFilePath(e);await (0,u.writeFile)(s,JSON.stringify(r),"utf-8")}async get(e){try{let t=this.getCacheFilePath(e);if(!(0,d.existsSync)(t))return null;let r=await (0,u.readFile)(t,"utf-8"),s=JSON.parse(r);if(Date.now()-s.timestamp>this.ttl)return null;return s.data}catch(e){return console.error("Cache read error:",e),null}}}async function f(e,{params:t}){let r=t.deviceId,s=(0,p.y)(r),{packageName:a}=t;if(!s)return o.NextResponse.json({error:"Device ID is required"},{status:400});try{let e=h.getInstance(),t=`app_details_${s}_${a}`,r=await e.get(t);if(r)return o.NextResponse.json({details:r});let i=c.J.getInstance(),n=await i.getAppInfo(s,a);return await e.set(t,n),o.NextResponse.json({details:n})}catch(e){return console.error("Error fetching app details:",e),o.NextResponse.json({error:e instanceof Error?e.message:"Failed to fetch app details"},{status:500})}}async function x(e,{params:t}){let r=t.deviceId,s=(0,p.y)(r),{packageName:a}=t,{action:i}=await e.json();if(!s)return o.NextResponse.json({error:"Device ID is required"},{status:400});if(!i)return o.NextResponse.json({error:"Action is required"},{status:400});let n=c.J.getInstance();try{switch(i){case"uninstall":return await n.uninstallApp(s,a),o.NextResponse.json({success:!0});case"clear":return await n.clearAppData(s,a),o.NextResponse.json({success:!0});case"force-stop":return await n.forceStopApp(s,a),o.NextResponse.json({success:!0});default:return o.NextResponse.json({error:"Invalid action specified"},{status:400})}}catch(e){return console.error("Error handling app operation:",e),o.NextResponse.json({error:e instanceof Error?e.message:"Operation failed"},{status:500})}}let g=new a.AppRouteRouteModule({definition:{kind:i.RouteKind.APP_ROUTE,page:"/api/device/[deviceId]/apps/[packageName]/route",pathname:"/api/device/[deviceId]/apps/[packageName]",filename:"route",bundlePath:"app/api/device/[deviceId]/apps/[packageName]/route"},resolvedPagePath:"/Users/saleeh/codes/appmaker/adb-web/src/app/api/device/[deviceId]/apps/[packageName]/route.ts",nextConfigOutput:"",userland:s}),{workAsyncStorage:v,workUnitAsyncStorage:m,serverHooks:w}=g;function j(){return(0,n.patchFetch)({workAsyncStorage:v,workUnitAsyncStorage:m})}},2021:(e,t,r)=>{r.d(t,{y:()=>s});function s(e){return Buffer.from(e,"base64").toString()}}};var t=require("../../../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[994,452,577],()=>r(452));module.exports=s})();