init commit
This commit is contained in:
commit
5cd2a1b6dc
14 files changed
+1113
No files matched your search
@@ -0,0 +1,79 @@
|
||||
|
||||
import { VideoHistoryItem } from '../types';
|
||||
|
||||
const API_ENDPOINT_1="https://o2odev.app.n8n.cloud/webhook/get_video_list"
|
||||
const API_ENDPOINT_2="https://o2odev.app.n8n.cloud/webhook/upload_image_path"
|
||||
const API_ENDPOINT_3="https://o2odev.app.n8n.cloud/webhook/ado3"
|
||||
const API_ENDPOINT_4="https://o2odev.app.n8n.cloud/webhook/mysql-api"
|
||||
|
||||
export const fetchVideoHistory = async (): Promise<VideoHistoryItem[]> => {
|
||||
try {
|
||||
const response = await fetch(API_ENDPOINT_1);
|
||||
if (!response.ok) {
|
||||
console.error("Failed to fetch history");
|
||||
return [];
|
||||
}
|
||||
const data = await response.json();
|
||||
return Array.isArray(data) ? data : [];
|
||||
} catch (error) {
|
||||
console.error("Error fetching video history:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const sendImageManifest = async (manifest: { task_id: string; img_url: string }[]) => {
|
||||
const url = API_ENDPOINT_2;
|
||||
|
||||
console.log(manifest)
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(manifest)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to send image manifest: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const submitJobMetadata = async (data: any) => {
|
||||
const url = API_ENDPOINT_3;
|
||||
|
||||
console.log(data)
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to submit job metadata: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const fetchTableData = async (task_id: string, tableName: 'lyrics' | 'song' | 'creatomate_result_url') => {
|
||||
const url = API_ENDPOINT_4;
|
||||
|
||||
try {
|
||||
// Calls API 4 with ?task_id=UUID&table=TABLE_NAME
|
||||
const response = await fetch(`${url}?task_id=${task_id}&table=${tableName}`, {
|
||||
method: 'GET'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
// If 404, it likely means that step isn't done yet
|
||||
return null;
|
||||
}
|
||||
var result = await response.json()
|
||||
console.log(result[0])
|
||||
// The API seems to return an array, grab the first item if so
|
||||
return Array.isArray(result) ? result[0] : result;
|
||||
} catch (error) {
|
||||
//console.error(`Error fetching table ${tableName}:`, error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
|
||||
import { BlobServiceClient, BlockBlobClient} from '@azure/storage-blob';
|
||||
|
||||
export const uploadImagesToAzure = async (files: File[], task_idx: string): Promise<string[]> => {
|
||||
// const sasUrl = process.env.AZURE_STORAGE_SAS_URL;
|
||||
// // Default to 'castad-data' if not set, or read from env
|
||||
// const rootPath = process.env.AZURE_UPLOAD_ROOT || "castad-data";
|
||||
// const containerName = "castad-uploads"; // Ensure this matches your SAS token permissions or container
|
||||
|
||||
// if (!sasUrl) {
|
||||
// console.warn("AZURE_STORAGE_SAS_URL is missing in .env. Returning mock URLs.");
|
||||
// return files.map((_, i) => `https://mock-azure.com/${rootPath}/${task_idx}/img/${i}.jpg`);
|
||||
// }
|
||||
const AZURE_SAS_TOKEN="sv=2024-11-04&ss=bfqt&srt=sco&sp=rwdlacupiytfx&se=2027-03-12T17:32:56Z&st=2025-12-08T09:17:56Z&spr=https,http&sig=J0uF91mTBpSUVSk0O%2FG2IXmebCDRMYp1%2BNOtBVpcOKE%3D"
|
||||
const AZURE_SERVICE_PATH="https://ado2mediastoragepublic.blob.core.windows.net/"
|
||||
// // const rootPath = "https://ado2mediastoragepublic.blob.core.windows.net/ado2-media-public-access/ado2-media-original/dev-user-idx"
|
||||
// // const blobPath =
|
||||
try {
|
||||
|
||||
// const sas_url = `https://ado2mediastoragepublic.blob.core.windows.net/?sv=2024-11-04&ss=bfqt&srt=sco&sp=rwdlacupiytfx&se=2027-03-12T17:32:56Z&st=2025-12-08T09:17:56Z&spr=https,http&sig=J0uF91mTBpSUVSk0O%2FG2IXmebCDRMYp1%2BNOtBVpcOKE%3D`;
|
||||
// const blobServiceClient = new BlobServiceClient(AZURE_SERVICE_PATH,);
|
||||
// const blobContainerClient = blobServiceClient.getContainerClient("ado2-media-public-access")
|
||||
// const blockBlobClient = new BlockBlobClient
|
||||
|
||||
const uploadPromises = files.map(async (file, index) => {
|
||||
const extension = file.name.split('.').pop() || 'jpg';
|
||||
// Path format: ROOT/task_id/img/uploadNumber.extension
|
||||
|
||||
const blobName = `${AZURE_SERVICE_PATH}ado2-media-public-access/ado2-media-original/dev-user-idx/dev-task-idx/${task_idx}-img-${index}.${extension}`;
|
||||
const sasUrl = `${blobName}?${AZURE_SAS_TOKEN}`
|
||||
// // console.log(`\nBlobUrl = ${sasUrl}\n`);
|
||||
// const blockBlobClient = blobContainerClient.getBlockBlobClient(blobName);
|
||||
|
||||
// await blockBlobClient.uploadData(file, {
|
||||
// blobHTTPHeaders: { blobContentType: file.type }
|
||||
// });
|
||||
// console.log(blockBlobClient.url)
|
||||
// return blockBlobClient.url;
|
||||
// var data = new FormData()
|
||||
// data.append('file', file)
|
||||
fetch(sasUrl, {
|
||||
headers: {"Content-Type": file.type,
|
||||
"x-ms-blob-type" : "BlockBlob"},
|
||||
method: 'PUT',
|
||||
body: file // FormData 객체를 직접 body에 전달하면 Content-Type이 자동으로 설정됨 (multipart/form-data)
|
||||
})
|
||||
console.log(blobName)
|
||||
return blobName
|
||||
});
|
||||
return await Promise.all(uploadPromises);
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Azure Upload Error:", error);
|
||||
throw new Error("Failed to upload images to Azure.");
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user