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 files hash names #390

Merged
merged 1 commit into from
Oct 16, 2023
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/gold-dogs-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

Fixed an issue where file and directory names could not contain the # symbol.
9 changes: 7 additions & 2 deletions apps/hostd/components/OnboardingBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
PendingFilled16,
Subtract24,
} from '@siafoundation/react-icons'
import { useState } from 'react'
import { useSyncStatus } from '../hooks/useSyncStatus'
import { routes } from '../config/routes'
import { useDialog } from '../contexts/dialog'
Expand All @@ -23,14 +22,20 @@ import BigNumber from 'bignumber.js'
import { humanSiacoin, toHastings } from '@siafoundation/sia-js'
import { useAppSettings } from '@siafoundation/react-core'
import { useVolumes } from '../contexts/volumes'
import useLocalStorageState from 'use-local-storage-state'

export function OnboardingBar() {
const { isUnlocked } = useAppSettings()
const { openDialog } = useDialog()
const { dataset: volumes } = useVolumes()
const settings = useSettings()
const wallet = useWallet()
const [maximized, setMaximized] = useState<boolean>(true)
const [maximized, setMaximized] = useLocalStorageState<boolean>(
'v0/hostd/onboarding/maximized',
{
defaultValue: true,
}
)
const syncStatus = useSyncStatus()

if (!isUnlocked) {
Expand Down
9 changes: 7 additions & 2 deletions apps/renterd/components/OnboardingBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
PendingFilled16,
Subtract24,
} from '@siafoundation/react-icons'
import { useState } from 'react'
import { useApp } from '../contexts/app'
import { useSyncStatus } from '../hooks/useSyncStatus'
import { routes } from '../config/routes'
Expand All @@ -24,6 +23,7 @@ import { useAutopilotConfig, useWallet } from '@siafoundation/react-renterd'
import BigNumber from 'bignumber.js'
import { humanSiacoin } from '@siafoundation/sia-js'
import { useAppSettings } from '@siafoundation/react-core'
import useLocalStorageState from 'use-local-storage-state'

export function OnboardingBar() {
const { isUnlocked } = useAppSettings()
Expand All @@ -37,7 +37,12 @@ export function OnboardingBar() {
},
},
})
const [maximized, setMaximized] = useState<boolean>(true)
const [maximized, setMaximized] = useLocalStorageState<boolean>(
'v0/renterd/onboarding/maximized',
{
defaultValue: true,
}
)

const syncStatus = useSyncStatus()
const notEnoughContracts = useNotEnoughContracts()
Expand Down
6 changes: 4 additions & 2 deletions apps/renterd/contexts/files/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function useFilesMain() {

// [bucket, key, directory]
const activeDirectory = useMemo<FullPathSegments>(
() => (router.query.path as FullPathSegments) || [],
() => (router.query.path as FullPathSegments).map(decodeURIComponent) || [],
[router.query.path]
)

Expand All @@ -42,7 +42,9 @@ function useFilesMain() {
const setActiveDirectory = useCallback(
(fn: (activeDirectory: FullPathSegments) => FullPathSegments) => {
const nextActiveDirectory = fn(activeDirectory)
router.push('/files/' + nextActiveDirectory.join('/'))
router.push(
'/files/' + nextActiveDirectory.map(encodeURIComponent).join('/')
)
},
[router, activeDirectory]
)
Expand Down
9 changes: 9 additions & 0 deletions apps/renterd/contexts/files/paths.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ describe('bucketAndKeyParamsFromPath', () => {
})
})

it('works for file with hash in path', () => {
expect(
bucketAndKeyParamsFromPath('bucket/path#/to#hash/file#hash.txt')
).toEqual({
bucket: 'bucket',
key: 'path%23/to%23hash/file%23hash.txt',
})
})

it('works for directory', () => {
expect(bucketAndKeyParamsFromPath('bucket/path/to/directory/')).toEqual({
bucket: 'bucket',
Expand Down
6 changes: 5 additions & 1 deletion apps/renterd/contexts/files/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export function bucketAndKeyParamsFromPath(path: FullPath): {
} {
return {
bucket: getBucketFromPath(path),
key: getKeyFromPath(path).slice(1),
key: getKeyFromPath(path)
.slice(1)
.split('/')
.map(encodeURIComponent)
.join('/'),
}
}

Expand Down