-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: design of useMultipartDownloadUpload
- Loading branch information
1 parent
c8fd97e
commit eb37b6a
Showing
1 changed file
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
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 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 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 UseMultipartDownloadUploadOptions = { | ||
packagesClient: PackagesClient; | ||
artifactsClient: ArtifactsClient; | ||
versionClient: VersionClient; | ||
}; | ||
type MultipartDownloadUpload = | ||
| { | ||
status: 'idle'; | ||
start: () => {}; | ||
} | ||
| { | ||
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; | ||
} |