Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(renterd): first file download no bucket error #853

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/late-points-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': patch
---

Fixed an issue where the first attempt to download a file would show a bucket not found error.
23 changes: 23 additions & 0 deletions apps/renterd-e2e/src/specs/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@ test('can upload, rename, and delete files', async ({ page }) => {
await deleteBucket(page, bucketName)
})

test('can upload and download a file', async ({ page }) => {
const bucketName = 'files-test'
const fileName = 'sample.txt'
const filePath = `${bucketName}/${fileName}`

// Create bucket.
await navigateToBuckets({ page })
await createBucket(page, bucketName)
await openBucket(page, bucketName)

// Upload.
await dragAndDropFileFromSystem(page, fileName)
await expect(page.getByText('100%')).toBeVisible()
await fileInList(page, filePath)

// Download.
await openFileContextMenu(page, filePath)
await page.getByRole('menuitem', { name: 'Download file' }).click()
await expect(
page.getByRole('button', { name: 'Active downloads' })
).toBeVisible()
})

test('can rename and delete a directory with contents', async ({ page }) => {
test.setTimeout(120_000)
const bucketName = 'files-test'
Expand Down
1 change: 1 addition & 0 deletions apps/renterd/contexts/config/transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ describe('tansforms', () => {
function buildAllResponses() {
return {
autopilotState: {
enabled: true,
migrating: true,
migratingLastStart: new Date().toISOString(),
scanning: true,
Expand Down
118 changes: 64 additions & 54 deletions apps/renterd/contexts/filesManager/downloads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,68 +85,78 @@ export function useDownloads() {
download.controller.abort()
}, [])

const downloadFiles = async (files: FullPath[]) => {
files.forEach(async (path) => {
let isDone = false
const bucketName = getBucketFromPath(path)
const key = getKeyFromPath(path)
const bucket = buckets.data?.find((b) => b.name === bucketName)
if (!bucket) {
triggerErrorToast({ title: 'Bucket not found', body: bucketName })
return
}
const name = getFilename(path)

if (downloadsMap[path]) {
triggerErrorToast({ title: 'Already downloading file', body: path })
return
}
const downloadFiles = useCallback(
async (files: FullPath[]) => {
files.forEach(async (path) => {
let isDone = false
const bucketName = getBucketFromPath(path)
const key = getKeyFromPath(path)
const bucket = buckets.data?.find((b) => b.name === bucketName)
if (!bucket) {
triggerErrorToast({ title: 'Bucket not found', body: bucketName })
return
}
const name = getFilename(path)

const controller = new AbortController()
const onDownloadProgress = throttle((e) => {
if (isDone) {
if (downloadsMap[path]) {
triggerErrorToast({ title: 'Already downloading file', body: path })
return
}
updateDownloadProgress({

const controller = new AbortController()
const onDownloadProgress = throttle((e) => {
if (isDone) {
return
}
updateDownloadProgress({
path,
loaded: e.loaded,
size: e.total,
})
}, 2000)
initDownloadProgress({
path,
loaded: e.loaded,
size: e.total,
key,
name,
bucket,
loaded: 0,
size: 1,
controller,
})
}, 2000)
initDownloadProgress({
path,
key,
name,
bucket,
loaded: 0,
size: 1,
controller,
})
const response = await download.get(name, {
params: bucketAndKeyParamsFromPath(path),
config: {
axios: {
onDownloadProgress,
signal: controller.signal,
const response = await download.get(name, {
params: bucketAndKeyParamsFromPath(path),
config: {
axios: {
onDownloadProgress,
signal: controller.signal,
},
},
},
})
isDone = true
if (response.error) {
if (response.error === 'canceled') {
triggerToast({ title: 'File download canceled' })
})
isDone = true
if (response.error) {
if (response.error === 'canceled') {
triggerToast({ title: 'File download canceled' })
} else {
triggerErrorToast({
title: 'Error downloading file',
body: response.error,
})
}
removeDownload(path)
} else {
triggerErrorToast({
title: 'Error downloading file',
body: response.error,
})
removeDownload(path)
}
removeDownload(path)
} else {
removeDownload(path)
}
})
}
})
},
[
buckets.data,
download,
downloadsMap,
initDownloadProgress,
removeDownload,
updateDownloadProgress,
]
)

const downloadsList = useMemo(
() => Object.entries(downloadsMap).map((d) => d[1]),
Expand Down
Loading