From 17381945b1b918e216728d066a94c03dd7b1fc69 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Fri, 13 Dec 2024 11:58:57 +0100 Subject: [PATCH] incorporate @mifi's feedback --- .../src/server/provider/webdav/index.js | 20 ++++++++++++------- packages/@uppy/webdav/src/Webdav.tsx | 11 ++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/@uppy/companion/src/server/provider/webdav/index.js b/packages/@uppy/companion/src/server/provider/webdav/index.js index a791ef5a4f..f3d4c65584 100644 --- a/packages/@uppy/companion/src/server/provider/webdav/index.js +++ b/packages/@uppy/companion/src/server/provider/webdav/index.js @@ -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 @@ -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, { @@ -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, @@ -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 () => { diff --git a/packages/@uppy/webdav/src/Webdav.tsx b/packages/@uppy/webdav/src/Webdav.tsx index 4bc90df0b4..a4d2854d21 100644 --- a/packages/@uppy/webdav/src/Webdav.tsx +++ b/packages/@uppy/webdav/src/Webdav.tsx @@ -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 (