aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/src/utils')
-rw-r--r--apps/files_external/src/utils/credentialsUtils.ts25
-rw-r--r--apps/files_external/src/utils/externalStorageUtils.spec.ts74
-rw-r--r--apps/files_external/src/utils/externalStorageUtils.ts22
3 files changed, 121 insertions, 0 deletions
diff --git a/apps/files_external/src/utils/credentialsUtils.ts b/apps/files_external/src/utils/credentialsUtils.ts
new file mode 100644
index 00000000000..5c19c7bce44
--- /dev/null
+++ b/apps/files_external/src/utils/credentialsUtils.ts
@@ -0,0 +1,25 @@
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+import type { StorageConfig } from '../services/externalStorage'
+
+// @see https://github.com/nextcloud/server/blob/ac2bc2384efe3c15ff987b87a7432bc60d545c67/lib/public/Files/StorageNotAvailableException.php#L41
+export enum STORAGE_STATUS {
+ SUCCESS = 0,
+ ERROR = 1,
+ INDETERMINATE = 2,
+ INCOMPLETE_CONF = 3,
+ UNAUTHORIZED = 4,
+ TIMEOUT = 5,
+ NETWORK_ERROR = 6,
+}
+
+export const isMissingAuthConfig = function(config: StorageConfig) {
+ // If we don't know the status, assume it is ok
+ if (!config.status || config.status === STORAGE_STATUS.SUCCESS) {
+ return false
+ }
+
+ return config.userProvided || config.authMechanism === 'password::global::user'
+}
diff --git a/apps/files_external/src/utils/externalStorageUtils.spec.ts b/apps/files_external/src/utils/externalStorageUtils.spec.ts
new file mode 100644
index 00000000000..a6a29e27a7c
--- /dev/null
+++ b/apps/files_external/src/utils/externalStorageUtils.spec.ts
@@ -0,0 +1,74 @@
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+import { File, Folder, Permission } from '@nextcloud/files'
+import { describe, expect, test } from 'vitest'
+import { isNodeExternalStorage } from './externalStorageUtils'
+
+describe('Is node an external storage', () => {
+ test('A Folder with a backend and a valid scope is an external storage', () => {
+ const folder = new Folder({
+ id: 1,
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
+ owner: 'admin',
+ permissions: Permission.ALL,
+ attributes: {
+ scope: 'personal',
+ backend: 'SFTP',
+ },
+ })
+ expect(isNodeExternalStorage(folder)).toBe(true)
+ })
+
+ test('a File is not a valid storage', () => {
+ const file = new File({
+ id: 1,
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
+ owner: 'admin',
+ mime: 'text/plain',
+ permissions: Permission.ALL,
+ })
+ expect(isNodeExternalStorage(file)).toBe(false)
+ })
+
+ test('A Folder without a backend is not a storage', () => {
+ const folder = new Folder({
+ id: 1,
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
+ owner: 'admin',
+ permissions: Permission.ALL,
+ attributes: {
+ scope: 'personal',
+ },
+ })
+ expect(isNodeExternalStorage(folder)).toBe(false)
+ })
+
+ test('A Folder without a scope is not a storage', () => {
+ const folder = new Folder({
+ id: 1,
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
+ owner: 'admin',
+ permissions: Permission.ALL,
+ attributes: {
+ backend: 'SFTP',
+ },
+ })
+ expect(isNodeExternalStorage(folder)).toBe(false)
+ })
+
+ test('A Folder with an invalid scope is not a storage', () => {
+ const folder = new Folder({
+ id: 1,
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
+ owner: 'admin',
+ permissions: Permission.ALL,
+ attributes: {
+ scope: 'null',
+ backend: 'SFTP',
+ },
+ })
+ expect(isNodeExternalStorage(folder)).toBe(false)
+ })
+})
diff --git a/apps/files_external/src/utils/externalStorageUtils.ts b/apps/files_external/src/utils/externalStorageUtils.ts
new file mode 100644
index 00000000000..4407def5ce7
--- /dev/null
+++ b/apps/files_external/src/utils/externalStorageUtils.ts
@@ -0,0 +1,22 @@
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+import { FileType, Node } from '@nextcloud/files'
+import type { MountEntry } from '../services/externalStorage'
+
+export const isNodeExternalStorage = function(node: Node) {
+ // Not a folder, not a storage
+ if (node.type === FileType.File) {
+ return false
+ }
+
+ // No backend or scope, not a storage
+ const attributes = node.attributes as MountEntry
+ if (!attributes.scope || !attributes.backend) {
+ return false
+ }
+
+ // Specific markers that we're sure are ext storage only
+ return attributes.scope === 'personal' || attributes.scope === 'system'
+}