Skip to content

Commit

Permalink
ui: design of useMultipartDownloadUpload
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengYanJin committed Jul 10, 2024
1 parent c8fd97e commit 0275190
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions ui/src/hooks/downloadUploadArtefacts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
type UploadChunk = {
rangeStartIndex: number;
rangeEndIndex: number;
rangeSize: number;
};

type IncompleteArtifacts = {
version: string;
path: string;
sha256sum: string;
size: number;
uploadedChunks: UploadChunk[];
};

type VersionDescription = {
v1: {
version: string;
artifacts: {
[component: string]: {
version: string;
path: string;
sha256sum: string;
size: number;
};
};
};
};

type UploadSessionStatus =
| {
status: 'incomplete';
missingOrImcompleteArtifacts: {
[component: string]: IncompleteArtifacts;
};
}
| { status: 'complete' };

type UseMultipartDownloadUploadOptions = {
packagesClient: PackagesClient;
artifactsClient: ArtifactsClient;
versionClient: VersionClient;
};

type PackagesClient = {
// packages.scality.com
// init with Scality packages credentials
downloadChunk: ({
artescaVersion,
rangeStartIndex,
rangeEndIndex,
component,
}: {
artescaVersion: string;
rangeStartIndex: number;
rangeEndIndex: number;
component: string;
}) => Promise<Blob>; //GET
};

type VersionClient = {
getVersionDescription: (
artescaVersion: string,
) => Promise<VersionDescription>; //GET
};

type ArtifactsClient = {
//MetalK8s backend API
initUploadSession: (
versionDescription: VersionDescription,
) => Promise<UploadSessionStatus>; //POST
getUploadSession: () => Promise<UploadSessionStatus>; //GET
uploadChunk: ({
component,
version,
sha256sum,
uploadChunk,
chunk,
}: {
component: string;
version: string;
sha256sum: string;
uploadChunk: UploadChunk;
chunk: Blob;
}) => Promise<IncompleteArtifacts & { isCompleted: boolean }>; //POST
abortUploadSession: () => Promise<void>; //DELETE
};

type MultipartDownloadUpload =
| {
status: 'idle';
start: () => {}; //call getVersionDescription()
}
| {
status: 'ongoing';
currentComponent: string; // the current component being downloaded / uploaded
percentage: number;
remainingTime: number;
uploadSpeedAvg: number;
downloadSpeedAvg: number;
pause: () => {};
abort: () => {};
}
| {
status: 'completed';
abort: () => {};
}
| {
status: 'error';
error: Error;
retry: () => {};
abort: () => {};
}
| {
status: 'paused';
currentComponent: string;
percentage: number;
resume: () => {};
abort: () => {};
}
| {
status: 'aborted';
};

function useMultipartDownloadUpload(
options: UseMultipartDownloadUploadOptions,
): MultipartDownloadUpload {
return;
}

0 comments on commit 0275190

Please sign in to comment.