From 0c1886a91e0174e69111109ff351d9a35b2c0cb6 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Tue, 17 Dec 2024 14:15:14 -0800 Subject: [PATCH] Get upload working, optimize walk --- api/projects.ts | 13 +++++++++++-- lib/fs.ts | 15 +++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/api/projects.ts b/api/projects.ts index 4923cee..b39e1ef 100644 --- a/api/projects.ts +++ b/api/projects.ts @@ -48,7 +48,7 @@ export function createProject( }); } -export function uploadProject( +export async function uploadProject( accountId: number, projectName: string, projectFile: string, @@ -66,12 +66,21 @@ export function uploadProject( }), }; - return http.post(accountId, { + const response = await http.post<{ + buildId: number; + createdBuildId: number; + }>(accountId, { url: `project-components-external/v3/upload/new-api`, timeout: 60_000, data: formData, headers: { 'Content-Type': 'multipart/form-data' }, }); + + // Remap the response to match the expected shape + response.data.buildId = response.data.createdBuildId; + + // @ts-expect-error Fix me later + return response; } const formData: FormData = { diff --git a/lib/fs.ts b/lib/fs.ts index 56a7bc0..3291f3c 100644 --- a/lib/fs.ts +++ b/lib/fs.ts @@ -42,12 +42,13 @@ export function flattenAndRemoveSymlinks( const generateRecursiveFilePromise = async ( dir: string, - file: string + file: string, + ignoreDirs?: string[] ): Promise => { return getFileInfoAsync(dir, file).then(fileData => { return new Promise(resolve => { if (fileData.type === STAT_TYPES.DIRECTORY) { - walk(fileData.filepath).then(files => { + walk(fileData.filepath, ignoreDirs).then(files => { resolve({ ...fileData, files }); }); } else { @@ -57,10 +58,16 @@ const generateRecursiveFilePromise = async ( }); }; -export async function walk(dir: string): Promise> { +export async function walk( + dir: string, + ignoreDirs?: string[] +): Promise> { function processFiles(files: Array) { + if (ignoreDirs?.some(ignored => dir.includes(ignored))) { + return []; + } return Promise.all( - files.map(file => generateRecursiveFilePromise(dir, file)) + files.map(file => generateRecursiveFilePromise(dir, file, ignoreDirs)) ); }