-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
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
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,25 @@ | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
/** | ||
* @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/>. | ||
* | ||
*/ |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
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 | ||
} | ||
} |