From c5b4c4132b27d1ca61aa81418f07bdcde20f8523 Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio@bekerle.com>
Date: Wed, 13 Jan 2021 13:33:34 +0100
Subject: [PATCH] Add nextcloud-file-url support (dbp/apps/signature#32)

---
 packages/file-handling/README.md                        | 4 ++++
 packages/file-handling/src/dbp-nextcloud-file-picker.js | 6 +++---
 packages/file-handling/src/file-sink.js                 | 3 +++
 packages/file-handling/src/file-source.js               | 3 +++
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/packages/file-handling/README.md b/packages/file-handling/README.md
index 4bbc3b8d..cbf85261 100644
--- a/packages/file-handling/README.md
+++ b/packages/file-handling/README.md
@@ -71,6 +71,8 @@ files from a [Nextcloud](https://nextcloud.com/) instance.
 - `nextcloud-web-dav-url` (optional): Nextcloud WebDav Url to use with the Nextcloud file picker
     - example `<dbp-file-source nextcloud-web-dav-url="http://localhost:8081/remote.php/dav/files"></dbp-file-source>`
     - `nextcloud-auth-url` also needs to be set for the Nextcloud file picker to be active
+- `nextcloud-file-url` (optional): Nextcloud File Url to use with the Nextcloud file picker
+    - example `<dbp-file-source nextcloud-file-url="http://localhost:8081/apps/files/?dir="></dbp-file-source>`
 - `dialog-open` (optional): if this attribute is set at runtime the dialog for selecting local or Nextcloud files will open
     - example `document.querySelector("dbp-file-source").setAttribute("dialog-open", "")`
 - `text` (optional): the text that is shown above the button to select files
@@ -112,6 +114,8 @@ files to a [Nextcloud](https://nextcloud.com/) instance.
 - `nextcloud-web-dav-url` (optional): Nextcloud WebDav Url to use with the Nextcloud file picker
     - example `<dbp-file-sink nextcloud-web-dav-url="http://localhost:8081/remote.php/dav/files"></dbp-file-sink>`
     - `nextcloud-auth-url` also needs to be set for the Nextcloud file picker to be active
+- `nextcloud-file-url` (optional): Nextcloud File Url to use with the Nextcloud file picker
+  - example `<dbp-file-source nextcloud-file-url="http://localhost:8081/apps/files/?dir="></dbp-file-source>`
 - `text` (optional): the text that is shown above the button to download the zip file
     - example `<dbp-file-sink text="Download files as ZIP-file"></dbp-file-sink>`
 - `button-label` (optional): the text that is shown on the button to download the zip file
diff --git a/packages/file-handling/src/dbp-nextcloud-file-picker.js b/packages/file-handling/src/dbp-nextcloud-file-picker.js
index 0a7e5da6..a1b56bc2 100644
--- a/packages/file-handling/src/dbp-nextcloud-file-picker.js
+++ b/packages/file-handling/src/dbp-nextcloud-file-picker.js
@@ -9,7 +9,6 @@ import {createClient} from 'webdav/web';
 import {classMap} from 'lit-html/directives/class-map.js';
 import {humanFileSize} from '@dbp-toolkit/common/i18next';
 import Tabulator from 'tabulator-tables';
-import nextcloudFileURL from 'consts:nextcloudFileURL';
 import MicroModal from './micromodal.es';
 import {name as pkgName} from './../package.json';
 
@@ -23,6 +22,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
         this.authUrl = '';
         this.webDavUrl = '';
         this.nextcloudName = 'Nextcloud';
+        this.nextcloudFileURL = '';
         this.loginWindow = null;
         this.isPickerActive = false;
         this.statusText = '';
@@ -68,6 +68,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
             lang: { type: String },
             authUrl: { type: String, attribute: 'auth-url' },
             webDavUrl: { type: String, attribute: 'web-dav-url' },
+            nextcloudFileURL: { type: String, attribute: 'nextcloud-file-url' },
             nextcloudName: { type: String, attribute: 'nextcloud-name' },
             isPickerActive: { type: Boolean, attribute: false },
             statusText: { type: String, attribute: false },
@@ -944,8 +945,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
      * @returns {string} actual directory Nextcloud link
      */
     getNextCloudLink() {
-        let link = nextcloudFileURL + this.directoryPath;
-        return link;
+        return this.nextcloudFileURL + this.directoryPath;
     }
 
     getCloudLogo() {
diff --git a/packages/file-handling/src/file-sink.js b/packages/file-handling/src/file-sink.js
index 90875ee6..3fb36192 100644
--- a/packages/file-handling/src/file-sink.js
+++ b/packages/file-handling/src/file-sink.js
@@ -24,6 +24,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
         this.nextcloudAuthUrl = '';
         this.nextcloudWebDavUrl = '';
         this.nextcloudName ='Nextcloud';
+        this.nextcloudFileURL = '';
         this.text = '';
         this.buttonLabel = '';
         this.filename = "files.zip";
@@ -54,6 +55,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
             nextcloudAuthUrl: { type: String, attribute: 'nextcloud-auth-url' },
             nextcloudWebDavUrl: { type: String, attribute: 'nextcloud-web-dav-url' },
             nextcloudName: { type: String, attribute: 'nextcloud-name' },
+            nextcloudFileURL: { type: String, attribute: 'nextcloud-file-url' },
             text: { type: String },
             buttonLabel: { type: String, attribute: 'button-label' },
             isDialogOpen: { type: Boolean, attribute: false },
@@ -239,6 +241,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
                                                            auth-url="${this.nextcloudAuthUrl}"
                                                            web-dav-url="${this.nextcloudWebDavUrl}"
                                                            nextcloud-name="${this.nextcloudName}"
+                                                           nextcloud-file-url="${this.nextcloudFileURL}"
                                                            @dbp-nextcloud-file-picker-file-uploaded="${(event) => {
                                                                this.uploadToNextcloud(event.detail);
                                                            }}"
diff --git a/packages/file-handling/src/file-source.js b/packages/file-handling/src/file-source.js
index f9e93def..59dc64b6 100644
--- a/packages/file-handling/src/file-source.js
+++ b/packages/file-handling/src/file-source.js
@@ -39,6 +39,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
         this.nextcloudAuthUrl = '';
         this.nextcloudName ='Nextcloud';
         this.nextcloudWebDavUrl = '';
+        this.nextcloudFileURL = '';
         this.dropArea = null;
         this.allowedMimeTypes = '*/*';
         this.enabledSources = 'local';
@@ -71,6 +72,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
             nextcloudAuthUrl: { type: String, attribute: 'nextcloud-auth-url' },
             nextcloudWebDavUrl: { type: String, attribute: 'nextcloud-web-dav-url' },
             nextcloudName: { type: String, attribute: 'nextcloud-name' },
+            nextcloudFileURL: { type: String, attribute: 'nextcloud-file-url' },
             text: { type: String },
             buttonLabel: { type: String, attribute: 'button-label' },
             disabled: { type: Boolean },
@@ -456,6 +458,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
                                        auth-url="${this.nextcloudAuthUrl}"
                                        web-dav-url="${this.nextcloudWebDavUrl}"
                                        nextcloud-name="${this.nextcloudName}"
+                                       nextcloud-file-url="${this.nextcloudFileURL}"
                                        allowed-mime-types="${this.allowedMimeTypes}"
                                        @dbp-nextcloud-file-picker-file-downloaded="${(event) => {
                                     this.sendFileEvent(event.detail.file);
-- 
GitLab