Skip to content

Commit

Permalink
turn download class into a function
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Mar 31, 2021
1 parent 3d96fb3 commit 7c33107
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion apps/files/js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
}
};

OCA.Files.Download.get(files, dir, randomToken);
OCA.Files.download(files, dir, randomToken);
OC.Util.waitFor(checkForDownloadCookie, 500);
}
};
Expand Down
5 changes: 2 additions & 3 deletions apps/files/src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
*
*/

import Download from './services/Download'
import download from './services/Download'

// Init Sidebar Service
if (!window.OCA.Files) {
window.OCA.Files = {}
}
Object.assign(window.OCA.Files, { Download: new Download() })
Object.assign(window.OCA.Files, { download })
40 changes: 17 additions & 23 deletions apps/files/src/services/Download.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,21 @@
import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'

export default class Download {

export
const
get(files, dir, downloadStartSecret) {
axios.post(
generateUrl('apps/files/registerDownload'),
{
files,
dir,
downloadStartSecret,
}
).then(res => {
if (res.status === 200 && res.data.token) {
const dlUrl = generateUrl(
'apps/files/ajax/download.php?token={token}',
{ token: res.data.token }
)
OC.redirect(dlUrl)
}
})
}

export default function(files, dir, downloadStartSecret) {
axios.post(
generateUrl('apps/files/registerDownload'),
{
files,
dir,
downloadStartSecret,
}
).then(res => {
if (res.status === 200 && res.data.token) {
const dlUrl = generateUrl(
'apps/files/ajax/download.php?token={token}',
{ token: res.data.token }
)
OC.redirect(dlUrl)
}
})
}
14 changes: 14 additions & 0 deletions apps/files_sharing/js/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,20 @@ OCA.Sharing.PublicApp = {
$('#download').click(function (e) {
e.preventDefault();
OC.redirect(FileList.getDownloadUrl());

var path = dir || this.getCurrentDirectory();
if (_.isArray(filename)) {
filename = JSON.stringify(filename);
}
var params = {
path: path
};
if (filename) {
params.files = filename;
}


OCA.Files.Download.get()
});

if (hideDownload === 'true') {
Expand Down

0 comments on commit 7c33107

Please sign in to comment.