summaryrefslogtreecommitdiffstats
path: root/apps/files/src
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2023-07-28 14:52:30 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-08-02 09:57:27 +0200
commit87b1719c88240d7ae230e5e6ad30c47e100701bd (patch)
treea328054f57ff87500594da226a85ed2cad106e0e /apps/files/src
parent6ec35e3799974afdfa04fe43585f613534465610 (diff)
downloadnextcloud-server-87b1719c88240d7ae230e5e6ad30c47e100701bd.tar.gz
nextcloud-server-87b1719c88240d7ae230e5e6ad30c47e100701bd.zip
feat(files): migrate recent view
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files/src')
-rw-r--r--apps/files/src/actions/openInFilesAction.spec.ts103
-rw-r--r--apps/files/src/actions/openInFilesAction.ts57
-rw-r--r--apps/files/src/components/FileEntry.vue9
-rw-r--r--apps/files/src/main.ts3
-rw-r--r--apps/files/src/services/Recent.ts148
-rw-r--r--apps/files/src/views/recent.ts47
6 files changed, 366 insertions, 1 deletions
diff --git a/apps/files/src/actions/openInFilesAction.spec.ts b/apps/files/src/actions/openInFilesAction.spec.ts
new file mode 100644
index 00000000000..302a6c45c6b
--- /dev/null
+++ b/apps/files/src/actions/openInFilesAction.spec.ts
@@ -0,0 +1,103 @@
+/**
+ * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @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 { action } from './openInFilesAction'
+import { expect } from '@jest/globals'
+import { File, Folder, Permission } from '@nextcloud/files'
+import { DefaultType, FileAction } from '../../../files/src/services/FileAction'
+import type { Navigation } from '../../../files/src/services/Navigation'
+
+const view = {
+ id: 'files',
+ name: 'Files',
+} as Navigation
+
+const recentView = {
+ id: 'recent',
+ name: 'Recent',
+} as Navigation
+
+describe('Open in files action conditions tests', () => {
+ test('Default values', () => {
+ expect(action).toBeInstanceOf(FileAction)
+ expect(action.id).toBe('open-in-files-recent')
+ expect(action.displayName([], recentView)).toBe('Open in Files')
+ expect(action.iconSvgInline([], recentView)).toBe('')
+ expect(action.default).toBe(DefaultType.HIDDEN)
+ expect(action.order).toBe(-1000)
+ expect(action.inline).toBeUndefined()
+ })
+})
+
+describe('Open in files action enabled tests', () => {
+ test('Enabled with on valid view', () => {
+ expect(action.enabled).toBeDefined()
+ expect(action.enabled!([], recentView)).toBe(true)
+ })
+
+ test('Disabled on wrong view', () => {
+ expect(action.enabled).toBeDefined()
+ expect(action.enabled!([], view)).toBe(false)
+ })
+})
+
+describe('Open in files action execute tests', () => {
+ test('Open in files', async () => {
+ const goToRouteMock = jest.fn()
+ window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } }
+
+ const file = new File({
+ id: 1,
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/foobar.txt',
+ owner: 'admin',
+ mime: 'text/plain',
+ root: '/files/admin',
+ permissions: Permission.ALL,
+ })
+
+ const exec = await action.exec(file, view, '/')
+
+ // Silent action
+ expect(exec).toBe(null)
+ expect(goToRouteMock).toBeCalledTimes(1)
+ expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { fileid: 1, dir: '/Foo', openfile: true })
+ })
+
+ test('Open in files with folder', async () => {
+ const goToRouteMock = jest.fn()
+ window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } }
+
+ const file = new Folder({
+ id: 1,
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/Bar',
+ owner: 'admin',
+ root: '/files/admin',
+ permissions: Permission.ALL,
+ })
+
+ const exec = await action.exec(file, view, '/')
+
+ // Silent action
+ expect(exec).toBe(null)
+ expect(goToRouteMock).toBeCalledTimes(1)
+ expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { fileid: 1, dir: '/Foo/Bar', openfile: true })
+ })
+})
diff --git a/apps/files/src/actions/openInFilesAction.ts b/apps/files/src/actions/openInFilesAction.ts
new file mode 100644
index 00000000000..283bfc63d50
--- /dev/null
+++ b/apps/files/src/actions/openInFilesAction.ts
@@ -0,0 +1,57 @@
+/**
+ * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @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 { translate as t } from '@nextcloud/l10n'
+import { FileType, type Node } from '@nextcloud/files'
+
+import { registerFileAction, FileAction, DefaultType } from '../../../files/src/services/FileAction'
+
+/**
+ * TODO: Move away from a redirect and handle
+ * navigation straight out of the recent view
+ */
+export const action = new FileAction({
+ id: 'open-in-files-recent',
+ displayName: () => t('files', 'Open in Files'),
+ iconSvgInline: () => '',
+
+ enabled: (nodes, view) => view.id === 'recent',
+
+ async exec(node: Node) {
+ let dir = node.dirname
+ if (node.type === FileType.Folder) {
+ dir = dir + '/' + node.basename
+ }
+
+ window.OCP.Files.Router.goToRoute(
+ null, // use default route
+ { view: 'files', fileid: node.fileid },
+ { dir, fileid: node.fileid, openfile: true },
+ )
+ return null
+ },
+
+ // Before openFolderAction
+ order: -1000,
+ default: DefaultType.HIDDEN,
+})
+
+registerFileAction(action)
diff --git a/apps/files/src/components/FileEntry.vue b/apps/files/src/components/FileEntry.vue
index 6156c64b60b..8fcf6846375 100644
--- a/apps/files/src/components/FileEntry.vue
+++ b/apps/files/src/components/FileEntry.vue
@@ -159,6 +159,7 @@ import { formatFileSize, Permission } from '@nextcloud/files'
import { Fragment } from 'vue-frag'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate } from '@nextcloud/l10n'
+import { generateUrl } from '@nextcloud/router'
import { vOnClickOutside } from '@vueuse/components'
import axios from '@nextcloud/axios'
import CancelablePromise from 'cancelable-promise'
@@ -367,10 +368,16 @@ export default Vue.extend({
},
previewUrl() {
try {
- const url = new URL(window.location.origin + this.source.attributes.previewUrl)
+ const previewUrl = this.source.attributes.previewUrl
+ || generateUrl('/core/preview?fileId={fileid}', {
+ fileid: this.source.fileid,
+ })
+ const url = new URL(window.location.origin + previewUrl)
+
// Request tiny previews
url.searchParams.set('x', '32')
url.searchParams.set('y', '32')
+
// Handle cropping
url.searchParams.set('a', this.cropPreviews === true ? '0' : '1')
return url.href
diff --git a/apps/files/src/main.ts b/apps/files/src/main.ts
index 2c0fa532570..9317f437368 100644
--- a/apps/files/src/main.ts
+++ b/apps/files/src/main.ts
@@ -6,6 +6,7 @@ import './actions/downloadAction'
import './actions/editLocallyAction'
import './actions/favoriteAction'
import './actions/openFolderAction'
+import './actions/openInFilesAction.js'
import './actions/renameAction'
import './actions/sidebarAction'
import './actions/viewInFolderAction'
@@ -18,6 +19,7 @@ import NavigationService from './services/Navigation'
import NavigationView from './views/Navigation.vue'
import processLegacyFilesViews from './legacy/navigationMapper.js'
import registerFavoritesView from './views/favorites'
+import registerRecentView from './views/recent'
import registerPreviewServiceWorker from './services/ServiceWorker.js'
import router from './router/router.js'
import RouterService from './services/RouterService'
@@ -78,6 +80,7 @@ FilesList.$mount('#app-content-vue')
// Init legacy and new files views
processLegacyFilesViews()
registerFavoritesView()
+registerRecentView()
// Register preview service worker
registerPreviewServiceWorker()
diff --git a/apps/files/src/services/Recent.ts b/apps/files/src/services/Recent.ts
new file mode 100644
index 00000000000..d6468d6a60e
--- /dev/null
+++ b/apps/files/src/services/Recent.ts
@@ -0,0 +1,148 @@
+/**
+ * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @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 { File, Folder, Permission, parseWebdavPermissions } from '@nextcloud/files'
+import { generateRemoteUrl } from '@nextcloud/router'
+import { getClient, rootPath } from './WebdavClient'
+import { getCurrentUser } from '@nextcloud/auth'
+import { getDavNameSpaces, getDavProperties } from './DavProperties'
+import type { ContentsWithRoot } from './Navigation'
+import type { FileStat, ResponseDataDetailed, DAVResultResponseProps } from 'webdav'
+
+const client = getClient(generateRemoteUrl('dav'))
+
+const lastTwoWeeksTimestamp = Math.round((Date.now() / 1000) - (60 * 60 * 24 * 14))
+const searchPayload = `<?xml version="1.0" encoding="UTF-8"?>
+<d:searchrequest ${getDavNameSpaces()}
+ xmlns:ns="https://github.com/icewind1991/SearchDAV/ns">
+ <d:basicsearch>
+ <d:select>
+ <d:prop>
+ ${getDavProperties()}
+ </d:prop>
+ </d:select>
+ <d:from>
+ <d:scope>
+ <d:href>/files/${getCurrentUser()?.uid}/</d:href>
+ <d:depth>infinity</d:depth>
+ </d:scope>
+ </d:from>
+ <d:where>
+ <d:and>
+ <d:or>
+ <d:not>
+ <d:eq>
+ <d:prop>
+ <d:getcontenttype/>
+ </d:prop>
+ <d:literal>httpd/unix-directory</d:literal>
+ </d:eq>
+ </d:not>
+ <d:eq>
+ <d:prop>
+ <oc:size/>
+ </d:prop>
+ <d:literal>0</d:literal>
+ </d:eq>
+ </d:or>
+ <d:gt>
+ <d:prop>
+ <d:getlastmodified/>
+ </d:prop>
+ <d:literal>${lastTwoWeeksTimestamp}</d:literal>
+ </d:gt>
+ </d:and>
+ </d:where>
+ <d:orderby>
+ <d:order>
+ <d:prop>
+ <d:getlastmodified/>
+ </d:prop>
+ <d:descending/>
+ </d:order>
+ </d:orderby>
+ <d:limit>
+ <d:nresults>100</d:nresults>
+ <ns:firstresult>0</ns:firstresult>
+ </d:limit>
+ </d:basicsearch>
+</d:searchrequest>`
+
+interface ResponseProps extends DAVResultResponseProps {
+ permissions: string,
+ fileid: number,
+ size: number,
+}
+
+const resultToNode = function(node: FileStat): File | Folder {
+ const props = node.props as ResponseProps
+ const permissions = parseWebdavPermissions(props?.permissions)
+ const owner = getCurrentUser()?.uid as string
+
+ const nodeData = {
+ id: props?.fileid as number || 0,
+ source: generateRemoteUrl('dav' + node.filename),
+ mtime: new Date(node.lastmod),
+ mime: node.mime as string,
+ size: props?.size as number || 0,
+ permissions,
+ owner,
+ root: rootPath,
+ attributes: {
+ ...node,
+ ...props,
+ hasPreview: props?.['has-preview'],
+ },
+ }
+
+ delete nodeData.attributes.props
+
+ return node.type === 'file'
+ ? new File(nodeData)
+ : new Folder(nodeData)
+}
+
+export const getContents = async (path = '/'): Promise<ContentsWithRoot> => {
+ const contentsResponse = await client.getDirectoryContents(path, {
+ details: true,
+ data: searchPayload,
+ headers: {
+ // Patched in WebdavClient.ts
+ method: 'SEARCH',
+ // Somehow it's needed to get the correct response
+ 'Content-Type': 'application/xml; charset=utf-8',
+ },
+ deep: true,
+ }) as ResponseDataDetailed<FileStat[]>
+
+ const contents = contentsResponse.data
+
+ return {
+ folder: new Folder({
+ id: 0,
+ source: generateRemoteUrl('dav' + rootPath),
+ root: rootPath,
+ owner: getCurrentUser()?.uid || null,
+ permissions: Permission.READ,
+ }),
+ contents: contents.map(resultToNode),
+ }
+}
diff --git a/apps/files/src/views/recent.ts b/apps/files/src/views/recent.ts
new file mode 100644
index 00000000000..5a0dbd91860
--- /dev/null
+++ b/apps/files/src/views/recent.ts
@@ -0,0 +1,47 @@
+/**
+ * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @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 type NavigationService from '../services/Navigation'
+import type { Navigation } from '../services/Navigation'
+
+import { translate as t } from '@nextcloud/l10n'
+import HistorySvg from '@mdi/svg/svg/history.svg?raw'
+
+import { getContents } from '../services/Recent'
+
+export default () => {
+ const Navigation = window.OCP.Files.Navigation as NavigationService
+ Navigation.register({
+ id: 'recent',
+ name: t('files', 'Recent'),
+ caption: t('files', 'List of recently modified files and folders.'),
+
+ emptyTitle: t('files', 'No recently modified files'),
+ emptyCaption: t('files', 'Files and folders you recently modified will show up here.'),
+
+ icon: HistorySvg,
+ order: 2,
+
+ defaultSortKey: 'mtime',
+
+ getContents,
+ } as Navigation)
+}