Skip to content

Commit 96c8275

Browse files
susnuxcome-nc
andcommitted
feat(files_sharing): Migrate public share to use Vue files list
Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de> Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent e4fa996 commit 96c8275

File tree

15 files changed

+614
-542
lines changed

15 files changed

+614
-542
lines changed

apps/files/src/main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ window.OCA.Files = window.OCA.Files ?? {}
3030
window.OCP.Files = window.OCP.Files ?? {}
3131

3232
// Expose router
33-
const Router = new RouterService(router)
34-
Object.assign(window.OCP.Files, { Router })
33+
if (!window.OCP.Files.Router) {
34+
const Router = new RouterService(router)
35+
Object.assign(window.OCP.Files, { Router })
36+
}
3537

3638
// Init Pinia store
3739
Vue.use(PiniaVuePlugin)
@@ -48,6 +50,6 @@ Object.assign(window.OCA.Files.Settings, { Setting: SettingsModel })
4850

4951
const FilesAppVue = Vue.extend(FilesApp)
5052
new FilesAppVue({
51-
router,
53+
router: window.OCP.Files.Router.router,
5254
pinia,
5355
}).$mount('#content')

apps/files/src/services/Files.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@
55
import type { ContentsWithRoot, File, Folder } from '@nextcloud/files'
66
import type { FileStat, ResponseDataDetailed } from 'webdav'
77

8-
import { CancelablePromise } from 'cancelable-promise'
98
import { davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files'
9+
import { CancelablePromise } from 'cancelable-promise'
10+
import { join } from 'path'
1011
import { client } from './WebdavClient.ts'
1112
import logger from '../logger.ts'
1213

1314
/**
1415
* Slim wrapper over `@nextcloud/files` `davResultToNode` to allow using the function with `Array.map`
15-
* @param node The node returned by the webdav library
16+
* @param stat The result returned by the webdav library
1617
*/
17-
export const resultToNode = (node: FileStat): File | Folder => davResultToNode(node)
18+
export const resultToNode = (stat: FileStat): File | Folder => davResultToNode(stat)
1819

1920
export const getContents = (path = '/'): CancelablePromise<ContentsWithRoot> => {
21+
path = join(davRootPath, path)
2022
const controller = new AbortController()
2123
const propfindPayload = davGetDefaultPropfind()
2224

23-
path = `${davRootPath}${path}`
24-
2525
return new CancelablePromise(async (resolve, reject, onCancel) => {
2626
onCancel(() => controller.abort())
27+
2728
try {
2829
const contentsResponse = await client.getDirectoryContents(path, {
2930
details: true,

apps/files/src/services/RouterService.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ export default class RouterService {
2626
return this._router.currentRoute.params || {}
2727
}
2828

29+
/**
30+
* This is a protected getter only for internal use
31+
* @private
32+
*/
33+
get router() {
34+
return this._router
35+
}
36+
2937
/**
3038
* Trigger a route change on the files app
3139
*

apps/files/src/views/Sidebar.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ import { getCurrentUser } from '@nextcloud/auth'
9191
import { getCapabilities } from '@nextcloud/capabilities'
9292
import { showError } from '@nextcloud/dialogs'
9393
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
94-
import { File, Folder, formatFileSize } from '@nextcloud/files'
94+
import { File, Folder, davRemoteURL, davRootPath, formatFileSize } from '@nextcloud/files'
9595
import { encodePath } from '@nextcloud/paths'
96-
import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
96+
import { generateUrl } from '@nextcloud/router'
9797
import { ShareType } from '@nextcloud/sharing'
9898
import { mdiStar, mdiStarOutline } from '@mdi/js'
9999
import axios from '@nextcloud/axios'
@@ -187,8 +187,7 @@ export default {
187187
* @return {string}
188188
*/
189189
davPath() {
190-
const user = this.currentUser.uid
191-
return generateRemoteUrl(`dav/files/${user}${encodePath(this.file)}`)
190+
return `${davRemoteURL}/${davRootPath}${encodePath(this.file)}`
192191
},
193192
194193
/**

0 commit comments

Comments
 (0)