-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR improve on the logic to display previews: 1. Append the etag of the file to the file request. This ensure that old cache will not be used if the image is updated 2. Listen to 'files:file:updated' to refetch the file's info and have the new etag 3. Distinguish onload and on error events of the small and large previews to have a finer rendering conditions. Mostly not rendering both previews if the larger one is loaded. 4. Do not delay rendering of files to make the UI snappier Signed-off-by: Louis Chemineau <[email protected]>
- Loading branch information
1 parent
d4fbd9f
commit 7f9a3c8
Showing
4 changed files
with
144 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* @copyright Copyright (c) 2023 Louis Chemineau <[email protected]> | ||
* | ||
* @author Louis Chemineau <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
import { genFileInfo } from '../utils/fileUtils.js' | ||
import defaultClient from './DavClient.js' | ||
|
||
/** | ||
* @param {string[]} extraProps - Extra properties to add to the DAV request. | ||
* @return {string} | ||
*/ | ||
function getCollectionFilesDavRequest(extraProps = []) { | ||
return `<?xml version="1.0"?> | ||
<d:propfind xmlns:d="DAV:" | ||
xmlns:oc="http://owncloud.org/ns" | ||
xmlns:nc="http://nextcloud.org/ns" | ||
xmlns:ocs="http://open-collaboration-services.org/ns"> | ||
<d:prop> | ||
<d:getcontentlength /> | ||
<d:getcontenttype /> | ||
<d:getetag /> | ||
<d:getlastmodified /> | ||
<d:resourcetype /> | ||
<nc:file-metadata-size /> | ||
<nc:has-preview /> | ||
<oc:favorite /> | ||
<oc:fileid /> | ||
<oc:permissions /> | ||
${extraProps.join('')} | ||
</d:prop> | ||
</d:propfind>` | ||
} | ||
|
||
/** | ||
* @param {string} fileName - The full file's name | ||
* @param {import('webdav').StatOptions} options - Options to forward to the webdav client. | ||
* @return {Promise<object>} | ||
*/ | ||
export async function fetchFile(fileName, options = {}) { | ||
try { | ||
const response = await defaultClient.stat(fileName, { | ||
data: getCollectionFilesDavRequest(), | ||
details: true, | ||
...options, | ||
}) | ||
|
||
return genFileInfo(response.data) | ||
} catch (error) { | ||
if (error.code === 'ERR_CANCELED') { | ||
return null | ||
} | ||
|
||
throw error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters