Skip to content

Commit

Permalink
Get upload working, optimize walk
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-yeager committed Dec 17, 2024
1 parent da1e098 commit 0c1886a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 11 additions & 2 deletions api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function createProject(
});
}

export function uploadProject(
export async function uploadProject(
accountId: number,
projectName: string,
projectFile: string,
Expand All @@ -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 = {
Expand Down
15 changes: 11 additions & 4 deletions lib/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ export function flattenAndRemoveSymlinks(

const generateRecursiveFilePromise = async (
dir: string,
file: string
file: string,
ignoreDirs?: string[]
): Promise<FileData> => {
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 {
Expand All @@ -57,10 +58,16 @@ const generateRecursiveFilePromise = async (
});
};

export async function walk(dir: string): Promise<Array<string>> {
export async function walk(
dir: string,
ignoreDirs?: string[]
): Promise<Array<string>> {
function processFiles(files: Array<string>) {
if (ignoreDirs?.some(ignored => dir.includes(ignored))) {
return [];
}
return Promise.all(
files.map(file => generateRecursiveFilePromise(dir, file))
files.map(file => generateRecursiveFilePromise(dir, file, ignoreDirs))
);
}

Expand Down

0 comments on commit 0c1886a

Please sign in to comment.