From f5133e467e2f5510f0a4033b031ed238c82f4ef2 Mon Sep 17 00:00:00 2001 From: kartikvirendrar Date: Thu, 19 Dec 2024 17:50:50 +0530 Subject: [PATCH 1/2] changes for export filename --- src/config/config.js | 4 +-- src/utils/subtitleUtils.js | 59 +++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/config/config.js b/src/config/config.js index 8e5eae50..9f3a0d0e 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -2,9 +2,9 @@ const configs = { BASE_URL: "https://backend.chitralekha.ai4bharat.org/", BASE_URL_AUTO: process.env.REACT_APP_APIGW_BASE_URL ? process.env.REACT_APP_APIGW_BASE_URL - : "https://backend.dev.chitralekha.ai4bharat.org" + // : "https://backend.dev.chitralekha.ai4bharat.org" // : "https://backend.chitralekha.ai4bharat.org" - // : "http://127.0.0.1:8000", + : "http://127.0.0.1:8000", }; export default configs; diff --git a/src/utils/subtitleUtils.js b/src/utils/subtitleUtils.js index b434e1e6..bc9f50b2 100644 --- a/src/utils/subtitleUtils.js +++ b/src/utils/subtitleUtils.js @@ -5,6 +5,7 @@ import store from "../redux/store/store"; import { noiseTags } from "config"; import { specialOrgIds } from "config"; import getLocalStorageData from "./getLocalStorageData"; +import { FetchVideoDetailsAPI } from "redux/actions"; export const newSub = (item) => { return new Sub(item); @@ -677,42 +678,76 @@ export const paraphrase = (index) => { return copySub; }; -export const exportVoiceover = (data, taskDetails, exportTypes) => { +export const exportVoiceover = async (data, taskDetails, exportTypes) => { const userOrgId = getLocalStorageData("userData").organization.id; - const { video_name: videoName, target_language: targetLanguage } = + const { video_name: videoName, target_language: targetLanguage, project, video_url, src_language } = taskDetails; + const apiObj = new FetchVideoDetailsAPI( + video_url, + src_language, + project + ); + const res = await fetch(apiObj.apiEndPoint(), { + method: "GET", + headers: apiObj.getHeaders().headers, + }); + const video = await res.json(); + console.log(video); + const { voiceover } = exportTypes; if (data.azure_url) { - const link = document.createElement("a"); - link.href = data.azure_url; - let fileName = ""; if (specialOrgIds.includes(userOrgId)) { fileName = data.video_name + } else if (video?.video?.description?.length){ + fileName = `${video.video.description}.${voiceover}`; } else { fileName = `Chitralekha_Video_${videoName}_${getDateTime()}_${targetLanguage}.${voiceover}`; } - link.setAttribute("download", fileName); + fetch(data.azure_url) + .then(response => response.blob()) + .then(blob => { + const url = URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.setAttribute("download", fileName); + + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); - document.body.appendChild(link); - link.click(); - link.parentNode.removeChild(link); + URL.revokeObjectURL(url); + }) + .catch(error => console.error("Error downloading file:", error)); } }; -export const exportFile = (data, taskDetails, exportType, type) => { +export const exportFile = async (data, taskDetails, exportType, type) => { const { video: videoId, src_language: sourceLanguage, target_language: targetLanguage, - description, + description, + project, + video_url } = taskDetails; const userOrgId = getLocalStorageData("userData").organization.id; + const apiObj = new FetchVideoDetailsAPI( + video_url, + sourceLanguage, + project + ); + const res = await fetch(apiObj.apiEndPoint(), { + method: "GET", + headers: apiObj.getHeaders().headers, + }); + const video = await res.json(); + let newBlob; if (exportType === "docx") { newBlob = new Blob([data], { @@ -740,6 +775,8 @@ export const exportFile = (data, taskDetails, exportType, type) => { let fileName = ""; if (specialOrgIds.includes(userOrgId) && description.length) { fileName = `${description}.${format}`; + } else if(video?.video?.description?.length){ + fileName = `${video.video.description}.${format}`; } else { fileName = `Chitralekha_Video${videoId}_${YYYYMMDD}_${HHMMSS}_${language}.${format}`; } From 4cb8f43f1a9d1d3f0e22dd3c93953b91b386924b Mon Sep 17 00:00:00 2001 From: kartikvirendrar Date: Thu, 19 Dec 2024 17:51:47 +0530 Subject: [PATCH 2/2] changes for export filename --- src/config/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/config.js b/src/config/config.js index 9f3a0d0e..8e5eae50 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -2,9 +2,9 @@ const configs = { BASE_URL: "https://backend.chitralekha.ai4bharat.org/", BASE_URL_AUTO: process.env.REACT_APP_APIGW_BASE_URL ? process.env.REACT_APP_APIGW_BASE_URL - // : "https://backend.dev.chitralekha.ai4bharat.org" + : "https://backend.dev.chitralekha.ai4bharat.org" // : "https://backend.chitralekha.ai4bharat.org" - : "http://127.0.0.1:8000", + // : "http://127.0.0.1:8000", }; export default configs;