Skip to content

Commit

Permalink
incorporate @mifi's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dschmidt committed Dec 13, 2024
1 parent a4797cc commit 1738194
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
20 changes: 13 additions & 7 deletions packages/@uppy/companion/src/server/provider/webdav/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class WebdavProvider extends Provider {
throw new Error('invalid public link url')
}

// dynamic import because Comanion currently uses CommonJS and webdav is shipped as ESM
// can be implemented as regular require as soon as Node 20.17 or 22 is required
// dynamic import because Companion currently uses CommonJS and webdav is shipped as ESM
// todo implement as regular require as soon as Node 20.17 or 22 is required
// or as regular import when Companion is ported to ESM
const { AuthType } = await import('webdav') // eslint-disable-line import/no-unresolved

Expand Down Expand Up @@ -84,8 +84,8 @@ class WebdavProvider extends Provider {
const { protocol } = new URL(url)
const HttpAgentClass = getProtectedHttpAgent({ protocol, allowLocalIPs: !allowLocalUrls })

// dynamic import because Comanion currently uses CommonJS and webdav is shipped as ESM
// can be implemented as regular require as soon as Node 20.17 or 22 is required
// dynamic import because Companion currently uses CommonJS and webdav is shipped as ESM
// todo implement as regular require as soon as Node 20.17 or 22 is required
// or as regular import when Companion is ported to ESM
const { createClient } = await import('webdav')
return createClient(url, {
Expand All @@ -110,12 +110,19 @@ class WebdavProvider extends Provider {
dir.forEach(item => {
const isFolder = item.type === 'directory'
const requestPath = encodeURIComponent(`${directory || ''}/${item.basename}`)

let modifiedDate
try {
modifiedDate = new Date(item.lastmod).toISOString()
} catch (e) {
// ignore invalid date from server
}

data.items.push({
isFolder,
id: requestPath,
name: item.basename,
requestPath, // TODO FIXME
modifiedDate: item.lastmod, // TODO FIXME: convert 'Tue, 04 Jul 2023 13:09:47 GMT' to ISO 8601
modifiedDate,
...(!isFolder && {
mimeType: item.mime,
size: item.size,
Expand Down Expand Up @@ -144,7 +151,6 @@ class WebdavProvider extends Provider {
throw new Error('call to thumbnail is not implemented')
}

// todo fixme implement
// eslint-disable-next-line
async size ({ id, token, providerUserSession }) {
return this.withErrorHandling('provider.webdav.size.error', async () => {
Expand Down
11 changes: 7 additions & 4 deletions packages/@uppy/webdav/src/Webdav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ class WebdavSimpleAuthProvider extends Provider {
const AuthForm = ({ loading, i18n, onAuth }) => {
const [webdavUrl, setWebdavUrl] = useState('')

const onSubmit = (event) => {
event.preventDefault()
onAuth({ webdavUrl: webdavUrl.trim() })
}
const onSubmit = useCallback(
(e) => {
e.preventDefault()
onAuth({ webdavUrl: webdavUrl.trim() })
},
[onAuth, webdavUrl],
)

return (
<form onSubmit={onSubmit}>
Expand Down

0 comments on commit 1738194

Please sign in to comment.