Skip to content

Commit 54d5eea

Browse files
authored
feat(downloader): add plugin (#4893)
1 parent 4352da9 commit 54d5eea

File tree

1 file changed

+115
-0
lines changed
  • src/@awesome-cordova-plugins/plugins/downloader

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { Injectable } from '@angular/core';
2+
import { Cordova, AwesomeCordovaNativePlugin, Plugin } from '@awesome-cordova-plugins/core';
3+
4+
export enum NotificationVisibility {
5+
Visible = 0,
6+
VisibleNotifyCompleted = 1,
7+
VisibilityHidden = 2,
8+
VisibleNotifyOnlyCompletion = 3
9+
}
10+
11+
export interface DownloadHttpHeader {
12+
header: string;
13+
value: string;
14+
}
15+
16+
export interface DestinationDirectory {
17+
dirType: string;
18+
subPath: string;
19+
}
20+
21+
export interface DownloadRequest {
22+
/**
23+
* Location of the resource to download
24+
*/
25+
uri: string;
26+
27+
/**
28+
* Set the title of this download, to be displayed in notifications (if enabled).
29+
* If no title is given, a default one will be assigned based on the download filename, once the download starts.
30+
*/
31+
title?: string;
32+
/**
33+
* Set a description of this download, to be displayed in notifications (if enabled)
34+
*/
35+
description?: string;
36+
/**
37+
* Set the MIME content type of this download. This will override the content type declared in the server's response.
38+
*/
39+
mimeType?: string;
40+
/**
41+
* Set whether this download should be displayed in the system's Downloads UI. True by default.
42+
*/
43+
visibleInDownloadsUi?: boolean;
44+
/**
45+
* Control whether a system notification is posted by the download manager while this download is running or when it is completed.
46+
*/
47+
notificationVisibility?: NotificationVisibility;
48+
/**
49+
* Set the local destination for the downloaded file to a path within the application's external files directory
50+
*/
51+
destinationInExternalFilesDir?: DestinationDirectory;
52+
/**
53+
* Set the local destination for the downloaded file to a path within the public external storage directory
54+
*/
55+
destinationInExternalPublicDir?: DestinationDirectory;
56+
/**
57+
* Set the local destination for the downloaded file.
58+
* Must be a file URI to a path on external storage, and the calling application must have the WRITE_EXTERNAL_STORAGE permission.
59+
*/
60+
destinationUri?: string;
61+
/**
62+
* Add an HTTP header to be included with the download request. The header will be added to the end of the list.
63+
*/
64+
headers?: DownloadHttpHeader[];
65+
}
66+
67+
/**
68+
* @name Document Downloader
69+
* @description
70+
* This plugin is designed to support downloading files using Android DownloadManager.
71+
* @usage
72+
* ```typescript
73+
* var request: DownloadRequest = {
74+
* uri: YOUR_URI,
75+
* title: 'MyDownload',
76+
* description: '',
77+
* mimeType: '',
78+
* visibleInDownloadsUi: true,
79+
* notificationVisibility: NotificationVisibility.VisibleNotifyCompleted,
80+
* destinationInExternalFilesDir: {
81+
* dirType: 'Downloads',
82+
* subPath: 'MyFile.apk'
83+
* }
84+
* };
85+
*
86+
*
87+
* this.downloader.download(request)
88+
* .then((location: string) => console.log('File downloaded at:'+location))
89+
* .catch((error: any) => console.error(error));
90+
* ```
91+
* @interfaces
92+
* Header
93+
* DestinationDirectory
94+
* DownloadHttpHeader
95+
* @enums
96+
* NotificationVisibility
97+
*/
98+
@Plugin({
99+
pluginName: 'Downloader',
100+
plugin: 'integrator-cordova-plugin-downloader',
101+
pluginRef: 'cordova.plugins.Downloader',
102+
repo: 'https://github.com/Luka313/integrator-cordova-plugin-downloader.git',
103+
platforms: ['Android'],
104+
})
105+
@Injectable()
106+
export class Downloader extends AwesomeCordovaNativePlugin {
107+
/**
108+
* Starts a new download and returns location of the downloaded file on completion
109+
* @param request {DownloadRequest}
110+
*/
111+
@Cordova()
112+
download(request: DownloadRequest): Promise<string> {
113+
return;
114+
}
115+
}

0 commit comments

Comments
 (0)