From b868561951ffbb810a59b340eeb76c38fb9855fe Mon Sep 17 00:00:00 2001
From: albertony <12441419+albertony@users.noreply.github.com>
Date: Thu, 10 Jun 2021 19:44:11 +0200
Subject: [PATCH] jottacloud: return direct download link from rclone link
 command

If the shared path is a directory, then the download will be a zip archive.

Fixes #5391

See #5399
---
 backend/jottacloud/api/types.go  |  1 +
 backend/jottacloud/jottacloud.go | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/backend/jottacloud/api/types.go b/backend/jottacloud/api/types.go
index 993f8e6e3..83dbf01a8 100644
--- a/backend/jottacloud/api/types.go
+++ b/backend/jottacloud/api/types.go
@@ -368,6 +368,7 @@ type JottaFile struct {
 	XMLName         xml.Name
 	Name            string `xml:"name,attr"`
 	Deleted         Flag   `xml:"deleted,attr"`
+	PublicURI       string `xml:"publicURI"`
 	PublicSharePath string `xml:"publicSharePath"`
 	State           string `xml:"currentRevision>state"`
 	CreatedAt       Time   `xml:"currentRevision>created"`
diff --git a/backend/jottacloud/jottacloud.go b/backend/jottacloud/jottacloud.go
index 85db2f9e1..7f6d1972d 100644
--- a/backend/jottacloud/jottacloud.go
+++ b/backend/jottacloud/jottacloud.go
@@ -1261,15 +1261,23 @@ func (f *Fs) PublicLink(ctx context.Context, remote string, expire fs.Duration,
 		return "", errors.Wrap(err, "couldn't create public link")
 	}
 	if unlink {
-		if result.PublicSharePath != "" {
-			return "", errors.Errorf("couldn't remove public link - %q", result.PublicSharePath)
+		if result.PublicURI != "" {
+			return "", errors.Errorf("couldn't remove public link - %q", result.PublicURI)
 		}
 		return "", nil
 	}
-	if result.PublicSharePath == "" {
-		return "", errors.New("couldn't create public link - no link path received")
+	if result.PublicURI == "" {
+		return "", errors.New("couldn't create public link - no uri received")
 	}
-	return joinPath(baseURL, result.PublicSharePath), nil
+	if result.PublicSharePath != "" {
+		webLink := joinPath(baseURL, result.PublicSharePath)
+		fs.Debugf(nil, "Web link: %s", webLink)
+	} else {
+		fs.Debugf(nil, "No web link received")
+	}
+	directLink := joinPath(baseURL, fmt.Sprintf("opin/io/downloadPublic/%s/%s", f.user, result.PublicURI))
+	fs.Debugf(nil, "Direct link: %s", directLink)
+	return directLink, nil
 }
 
 // About gets quota information