fix: account.redirection without final slash led to problems creating folders #144

Massimo Melina committed Mar 11, 2023 at 19:10 UTC a6cf3e85264d591a2b34a4d7b1415e8575a9cb2d
1 file changed +10 -6
frontend/src/useFetchList.ts
+10 -6
@@ -10,6 +10,7 @@ import { useIsMounted } from 'usehooks-ts'
10 import { alertDialog } from './dialog'
11 import { ERRORS } from './misc'
12 import { t } from './i18n'
13 +import { useNavigate } from 'react-router-dom'
14
15 const API = 'file_list'
16
@@ -20,6 +21,7 @@ export default function useFetchList() {
21 const lastPath = useRef('')
22 const lastReq = useRef<any>()
23 const isMounted = useIsMounted()
24 + const navigate = useNavigate()
25 useEffect(()=>{
26 if (snap.loginRequired) return
27 const previous = lastPath.current
@@ -69,12 +71,6 @@ export default function useFetchList() {
71 return
72 case 'msg':
73 data.forEach(async (entry: any) => {
72 - if (entry.props)
73 - return Object.assign(state, _.pick(entry.props, ['can_upload', 'can_delete']))
74 - state.can_upload ??= false
75 - state.can_delete ??= false
76 - if (entry.add)
77 - return buffer.push(entry.add)
74 const { error } = entry
75 if (error === 405) { // "method not allowed" happens when we try to directly access an unauthorized file, and we get a login prompt, and then file_list the file (because we didn't know it was file or folder)
76 state.messageOnly = t('upload_starting', "Your download should now start")
@@ -90,6 +86,14 @@ export default function useFetchList() {
86 lastReq.current = null
87 return
88 }
89 + if (!desiredPath.endsWith('/')) // now we know it was a folder for sure
90 + return navigate(desiredPath + '/')
91 + if (entry.props)
92 + return Object.assign(state, _.pick(entry.props, ['can_upload', 'can_delete']))
93 + state.can_upload ??= false
94 + state.can_delete ??= false
95 + if (entry.add)
96 + return buffer.push(entry.add)
97 })
98 if (src?.readyState === src?.CLOSED)
99 return state.stopSearch?.()