diff --git a/app/controllers/creditpd.controller.js b/app/controllers/creditpd.controller.js index cd71308..a35f4c9 100644 --- a/app/controllers/creditpd.controller.js +++ b/app/controllers/creditpd.controller.js @@ -199,26 +199,33 @@ exports.DownloadPdReport = async (req, res) => { try { - pd_id = req.query.ref_no; - DownloadPdReportUrl = process.env.PD_REPORT_URL; - url = DownloadPdReportUrl+"getCreditPDReportforCETApp?credit_pd_id="+pd_id; + // pd_id = req.query.ref_no; + // DownloadPdReportUrl = process.env.PD_REPORT_URL; + // url = DownloadPdReportUrl+"getCreditPDReportforCETApp?credit_pd_id="+pd_id; - request({ - url: url, - method: "GET" + // request({ + // url: url, + // method: "GET" - }, function (error, response, body) { console.log(body); - if (body != undefined) { - data = JSON.parse(body); - if ( data.status == 200) { + // }, function (error, response, body) { console.log(body); + // if (body != undefined) { + // data = JSON.parse(body); + // if ( data.status == 200) { - link = data.records; - res.send({'status':200,'message':"success",'data':link}); - }else{ - res.send({'status':404,'message':"failed",'data':"No data"}); - } - } - }); + // link = data.records; + // res.send({'status':200,'message':"success",'data':link}); + // }else{ + // res.send({'status':404,'message':"failed",'data':"No data"}); + // } + // } + // }); + + const storage = new Storage({ keyFilename : path.join(__dirname, "../../googleCloud.json") }); + const bucketName = process.env.GCP_BUCKET_NAME; + const fileName = 'credit-pd/pd'+req.query.ref_no+'/'+req.query.ref_no+'.pdf'; + const options = {version: 'v2', action: 'read',expires: Date.now() + 1000 * 60 * 60, }; + const [url] = await storage.bucket(bucketName).file(fileName).getSignedUrl(options); + res.send({'status':200,'message':"success",'data':url}); } catch(err) {