diff options
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/lib/Controller/ViewController.php | 1 | ||||
-rw-r--r-- | apps/files/src/actions/deleteAction.ts | 4 | ||||
-rw-r--r-- | apps/files/src/actions/downloadAction.ts | 4 | ||||
-rw-r--r-- | apps/files/src/actions/editLocallyAction.ts | 6 | ||||
-rw-r--r-- | apps/files/src/actions/favoriteAction.ts | 4 | ||||
-rw-r--r-- | apps/files/src/actions/openFolderAction.ts | 4 | ||||
-rw-r--r-- | apps/files/src/actions/openInFilesAction.ts | 6 | ||||
-rw-r--r-- | apps/files/src/actions/renameAction.ts | 4 | ||||
-rw-r--r-- | apps/files/src/actions/sidebarAction.ts | 4 | ||||
-rw-r--r-- | apps/files/src/actions/viewInFolderAction.ts | 4 | ||||
-rw-r--r-- | apps/files/src/init.ts | 59 | ||||
-rw-r--r-- | apps/files/src/main.ts | 23 | ||||
-rw-r--r-- | apps/files/src/newMenu/newFolder.ts | 4 | ||||
-rw-r--r-- | apps/files/src/services/DavProperties.ts | 130 | ||||
-rw-r--r-- | apps/files/src/services/Favorites.ts | 19 | ||||
-rw-r--r-- | apps/files/src/services/Files.ts | 7 | ||||
-rw-r--r-- | apps/files/src/services/Recent.ts | 3 |
17 files changed, 79 insertions, 207 deletions
diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 8fe7eea01a0..ca0760fd5e2 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -217,6 +217,7 @@ class ViewController extends Controller { } // Load the files we need + \OCP\Util::addInitScript('files', 'init'); \OCP\Util::addStyle('files', 'merged'); \OCP\Util::addScript('files', 'merged-index', 'files'); \OCP\Util::addScript('files', 'main'); diff --git a/apps/files/src/actions/deleteAction.ts b/apps/files/src/actions/deleteAction.ts index 04c139fe38e..18c18178cb7 100644 --- a/apps/files/src/actions/deleteAction.ts +++ b/apps/files/src/actions/deleteAction.ts @@ -20,7 +20,7 @@ * */ import { emit } from '@nextcloud/event-bus' -import { Permission, Node, View, registerFileAction, FileAction } from '@nextcloud/files' +import { Permission, Node, View, FileAction } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' import axios from '@nextcloud/axios' import TrashCanSvg from '@mdi/svg/svg/trash-can.svg?raw' @@ -62,5 +62,3 @@ export const action = new FileAction({ order: 100, }) - -registerFileAction(action) diff --git a/apps/files/src/actions/downloadAction.ts b/apps/files/src/actions/downloadAction.ts index ce9f22450e9..0b1c88fa985 100644 --- a/apps/files/src/actions/downloadAction.ts +++ b/apps/files/src/actions/downloadAction.ts @@ -20,7 +20,7 @@ * */ import { generateUrl } from '@nextcloud/router' -import { registerFileAction, FileAction, Permission, Node, FileType, View } from '@nextcloud/files' +import { FileAction, Permission, Node, FileType, View } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' import ArrowDownSvg from '@mdi/svg/svg/arrow-down.svg?raw' @@ -86,5 +86,3 @@ export const action = new FileAction({ order: 30, }) - -registerFileAction(action) diff --git a/apps/files/src/actions/editLocallyAction.ts b/apps/files/src/actions/editLocallyAction.ts index c8e6f295544..f52f8191df8 100644 --- a/apps/files/src/actions/editLocallyAction.ts +++ b/apps/files/src/actions/editLocallyAction.ts @@ -22,7 +22,7 @@ import { encodePath } from '@nextcloud/paths' import { generateOcsUrl } from '@nextcloud/router' import { getCurrentUser } from '@nextcloud/auth' -import { registerFileAction, FileAction, Permission, type Node } from '@nextcloud/files' +import { FileAction, Permission, type Node } from '@nextcloud/files' import { showError } from '@nextcloud/dialogs' import { translate as t } from '@nextcloud/l10n' import axios from '@nextcloud/axios' @@ -66,7 +66,3 @@ export const action = new FileAction({ order: 25, }) - -if (!/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) { - registerFileAction(action) -} diff --git a/apps/files/src/actions/favoriteAction.ts b/apps/files/src/actions/favoriteAction.ts index 1309539bad2..34d34039101 100644 --- a/apps/files/src/actions/favoriteAction.ts +++ b/apps/files/src/actions/favoriteAction.ts @@ -21,7 +21,7 @@ */ import { emit } from '@nextcloud/event-bus' import { generateUrl } from '@nextcloud/router' -import { Permission, type Node, View, registerFileAction, FileAction } from '@nextcloud/files' +import { Permission, type Node, View, FileAction } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' import axios from '@nextcloud/axios' import Vue from 'vue' @@ -101,5 +101,3 @@ export const action = new FileAction({ order: -50, }) - -registerFileAction(action) diff --git a/apps/files/src/actions/openFolderAction.ts b/apps/files/src/actions/openFolderAction.ts index 2694667222d..f802ea4ad6d 100644 --- a/apps/files/src/actions/openFolderAction.ts +++ b/apps/files/src/actions/openFolderAction.ts @@ -20,7 +20,7 @@ * */ import { join } from 'path' -import { Permission, Node, FileType, View, registerFileAction, FileAction, DefaultType } from '@nextcloud/files' +import { Permission, Node, FileType, View, FileAction, DefaultType } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' import FolderSvg from '@mdi/svg/svg/folder.svg?raw' @@ -66,5 +66,3 @@ export const action = new FileAction({ default: DefaultType.HIDDEN, order: -100, }) - -registerFileAction(action) diff --git a/apps/files/src/actions/openInFilesAction.ts b/apps/files/src/actions/openInFilesAction.ts index ed3b781548c..235b59046d7 100644 --- a/apps/files/src/actions/openInFilesAction.ts +++ b/apps/files/src/actions/openInFilesAction.ts @@ -20,9 +20,7 @@ * */ import { translate as t } from '@nextcloud/l10n' -import { FileType, type Node } from '@nextcloud/files' - -import { registerFileAction, FileAction, DefaultType } from '@nextcloud/files' +import { type Node, FileType, FileAction, DefaultType } from '@nextcloud/files' /** * TODO: Move away from a redirect and handle @@ -53,5 +51,3 @@ export const action = new FileAction({ order: -1000, default: DefaultType.HIDDEN, }) - -registerFileAction(action) diff --git a/apps/files/src/actions/renameAction.ts b/apps/files/src/actions/renameAction.ts index 001bedfc73a..81d6b6384b0 100644 --- a/apps/files/src/actions/renameAction.ts +++ b/apps/files/src/actions/renameAction.ts @@ -20,7 +20,7 @@ * */ import { emit } from '@nextcloud/event-bus' -import { Permission, type Node, registerFileAction, FileAction } from '@nextcloud/files' +import { Permission, type Node, FileAction } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' import PencilSvg from '@mdi/svg/svg/pencil.svg?raw' @@ -45,5 +45,3 @@ export const action = new FileAction({ order: 10, }) - -registerFileAction(action) diff --git a/apps/files/src/actions/sidebarAction.ts b/apps/files/src/actions/sidebarAction.ts index aa265d6709a..32cd8e6d433 100644 --- a/apps/files/src/actions/sidebarAction.ts +++ b/apps/files/src/actions/sidebarAction.ts @@ -19,7 +19,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -import { Permission, type Node, View, registerFileAction, FileAction, FileType } from '@nextcloud/files' +import { Permission, type Node, View, FileAction, FileType } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' import InformationSvg from '@mdi/svg/svg/information-variant.svg?raw' @@ -73,5 +73,3 @@ export const action = new FileAction({ order: -50, }) - -registerFileAction(action) diff --git a/apps/files/src/actions/viewInFolderAction.ts b/apps/files/src/actions/viewInFolderAction.ts index a5a5896df0c..c306f93b0af 100644 --- a/apps/files/src/actions/viewInFolderAction.ts +++ b/apps/files/src/actions/viewInFolderAction.ts @@ -19,7 +19,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -import { Node, FileType, Permission, View, registerFileAction, FileAction } from '@nextcloud/files' +import { Node, FileType, Permission, View, FileAction } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' import FolderMoveSvg from '@mdi/svg/svg/folder-move.svg?raw' @@ -64,5 +64,3 @@ export const action = new FileAction({ order: 80, }) - -registerFileAction(action) diff --git a/apps/files/src/init.ts b/apps/files/src/init.ts new file mode 100644 index 00000000000..64e3846979e --- /dev/null +++ b/apps/files/src/init.ts @@ -0,0 +1,59 @@ +/** + * @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 as deleteAction } from './actions/deleteAction' +import { action as downloadAction } from './actions/downloadAction' +import { action as editLocallyAction } from './actions/editLocallyAction' +import { action as favoriteAction } from './actions/favoriteAction' +import { action as openFolderAction } from './actions/openFolderAction' +import { action as openInFilesAction } from './actions/openInFilesAction' +import { action as renameAction } from './actions/renameAction' +import { action as sidebarAction } from './actions/sidebarAction' +import { action as viewInFolderAction } from './actions/viewInFolderAction' +import { entry as newFolderEntry } from './newMenu/newFolder' + +import registerFavoritesView from './views/favorites' +import registerRecentView from './views/recent' +import registerFilesView from './views/files' +import registerPreviewServiceWorker from './services/ServiceWorker.js' +import { addNewFileMenuEntry, registerFileAction } from '@nextcloud/files' + +// Register file actions +registerFileAction(deleteAction) +registerFileAction(downloadAction) +registerFileAction(editLocallyAction) +registerFileAction(favoriteAction) +registerFileAction(openFolderAction) +registerFileAction(openInFilesAction) +registerFileAction(renameAction) +registerFileAction(sidebarAction) +registerFileAction(viewInFolderAction) + +// Register new menu entry +addNewFileMenuEntry(newFolderEntry) + +// Register files views +registerFavoritesView() +registerFilesView() +registerRecentView() + +// Register preview service worker +registerPreviewServiceWorker() diff --git a/apps/files/src/main.ts b/apps/files/src/main.ts index 8bcfacf953a..38bec4ad087 100644 --- a/apps/files/src/main.ts +++ b/apps/files/src/main.ts @@ -1,17 +1,6 @@ import './templates.js' import './legacy/filelistSearch.js' -import './actions/deleteAction' -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' -import './newMenu/newFolder' - import Vue from 'vue' import { createPinia, PiniaVuePlugin } from 'pinia' import { getNavigation } from '@nextcloud/files' @@ -19,10 +8,6 @@ import { getRequestToken } from '@nextcloud/auth' import FilesListView from './views/FilesList.vue' import NavigationView from './views/Navigation.vue' -import registerFavoritesView from './views/favorites' -import registerRecentView from './views/recent' -import registerFilesView from './views/files' -import registerPreviewServiceWorker from './services/ServiceWorker.js' import router from './router/router' import RouterService from './services/RouterService' import SettingsModel from './models/Setting.js' @@ -80,11 +65,3 @@ const FilesList = new ListView({ pinia, }) FilesList.$mount('#app-content-vue') - -// Init legacy and new files views -registerFavoritesView() -registerFilesView() -registerRecentView() - -// Register preview service worker -registerPreviewServiceWorker() diff --git a/apps/files/src/newMenu/newFolder.ts b/apps/files/src/newMenu/newFolder.ts index 1bf178de183..33fd113b7c3 100644 --- a/apps/files/src/newMenu/newFolder.ts +++ b/apps/files/src/newMenu/newFolder.ts @@ -62,7 +62,7 @@ export const getUniqueName = (name: string, names: string[]): string => { return newName } -const entry = { +export const entry = { id: 'newFolder', displayName: t('files', 'New folder'), if: (context: Folder) => (context.permissions & Permission.CREATE) !== 0, @@ -92,5 +92,3 @@ const entry = { emit('files:node:rename', folder) }, } as Entry - -addNewFileMenuEntry(entry) diff --git a/apps/files/src/services/DavProperties.ts b/apps/files/src/services/DavProperties.ts deleted file mode 100644 index 79a80706925..00000000000 --- a/apps/files/src/services/DavProperties.ts +++ /dev/null @@ -1,130 +0,0 @@ -/** - * @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 logger from '../logger' - -type DavProperty = { [key: string]: string } - -declare global { - interface Window { - OC: any; - _nc_dav_properties: string[]; - _nc_dav_namespaces: DavProperty; - } -} - -const defaultDavProperties = [ - 'd:getcontentlength', - 'd:getcontenttype', - 'd:getetag', - 'd:getlastmodified', - 'd:quota-available-bytes', - 'd:resourcetype', - 'nc:has-preview', - 'nc:is-encrypted', - 'nc:mount-type', - 'nc:share-attributes', - 'oc:comments-unread', - 'oc:favorite', - 'oc:fileid', - 'oc:owner-display-name', - 'oc:owner-id', - 'oc:permissions', - 'oc:share-types', - 'oc:size', - 'ocs:share-permissions', -] - -const defaultDavNamespaces = { - d: 'DAV:', - nc: 'http://nextcloud.org/ns', - oc: 'http://owncloud.org/ns', - ocs: 'http://open-collaboration-services.org/ns', -} - -/** - * TODO: remove and move to @nextcloud/files - * @param prop - * @param namespace - */ -export const registerDavProperty = function(prop: string, namespace: DavProperty = { nc: 'http://nextcloud.org/ns' }): void { - if (typeof window._nc_dav_properties === 'undefined') { - window._nc_dav_properties = defaultDavProperties - window._nc_dav_namespaces = defaultDavNamespaces - } - - const namespaces = { ...window._nc_dav_namespaces, ...namespace } - - // Check duplicates - if (window._nc_dav_properties.find(search => search === prop)) { - logger.error(`${prop} already registered`, { prop }) - return - } - - if (prop.startsWith('<') || prop.split(':').length !== 2) { - logger.error(`${prop} is not valid. See example: 'oc:fileid'`, { prop }) - return - } - - const ns = prop.split(':')[0] - if (!namespaces[ns]) { - logger.error(`${prop} namespace unknown`, { prop, namespaces }) - return - } - - window._nc_dav_properties.push(prop) - window._nc_dav_namespaces = namespaces -} - -/** - * Get the registered dav properties - */ -export const getDavProperties = function(): string { - if (typeof window._nc_dav_properties === 'undefined') { - window._nc_dav_properties = defaultDavProperties - } - - return window._nc_dav_properties.map(prop => `<${prop} />`).join(' ') -} - -/** - * Get the registered dav namespaces - */ -export const getDavNameSpaces = function(): string { - if (typeof window._nc_dav_namespaces === 'undefined') { - window._nc_dav_namespaces = defaultDavNamespaces - } - - return Object.keys(window._nc_dav_namespaces).map(ns => `xmlns:${ns}="${window._nc_dav_namespaces[ns]}"`).join(' ') -} - -/** - * Get the default PROPFIND request payload - */ -export const getDefaultPropfind = function() { - return `<?xml version="1.0"?> - <d:propfind ${getDavNameSpaces()}> - <d:prop> - ${getDavProperties()} - </d:prop> - </d:propfind>` -} diff --git a/apps/files/src/services/Favorites.ts b/apps/files/src/services/Favorites.ts index 633ba718560..800feb2c80a 100644 --- a/apps/files/src/services/Favorites.ts +++ b/apps/files/src/services/Favorites.ts @@ -20,14 +20,11 @@ * */ import type { ContentsWithRoot } from '@nextcloud/files' -import type { FileStat, ResponseDataDetailed, DAVResultResponseProps } from 'webdav' +import type { FileStat, ResponseDataDetailed } from 'webdav' -import { File, Folder, davParsePermissions } from '@nextcloud/files' -import { generateRemoteUrl } from '@nextcloud/router' -import { getCurrentUser } from '@nextcloud/auth' +import { Folder, getDavNameSpaces, getDavProperties, davGetDefaultPropfind } from '@nextcloud/files' -import { getClient, rootPath } from './WebdavClient' -import { getDavNameSpaces, getDavProperties, getDefaultPropfind } from './DavProperties' +import { getClient } from './WebdavClient' import { resultToNode } from './Files' const client = getClient() @@ -42,21 +39,15 @@ const reportPayload = `<?xml version="1.0"?> </oc:filter-rules> </oc:filter-files>` -interface ResponseProps extends DAVResultResponseProps { - permissions: string, - fileid: number, - size: number, -} - export const getContents = async (path = '/'): Promise<ContentsWithRoot> => { - const propfindPayload = getDefaultPropfind() + const propfindPayload = davGetDefaultPropfind() // Get root folder let rootResponse if (path === '/') { rootResponse = await client.stat(path, { details: true, - data: getDefaultPropfind(), + data: propfindPayload, }) as ResponseDataDetailed<FileStat> } diff --git a/apps/files/src/services/Files.ts b/apps/files/src/services/Files.ts index fba65ac44ae..c09be2d72ac 100644 --- a/apps/files/src/services/Files.ts +++ b/apps/files/src/services/Files.ts @@ -22,13 +22,12 @@ import type { ContentsWithRoot } from '@nextcloud/files' import type { FileStat, ResponseDataDetailed, DAVResultResponseProps } from 'webdav' -import { cancelable, CancelablePromise } from 'cancelable-promise' -import { File, Folder, davParsePermissions } from '@nextcloud/files' +import { CancelablePromise } from 'cancelable-promise' +import { File, Folder, davParsePermissions, davGetDefaultPropfind } from '@nextcloud/files' import { generateRemoteUrl } from '@nextcloud/router' import { getCurrentUser } from '@nextcloud/auth' import { getClient, rootPath } from './WebdavClient' -import { getDefaultPropfind } from './DavProperties' import { hashCode } from '../utils/hashUtils' import logger from '../logger' @@ -76,7 +75,7 @@ export const resultToNode = function(node: FileStat): File | Folder { export const getContents = (path = '/'): Promise<ContentsWithRoot> => { const controller = new AbortController() - const propfindPayload = getDefaultPropfind() + const propfindPayload = davGetDefaultPropfind() return new CancelablePromise(async (resolve, reject, onCancel) => { onCancel(() => controller.abort()) diff --git a/apps/files/src/services/Recent.ts b/apps/files/src/services/Recent.ts index 7a585d28fc5..ecd43b90ecc 100644 --- a/apps/files/src/services/Recent.ts +++ b/apps/files/src/services/Recent.ts @@ -22,12 +22,11 @@ import type { ContentsWithRoot } from '@nextcloud/files' import type { FileStat, ResponseDataDetailed, DAVResultResponseProps } from 'webdav' -import { File, Folder, Permission, davParsePermissions } from '@nextcloud/files' +import { Folder, Permission, getDavNameSpaces, getDavProperties } from '@nextcloud/files' import { generateRemoteUrl } from '@nextcloud/router' import { getCurrentUser } from '@nextcloud/auth' import { getClient, rootPath } from './WebdavClient' -import { getDavNameSpaces, getDavProperties } from './DavProperties' import { resultToNode } from './Files' const client = getClient(generateRemoteUrl('dav')) |