"use strict";(()=>{var e={};e.id=341,e.ids=[341],e.modules={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")},39491:e=>{e.exports=require("assert")},14300:e=>{e.exports=require("buffer")},32081:e=>{e.exports=require("child_process")},6113:e=>{e.exports=require("crypto")},82361:e=>{e.exports=require("events")},57147:e=>{e.exports=require("fs")},13685:e=>{e.exports=require("http")},85158:e=>{e.exports=require("http2")},95687:e=>{e.exports=require("https")},41808:e=>{e.exports=require("net")},15673:e=>{e.exports=require("node:events")},97742:e=>{e.exports=require("node:process")},47261:e=>{e.exports=require("node:util")},22037:e=>{e.exports=require("os")},71017:e=>{e.exports=require("path")},77282:e=>{e.exports=require("process")},85477:e=>{e.exports=require("punycode")},63477:e=>{e.exports=require("querystring")},12781:e=>{e.exports=require("stream")},24404:e=>{e.exports=require("tls")},76224:e=>{e.exports=require("tty")},57310:e=>{e.exports=require("url")},73837:e=>{e.exports=require("util")},59796:e=>{e.exports=require("zlib")},32583:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>j,patchFetch:()=>y,requestAsyncStorage:()=>g,routeModule:()=>v,serverHooks:()=>q,staticGenerationAsyncStorage:()=>h});var s={};t.r(s),t.d(s,{POST:()=>m,runtime:()=>f});var o=t(49303),i=t(88716),a=t(60670),n=t(87070),p=t(97816),u=t(12781),l=t(71017),d=t.n(l),c=t(57147);let f="nodejs",x=d().resolve(process.cwd(),"..");async function m(e){try{let{fileData:r,fileName:t,userEmail:s}=await e.json(),o=d().join(process.cwd(),"public","assets","js","localData.json"),i={email:[],drive_folder_url:[]};try{let e=await c.promises.readFile(o,"utf8");i=JSON.parse(e)}catch(e){console.warn("Could not read localData.json:",e.message)}if(!r||!t)return n.NextResponse.json({error:"Missing data or fileName in request body"},{status:400});let a=d().join(process.cwd(),"json-service.json"),l=await c.promises.readFile(a,"utf-8"),f=JSON.parse(l),m=new p.lkr.auth.GoogleAuth({credentials:{client_email:f.client_email,private_key:f.private_key},scopes:["https://www.googleapis.com/auth/drive.file"]}),v=p.lkr.drive({version:"v3",auth:m}),g=d().join(x,"data","profile_data"),h=[];try{h=await c.promises.readdir(g)}catch{}let q=h.find(e=>e.endsWith(".json"))||null,j=null;if(q){let e=d().join(g,q),r=await c.promises.readFile(e,"utf8");j=JSON.parse(r).find(e=>e.email===s)}let y=j?.drive_folder_url||(i.email[0]===s?i.drive_folder_url[0]:"");if(!y)return n.NextResponse.json({warning:"Drive folder URL not found for user; upload skipped",message:"No folder URL to upload file"},{status:400});let w=y.match(/\/folders\/([a-zA-Z0-9_-]+)/),_=w?w[1]:null;if(!_)return n.NextResponse.json({warning:"Drive folder ID could not be extracted from folder URL",message:"No valid folder ID found; upload skipped"},{status:400});let b=function(e){if(!Array.isArray(e)||0===e.length)return"";if(Array.isArray(e[0]))return e.map(e=>e.map(e=>"string"==typeof e&&e.includes(",")?`"${e.replace(/"/g,'""')}"`:e).join(",")).join("\n");if("object"==typeof e[0]){let r=Object.keys(e[0]),t=e.map(e=>r.map(r=>{let t=e[r];return null==t&&(t=""),"string"==typeof t&&t.includes(",")&&(t=`"${t.replace(/"/g,'""')}"`),t}).join(","));return[r.join(","),...t].join("\n")}return e.join("\n")}(r),D=new u.Readable;D.push(b),D.push(null);let k=new Date,N=t.endsWith(".gsheet")||t.endsWith(".xlsx")?t:`${t}_${k.getDate()}${k.getMonth()+1}${k.getTime()}`,R=await v.files.create({requestBody:{name:N,mimeType:"application/vnd.google-apps.spreadsheet",parents:[_]},media:{mimeType:"text/csv",body:D},fields:"id, name, mimeType"});return n.NextResponse.json({message:"Success",fileUrl:`https://drive.google.com/drive/folders/${_}`,fileInfo:R.data},{status:200})}catch(e){return n.NextResponse.json({error:"Failed to upload file",message:e.message},{status:500})}}let v=new o.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/export_drive/route",pathname:"/api/export_drive",filename:"route",bundlePath:"app/api/export_drive/route"},resolvedPagePath:"C:\\Users\\Design Collection\\OneDrive\\Desktop\\Jitendra Vishwakarma\\Next Dashboard\\web crawler for user dev\\Scrape Genius\\app\\api\\export_drive\\route.js",nextConfigOutput:"",userland:s}),{requestAsyncStorage:g,staticGenerationAsyncStorage:h,serverHooks:q}=v,j="/api/export_drive/route";function y(){return(0,a.patchFetch)({serverHooks:q,staticGenerationAsyncStorage:h})}}};var r=require("../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[8948,5972,6577,820,7816],()=>t(32583));module.exports=s})();