Skip to content

Commit

Permalink
feat: renterd multipart upload manager
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Feb 23, 2024
1 parent 3d93dc6 commit dfbd336
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 102 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-garlics-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

File uploads now use multipart uploads.
5 changes: 5 additions & 0 deletions .changeset/pretty-roses-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

File uploads now have a max concurrency and get queued.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function FilesHealthColumnContents({
const slabs = sortBy(
obj.data.object.slabs.map((s) => ({
...s.slab,
key: `${s.offset}${s.length}${s.slab.key}`,
isPartialSlab: !!s.slab.shards,
contractSetShards: s.slab.shards?.length
? computeSlabContractSetShards({
Expand Down
10 changes: 5 additions & 5 deletions apps/renterd/components/TransfersBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import {
import { useState } from 'react'
import { useFilesManager } from '../contexts/filesManager'
import { useAppSettings } from '@siafoundation/react-core'
import { upperFirst } from '@technically/lodash'

function getProgress(transfer: { loaded?: number; size?: number }) {
return transfer.loaded !== undefined ? transfer.loaded / transfer.size : 1
}

export function TransfersBar() {
const { isUnlockedAndAuthedRoute } = useAppSettings()
const { uploadsList, uploadCancel, downloadsList, downloadCancel } =
useFilesManager()
const { uploadsList, downloadsList, downloadCancel } = useFilesManager()
const [maximized, setMaximized] = useState<boolean>(true)

const uploadCount = uploadsList.length
Expand Down Expand Up @@ -56,7 +56,7 @@ export function TransfersBar() {
const progress = getProgress(upload)
return (
<div
key={upload.path}
key={upload.id}
className="flex flex-col gap-1 border-t first:border-t-0 border-gray-200 dark:border-graydark-300 px-3 py-2"
>
<div className="flex gap-1">
Expand All @@ -67,7 +67,7 @@ export function TransfersBar() {
tip="Cancel file upload"
variant="ghost"
size="none"
onClick={() => uploadCancel(upload)}
onClick={() => upload.uploadAbort?.()}
>
<Close16 />
</Button>
Expand All @@ -80,7 +80,7 @@ export function TransfersBar() {
/>
<div className="flex justify-between mt-1">
<Text size="12" color="subtle">
{progress === 1 ? 'Processing' : 'Uploading'}
{upperFirst(upload.uploadStatus)}
</Text>
<Text size="12" color="subtle">
{(progress * 100).toFixed(0)}%
Expand Down
3 changes: 1 addition & 2 deletions apps/renterd/contexts/filesManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function useFilesManagerMain() {
[router, activeDirectory]
)

const { uploadFiles, uploadsList, uploadCancel } = useUploads({
const { uploadFiles, uploadsList } = useUploads({
activeDirectoryPath,
})
const { downloadFiles, downloadsList, getFileUrl, downloadCancel } =
Expand Down Expand Up @@ -174,7 +174,6 @@ function useFilesManagerMain() {
navigateToModeSpecificFiltering,
uploadFiles,
uploadsList,
uploadCancel,
downloadFiles,
downloadsList,
downloadCancel,
Expand Down
16 changes: 16 additions & 0 deletions apps/renterd/contexts/filesManager/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Bucket } from '@siafoundation/react-renterd'
import { FullPath } from '../../lib/paths'
import { TableColumn } from '@siafoundation/design-system'
import { MultipartUpload } from '../../lib/multipartUpload'

export type ObjectType = 'bucket' | 'directory' | 'file'

Expand Down Expand Up @@ -78,3 +79,18 @@ export const sortOptions: { id: SortField; label: string; category: string }[] =
]

export type ExplorerMode = 'directory' | 'flat'

export type UploadStatus = 'queued' | 'uploading' | 'processing'

export type ObjectUploadData = ObjectData & {
upload: MultipartUpload
uploadStatus: UploadStatus
uploadAbort?: () => Promise<void>
uploadFile?: File
}

export type ObjectUploadRemoteData = ObjectData & {
remote: true
}

export type UploadsMap = Record<string, ObjectUploadData>
Loading

0 comments on commit dfbd336

Please sign in to comment.