From 942af90bc28efe872db536ea91268c29dcc1a76c Mon Sep 17 00:00:00 2001 From: Rajnish Dargan Date: Fri, 13 Dec 2024 15:51:31 +0530 Subject: [PATCH] PS-2796 fix: Handling get-status API in admin app ZIP file upload --- next.config.mjs | 4 -- src/pages/api/content-upload/get-status.js | 45 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/pages/api/content-upload/get-status.js diff --git a/next.config.mjs b/next.config.mjs index e5d6b34..ccbb45b 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -95,10 +95,6 @@ const nextConfig = { source: "/action/:path*", // Match any other routes starting with /action/ destination: `${process.env.WORKSPACE_BASE_URL}/api/proxy?path=/action/:path*`, // Forward them to proxy.js }, - { - source: "/api/content-upload/get-status/:path*", // Match //api/content-upload/get-status/ routes - destination: `${process.env.WORKSPACE_BASE_URL}/api/content-upload/get-status/:path*`, // Forward to workspace get-status API - }, { source: "/api/:path*", // Match /api/ routes destination: `${process.env.WORKSPACE_BASE_URL}/api/proxy?path=/api/:path*`, // Forward them to proxy.js diff --git a/src/pages/api/content-upload/get-status.js b/src/pages/api/content-upload/get-status.js new file mode 100644 index 0000000..d5ad36d --- /dev/null +++ b/src/pages/api/content-upload/get-status.js @@ -0,0 +1,45 @@ +export default async function handler(req, res) { + if (req.method === "POST") { + try { + const { contenturl } = req.body; + + // Split the URL by slashes and extract the second last part + const parts = contenturl.split("/"); + const doId = parts.length > 2 ? parts[parts.length - 2] : null; + if (doId) { + const baseURL = process.env.NEXT_PUBLIC_MIDDLEWARE_URL; + + const axios = require("axios"); + + let config = { + method: "get", + maxBodyLength: Infinity, + url: `${baseURL}/api/content/v1/read/${doId}?fields=artifactUrl`, + headers: { + }, + }; + + await axios + .request(config) + .then((response) => { + console.log(JSON.stringify(response.data)); + if (response?.data?.result?.content?.artifactUrl != null) { + res.status(200).json({ doId, success: true }); + } else { + res.status(200).json({ doId, success: false }); + } + }) + .catch((error) => { + res.status(200).json({ doId, success: false }); + }); + } else { + res.status(200).json({ doId, success: false }); + } + } catch (error) { + console.error("Error", error); + res.status(500).json({ error: error.message }); + } + } else { + res.status(405).json({ error: "Method not allowed" }); + } +}