Skip to content

Commit ca81e95

Browse files
committed
turn download class into a function
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent 397cecd commit ca81e95

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

apps/files/js/files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@
380380
}
381381
};
382382

383-
OCA.Files.Download.get(files, dir, randomToken);
383+
OCA.Files.download(files, dir, randomToken);
384384
OC.Util.waitFor(checkForDownloadCookie, 500);
385385
}
386386
};

apps/files/src/download.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
*
2121
*/
2222

23-
import Download from './services/Download'
23+
import download from './services/Download'
2424

25-
// Init Sidebar Service
2625
if (!window.OCA.Files) {
2726
window.OCA.Files = {}
2827
}
29-
Object.assign(window.OCA.Files, { Download: new Download() })
28+
Object.assign(window.OCA.Files, { download })

apps/files/src/services/Download.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,21 @@
2323
import { generateUrl } from '@nextcloud/router'
2424
import axios from '@nextcloud/axios'
2525

26-
export default class Download {
27-
28-
export
29-
const
30-
get(files, dir, downloadStartSecret) {
31-
axios.post(
32-
generateUrl('apps/files/registerDownload'),
33-
{
34-
files,
35-
dir,
36-
downloadStartSecret,
37-
}
38-
).then(res => {
39-
if (res.status === 200 && res.data.token) {
40-
const dlUrl = generateUrl(
41-
'apps/files/ajax/download.php?token={token}',
42-
{ token: res.data.token }
43-
)
44-
OC.redirect(dlUrl)
45-
}
46-
})
47-
}
48-
26+
export default function(files, dir, downloadStartSecret) {
27+
axios.post(
28+
generateUrl('apps/files/registerDownload'),
29+
{
30+
files,
31+
dir,
32+
downloadStartSecret,
33+
}
34+
).then(res => {
35+
if (res.status === 200 && res.data.token) {
36+
const dlUrl = generateUrl(
37+
'apps/files/ajax/download.php?token={token}',
38+
{ token: res.data.token }
39+
)
40+
OC.redirect(dlUrl)
41+
}
42+
})
4943
}

apps/files_sharing/js/public.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@ OCA.Sharing.PublicApp = {
295295
$('#download').click(function (e) {
296296
e.preventDefault();
297297
OC.redirect(FileList.getDownloadUrl());
298+
299+
var path = dir || this.getCurrentDirectory();
300+
if (_.isArray(filename)) {
301+
filename = JSON.stringify(filename);
302+
}
303+
var params = {
304+
path: path
305+
};
306+
if (filename) {
307+
params.files = filename;
308+
}
309+
310+
311+
OCA.Files.Download.get()
298312
});
299313

300314
if (hideDownload === 'true') {

0 commit comments

Comments
 (0)