-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add function to query current path of the files list
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
- Loading branch information
Showing
9 changed files
with
124 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const generateRemoteUrl = (path) => `https://localhost/${path}` |
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,77 @@ | ||
import { afterAll, describe, expect, test, vi } from 'vitest' | ||
import { readFile } from 'fs/promises' | ||
|
||
import { File, Folder, davDefaultRootUrl, davGetDefaultPropfind, davGetFavoritesReport, davRootPath, getFavoriteNodes } from '../../lib' | ||
|
||
vi.mock('@nextcloud/auth') | ||
vi.mock('@nextcloud/router') | ||
|
||
afterAll(() => { | ||
vi.resetAllMocks() | ||
}) | ||
|
||
describe('DAV functions', () => { | ||
test('root path is correct', () => { | ||
expect(davRootPath).toBe('/files/test') | ||
}) | ||
|
||
test('root url is correct', () => { | ||
expect(davDefaultRootUrl).toBe('https://localhost/dav/files/test') | ||
}) | ||
}) | ||
|
||
describe('DAV requests', () => { | ||
test('request all favorite files', async () => { | ||
const favoritesResponseJSON = JSON.parse((await readFile(new URL('../fixtures/favorites-response.json', import.meta.url))).toString()) | ||
|
||
// Mock the WebDAV client | ||
const client = { | ||
getDirectoryContents: vi.fn((path: string, options: any) => { | ||
if (options?.details) { | ||
return { | ||
data: favoritesResponseJSON, | ||
} | ||
} | ||
return favoritesResponseJSON | ||
}), | ||
} | ||
|
||
const nodes = await getFavoriteNodes(client as never) | ||
// Check client was called correctly | ||
expect(client.getDirectoryContents).toBeCalled() | ||
expect(client.getDirectoryContents.mock.lastCall?.at(0)).toBe('/') | ||
expect(client.getDirectoryContents.mock.lastCall?.at(1)?.data).toBe(davGetFavoritesReport()) | ||
expect(client.getDirectoryContents.mock.lastCall?.at(1)?.headers?.method).toBe('REPORT') | ||
// Check for correct output | ||
expect(nodes.length).toBe(2) | ||
expect(nodes[0] instanceof Folder).toBe(true) | ||
expect(nodes[0].basename).toBe('Neuer Ordner') | ||
expect(nodes[0].mtime?.getTime()).toBe(Date.parse('Mon, 24 Jul 2023 16:30:44 GMT')) | ||
expect(nodes[1] instanceof File).toBe(true) | ||
}) | ||
|
||
test('request inner favorites', async () => { | ||
const favoritesResponseJSON = JSON.parse((await readFile(new URL('../fixtures/favorites-inner-response.json', import.meta.url))).toString()) | ||
|
||
// Mock the WebDAV client | ||
const client = { | ||
getDirectoryContents: vi.fn((path: string, options: any) => { | ||
if (options?.details) { | ||
return { | ||
data: favoritesResponseJSON, | ||
} | ||
} | ||
return favoritesResponseJSON | ||
}), | ||
} | ||
|
||
const nodes = await getFavoriteNodes(client as never, '/Neuer Ordner') | ||
// Check client was called correctly | ||
expect(client.getDirectoryContents).toBeCalled() | ||
expect(client.getDirectoryContents.mock.lastCall?.at(0)).toBe('/Neuer Ordner') | ||
expect(client.getDirectoryContents.mock.lastCall?.at(1)?.data).toBe(davGetDefaultPropfind()) | ||
expect(client.getDirectoryContents.mock.lastCall?.at(1)?.headers?.method).toBe('PROPFIND') | ||
// There are no inner nodes | ||
expect(nodes.length).toBe(0) | ||
}) | ||
}) |
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 @@ | ||
[{"filename":"/Neuer Ordner","basename":"Neuer Ordner","lastmod":"Mon, 24 Jul 2023 16:30:44 GMT","size":0,"type":"directory","etag":"64bea734d3987","props":{"getetag":"\"64bea734d3987\"","getlastmodified":"Mon, 24 Jul 2023 16:30:44 GMT","quota-available-bytes":-3,"resourcetype":{"collection":""},"has-preview":false,"is-encrypted":0,"mount-type":"","share-attributes":"[]","comments-unread":0,"favorite":1,"fileid":74,"owner-display-name":"user1","owner-id":"user1","permissions":"RGDNVCK","share-types":{"share-type":3},"size":0,"share-permissions":31}}] |
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,2 @@ | ||
<?xml version="1.0"?> | ||
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns"><d:response><d:href>/remote.php/dav/files/user1/Neuer%20Ordner/</d:href><d:propstat><d:prop><d:getetag>"64bea734d3987"</d:getetag><d:getlastmodified>Mon, 24 Jul 2023 16:30:44 GMT</d:getlastmodified><d:quota-available-bytes>-3</d:quota-available-bytes><d:resourcetype><d:collection/></d:resourcetype><nc:has-preview>false</nc:has-preview><nc:is-encrypted>0</nc:is-encrypted><nc:mount-type></nc:mount-type><nc:share-attributes>[]</nc:share-attributes><oc:comments-unread>0</oc:comments-unread><oc:favorite>1</oc:favorite><oc:fileid>74</oc:fileid><oc:owner-display-name>user1</oc:owner-display-name><oc:owner-id>user1</oc:owner-id><oc:permissions>RGDNVCK</oc:permissions><oc:share-types><oc:share-type>3</oc:share-type></oc:share-types><oc:size>0</oc:size><x1:share-permissions xmlns:x1="http://open-collaboration-services.org/ns">31</x1:share-permissions></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat><d:propstat><d:prop><d:getcontentlength/><d:getcontenttype/></d:prop><d:status>HTTP/1.1 404 Not Found</d:status></d:propstat></d:response></d:multistatus> |
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 @@ | ||
[{"filename":"/Neuer Ordner","basename":"Neuer Ordner","lastmod":"Mon, 24 Jul 2023 16:30:44 GMT","size":0,"type":"directory","etag":"64bea734d3987","props":{"getetag":"\"64bea734d3987\"","getlastmodified":"Mon, 24 Jul 2023 16:30:44 GMT","quota-available-bytes":-3,"resourcetype":{"collection":""},"has-preview":false,"is-encrypted":0,"mount-type":"","share-attributes":"[]","comments-unread":0,"favorite":1,"fileid":74,"owner-display-name":"user1","owner-id":"user1","permissions":"RGDNVCK","share-types":{"share-type":3},"size":0,"share-permissions":31}},{"filename":"/New folder/Neue Textdatei.md","basename":"Neue Textdatei.md","lastmod":"Tue, 25 Jul 2023 12:29:34 GMT","size":0,"type":"file","etag":"7a27142de0a62ed27a7293dbc16e93bc","mime":"text/markdown","props":{"getcontentlength":0,"getcontenttype":"text/markdown","getetag":"\"7a27142de0a62ed27a7293dbc16e93bc\"","getlastmodified":"Tue, 25 Jul 2023 12:29:34 GMT","resourcetype":"","has-preview":false,"mount-type":"shared","share-attributes":"[{\"scope\":\"permissions\",\"key\":\"download\",\"enabled\":false}]","comments-unread":0,"favorite":1,"fileid":80,"owner-display-name":"admin","owner-id":"admin","permissions":"SRGDNVW","share-types":"","size":0,"share-permissions":19}}] |
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,2 @@ | ||
<?xml version="1.0"?> | ||
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns"><d:response><d:href>/remote.php/dav/files/user1/</d:href><d:propstat><d:prop><d:getetag>"632a3876842ffbf86f9e02df59829a56"</d:getetag><d:getlastmodified>Tue, 25 Jul 2023 12:29:34 GMT</d:getlastmodified><d:quota-available-bytes>-3</d:quota-available-bytes><d:resourcetype><d:collection/></d:resourcetype><nc:has-preview>false</nc:has-preview><nc:is-encrypted>0</nc:is-encrypted><nc:mount-type></nc:mount-type><nc:share-attributes>[]</nc:share-attributes><oc:comments-unread>0</oc:comments-unread><oc:favorite>0</oc:favorite><oc:fileid>57</oc:fileid><oc:owner-display-name>user1</oc:owner-display-name><oc:owner-id>user1</oc:owner-id><oc:permissions>RGDNVCK</oc:permissions><oc:share-types/><oc:size>171</oc:size><x1:share-permissions xmlns:x1="http://open-collaboration-services.org/ns">31</x1:share-permissions></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat><d:propstat><d:prop><d:getcontentlength/><d:getcontenttype/></d:prop><d:status>HTTP/1.1 404 Not Found</d:status></d:propstat></d:response></d:multistatus> |
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,35 @@ | ||
/** | ||
* @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com> | ||
* | ||
* @author John Molakvoæ <skjnldsv@protonmail.com> | ||
* @author Ferdinand Thiessen <opensource@fthiessen.de> | ||
* | ||
* @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/>. | ||
* | ||
*/ | ||
|
||
/** | ||
* Return the current directory of the files list, fallback to root | ||
* | ||
* @return {string} The current directory | ||
*/ | ||
export const getCurrentDirectory = () => { | ||
const currentDirInfo = window.OCA?.Files?.App?.currentFileList?.dirInfo | ||
|| { path: '/', name: '' } | ||
|
||
// Make sure we don't have double slashes | ||
return `${currentDirInfo.path}/${currentDirInfo.name}`.replace(/\/\//gi, '/') | ||
} |