-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: renterd multipart remote uploads
- Loading branch information
1 parent
68c9623
commit 9b328a9
Showing
5 changed files
with
148 additions
and
11 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,5 @@ | ||
--- | ||
'renterd': minor | ||
--- | ||
|
||
Transfers now list remote uploads originating from other devices. |
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,5 @@ | ||
--- | ||
'renterd': minor | ||
--- | ||
|
||
Remote file uploads can now be aborted from the transfer list. |
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
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
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,66 @@ | ||
import { | ||
Bucket, | ||
useMultipartUploadAbort, | ||
useMultipartUploadListUploads, | ||
} from '@siafoundation/react-renterd' | ||
import { useMemo } from 'react' | ||
import { ObjectUploadData, ObjectUploadRemoteData, UploadsMap } from './types' | ||
import { getFilename, join } from '../../lib/paths' | ||
|
||
type Props = { | ||
activeBucket?: Bucket | ||
uploadsMap: UploadsMap | ||
} | ||
|
||
export function useRemoteUploads({ activeBucket, uploadsMap }: Props) { | ||
const apiBusUploadAbort = useMultipartUploadAbort() | ||
const remoteUploads = useMultipartUploadListUploads({ | ||
disabled: !activeBucket, | ||
payload: { | ||
bucket: activeBucket?.name, | ||
}, | ||
}) | ||
|
||
const remoteUploadsMap = useMemo(() => { | ||
return ( | ||
remoteUploads.data?.uploads?.reduce((acc, upload) => { | ||
const id = upload.uploadID | ||
const name = getFilename(upload.path) | ||
const fullPath = join(activeBucket?.name, upload.path) | ||
return { | ||
...acc, | ||
[id]: { | ||
id, | ||
path: fullPath, | ||
bucket: activeBucket, | ||
name, | ||
size: 1, | ||
loaded: 1, | ||
isUploading: true, | ||
remote: true, | ||
type: 'file', | ||
uploadAbort: () => | ||
apiBusUploadAbort.post({ | ||
payload: { | ||
bucket: activeBucket?.name, | ||
path: upload.path, | ||
uploadID: upload.uploadID, | ||
}, | ||
}), | ||
} as ObjectUploadRemoteData, | ||
} | ||
}, {}) || {} | ||
) | ||
}, [activeBucket, remoteUploads.data, apiBusUploadAbort]) | ||
|
||
const remoteUploadsList = useMemo(() => { | ||
// remoteUploadsMap without anything in uploadsMap | ||
return Object.values(remoteUploadsMap).filter( | ||
(remoteUpload: ObjectUploadData) => !uploadsMap[remoteUpload.id] | ||
) as ObjectUploadData[] | ||
}, [remoteUploadsMap, uploadsMap]) | ||
|
||
return { | ||
remoteUploadsList, | ||
} | ||
} |