Skip to content

Commit a4690a8

Browse files
committed
fix(renterd): first file download no bucket error
1 parent 0f8b3ab commit a4690a8

File tree

4 files changed

+93
-54
lines changed

4 files changed

+93
-54
lines changed

.changeset/late-points-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'renterd': patch
3+
---
4+
5+
Fixed an issue where the first attempt to download a file would show a bucket not found error.

apps/renterd-e2e/src/specs/files.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ test('can upload, rename, and delete files', async ({ page }) => {
111111
await deleteBucket(page, bucketName)
112112
})
113113

114+
test('can upload and download a file', async ({ page }) => {
115+
const bucketName = 'files-test'
116+
const fileName = 'sample.txt'
117+
const filePath = `${bucketName}/${fileName}`
118+
119+
// Create bucket.
120+
await navigateToBuckets({ page })
121+
await createBucket(page, bucketName)
122+
await openBucket(page, bucketName)
123+
124+
// Upload.
125+
await dragAndDropFileFromSystem(page, fileName)
126+
await expect(page.getByText('100%')).toBeVisible()
127+
await fileInList(page, filePath)
128+
129+
// Download.
130+
await openFileContextMenu(page, filePath)
131+
await page.getByRole('menuitem', { name: 'Download file' }).click()
132+
await expect(
133+
page.getByRole('button', { name: 'Active downloads' })
134+
).toBeVisible()
135+
})
136+
114137
test('can rename and delete a directory with contents', async ({ page }) => {
115138
test.setTimeout(120_000)
116139
const bucketName = 'files-test'

apps/renterd/contexts/config/transform.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ describe('tansforms', () => {
464464
function buildAllResponses() {
465465
return {
466466
autopilotState: {
467+
enabled: true,
467468
migrating: true,
468469
migratingLastStart: new Date().toISOString(),
469470
scanning: true,

apps/renterd/contexts/filesManager/downloads.tsx

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -85,68 +85,78 @@ export function useDownloads() {
8585
download.controller.abort()
8686
}, [])
8787

88-
const downloadFiles = async (files: FullPath[]) => {
89-
files.forEach(async (path) => {
90-
let isDone = false
91-
const bucketName = getBucketFromPath(path)
92-
const key = getKeyFromPath(path)
93-
const bucket = buckets.data?.find((b) => b.name === bucketName)
94-
if (!bucket) {
95-
triggerErrorToast({ title: 'Bucket not found', body: bucketName })
96-
return
97-
}
98-
const name = getFilename(path)
99-
100-
if (downloadsMap[path]) {
101-
triggerErrorToast({ title: 'Already downloading file', body: path })
102-
return
103-
}
88+
const downloadFiles = useCallback(
89+
async (files: FullPath[]) => {
90+
files.forEach(async (path) => {
91+
let isDone = false
92+
const bucketName = getBucketFromPath(path)
93+
const key = getKeyFromPath(path)
94+
const bucket = buckets.data?.find((b) => b.name === bucketName)
95+
if (!bucket) {
96+
triggerErrorToast({ title: 'Bucket not found', body: bucketName })
97+
return
98+
}
99+
const name = getFilename(path)
104100

105-
const controller = new AbortController()
106-
const onDownloadProgress = throttle((e) => {
107-
if (isDone) {
101+
if (downloadsMap[path]) {
102+
triggerErrorToast({ title: 'Already downloading file', body: path })
108103
return
109104
}
110-
updateDownloadProgress({
105+
106+
const controller = new AbortController()
107+
const onDownloadProgress = throttle((e) => {
108+
if (isDone) {
109+
return
110+
}
111+
updateDownloadProgress({
112+
path,
113+
loaded: e.loaded,
114+
size: e.total,
115+
})
116+
}, 2000)
117+
initDownloadProgress({
111118
path,
112-
loaded: e.loaded,
113-
size: e.total,
119+
key,
120+
name,
121+
bucket,
122+
loaded: 0,
123+
size: 1,
124+
controller,
114125
})
115-
}, 2000)
116-
initDownloadProgress({
117-
path,
118-
key,
119-
name,
120-
bucket,
121-
loaded: 0,
122-
size: 1,
123-
controller,
124-
})
125-
const response = await download.get(name, {
126-
params: bucketAndKeyParamsFromPath(path),
127-
config: {
128-
axios: {
129-
onDownloadProgress,
130-
signal: controller.signal,
126+
const response = await download.get(name, {
127+
params: bucketAndKeyParamsFromPath(path),
128+
config: {
129+
axios: {
130+
onDownloadProgress,
131+
signal: controller.signal,
132+
},
131133
},
132-
},
133-
})
134-
isDone = true
135-
if (response.error) {
136-
if (response.error === 'canceled') {
137-
triggerToast({ title: 'File download canceled' })
134+
})
135+
isDone = true
136+
if (response.error) {
137+
if (response.error === 'canceled') {
138+
triggerToast({ title: 'File download canceled' })
139+
} else {
140+
triggerErrorToast({
141+
title: 'Error downloading file',
142+
body: response.error,
143+
})
144+
}
145+
removeDownload(path)
138146
} else {
139-
triggerErrorToast({
140-
title: 'Error downloading file',
141-
body: response.error,
142-
})
147+
removeDownload(path)
143148
}
144-
removeDownload(path)
145-
} else {
146-
removeDownload(path)
147-
}
148-
})
149-
}
149+
})
150+
},
151+
[
152+
buckets.data,
153+
download,
154+
downloadsMap,
155+
initDownloadProgress,
156+
removeDownload,
157+
updateDownloadProgress,
158+
]
159+
)
150160

151161
const downloadsList = useMemo(
152162
() => Object.entries(downloadsMap).map((d) => d[1]),

0 commit comments

Comments
 (0)