Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit cd969f8

Browse files
#75 feat(Storage): file removal ability.
- Added TS definition - Fixed an issue on iOS where error was never set as the method only supports 1 param
1 parent 8d4f308 commit cd969f8

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

docs/STORAGE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@ In this example we'll determine the remote URL of the previously uploaded file.
117117
);
118118
```
119119

120-
### removeFile
121-
You can pass in remote file path to remove it.
120+
### deleteFile
121+
You can pass in remote file path to delete it.
122122

123123
```js
124-
firebase.removeFile({
124+
firebase.deleteFile({
125125
// optional, can also be passed during init() as 'storageBucket' param so we can cache it
126126
bucket: 'gs://n-plugin-test.appspot.com',
127127
// the full path of an existing file in your Firebase storage
128128
remoteFullPath: 'uploads/images/telerik-logo-uploaded.png'
129129
}).then(
130130
function ()
131-
console.log("File removed.");
131+
console.log("File deleted.");
132132
},
133133
function (error) {
134-
console.log("File removal Error: " + error);
134+
console.log("File deletion Error: " + error);
135135
}
136136
);
137137
```

firebase.android.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,14 +1025,13 @@ firebase.getDownloadUrl = function (arg) {
10251025

10261026
var onSuccessListener = new com.google.android.gms.tasks.OnSuccessListener({
10271027
onSuccess: function(uri) {
1028-
console.log("uri: " + uri);
10291028
resolve(uri);
10301029
}
10311030
});
10321031

10331032
var onFailureListener = new com.google.android.gms.tasks.OnFailureListener({
10341033
onFailure: function (exception) {
1035-
reject(exception);
1034+
reject(exception.getMessage());
10361035
}
10371036
});
10381037

@@ -1047,7 +1046,7 @@ firebase.getDownloadUrl = function (arg) {
10471046
});
10481047
};
10491048

1050-
firebase.removeFile = function (arg) {
1049+
firebase.deleteFile = function (arg) {
10511050
return new Promise(function (resolve, reject) {
10521051
try {
10531052

@@ -1061,15 +1060,13 @@ firebase.removeFile = function (arg) {
10611060

10621061
var onSuccessListener = new com.google.android.gms.tasks.OnSuccessListener({
10631062
onSuccess: function() {
1064-
console.log("Removed file.");
10651063
resolve();
10661064
}
10671065
});
10681066

10691067
var onFailureListener = new com.google.android.gms.tasks.OnFailureListener({
10701068
onFailure: function (exception) {
1071-
console.log("Error removing file.");
1072-
reject(exception);
1069+
reject(exception.getMessage());
10731070
}
10741071
});
10751072

@@ -1078,7 +1075,7 @@ firebase.removeFile = function (arg) {
10781075
.addOnFailureListener(onFailureListener);
10791076

10801077
} catch (ex) {
1081-
console.log("Error in firebase.removeFile: " + ex);
1078+
console.log("Error in firebase.deleteFile: " + ex);
10821079
reject(ex);
10831080
}
10841081
});

firebase.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ declare module "nativescript-plugin-firebase" {
307307
remoteFullPath: string;
308308
}
309309

310-
export interface RemoveFileOptions {
310+
export interface DeleteFileOptions {
311311
/**
312312
* If you didn't pass 'storageBucket' during init() you will need to do it now.
313313
* Takes the form of 'gs://n-plugin-test.appspot.com' and can be found in the Firebase console.
@@ -365,7 +365,7 @@ declare module "nativescript-plugin-firebase" {
365365
export function uploadFile(options: UploadFileOptions): Promise<UploadFileResult>;
366366
export function downloadFile(options: DownloadFileOptions): Promise<any>;
367367
export function getDownloadUrl(options: GetDownloadUrlOptions): Promise<string>;
368-
export function removeFile(options: RemoveFileOptions): Promise<any>;
368+
export function deleteFile(options: DeleteFileOptions): Promise<any>;
369369

370370
// crash logging
371371
// export function sendCrashLog(options: SendCrashLogOptions): Promise<any>;

firebase.ios.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ firebase._processPendingNotifications = function() {
138138
// Firebase notifications (FCM)
139139
if (firebase._messagingConnected !== null) {
140140
FIRMessaging.messaging().connectWithCompletion(function(error) {
141-
if (error !== null) {
141+
if (error) {
142142
console.log("Firebase was unable to connect to FCM. Error: " + error);
143143
} else {
144144
firebase._messagingConnected = true;
@@ -326,7 +326,7 @@ firebase._onTokenRefreshNotification = function (notification) {
326326
}
327327

328328
FIRMessaging.messaging().connectWithCompletion(function(error) {
329-
if (error !== null) {
329+
if (error) {
330330
// this is not fatal at all but still would like to know how often this happens
331331
console.log("Firebase was unable to connect to FCM. Error: " + error);
332332
} else {
@@ -887,7 +887,7 @@ firebase.uploadFile = function (arg) {
887887
try {
888888

889889
var onCompletion = function(metadata, error) {
890-
if (error !== null) {
890+
if (error) {
891891
reject(error.localizedDescription);
892892
} else {
893893
resolve({
@@ -947,7 +947,7 @@ firebase.downloadFile = function (arg) {
947947
try {
948948

949949
var onCompletion = function(url, error) {
950-
if (error !== null) {
950+
if (error) {
951951
reject(error.localizedDescription);
952952
} else {
953953
resolve(url.absoluteURL);
@@ -996,7 +996,7 @@ firebase.getDownloadUrl = function (arg) {
996996
try {
997997

998998
var onCompletion = function(url, error) {
999-
if (error !== null) {
999+
if (error) {
10001000
reject(error.localizedDescription);
10011001
} else {
10021002
resolve(url.absoluteURL);
@@ -1020,12 +1020,12 @@ firebase.getDownloadUrl = function (arg) {
10201020
});
10211021
};
10221022

1023-
firebase.removeFile = function (arg) {
1023+
firebase.deleteFile = function (arg) {
10241024
return new Promise(function (resolve, reject) {
10251025
try {
10261026

1027-
var onCompletion = function(metadata, error) {
1028-
if (error !== null) {
1027+
var onCompletion = function(error) {
1028+
if (error) {
10291029
reject(error.localizedDescription);
10301030
} else {
10311031
resolve();
@@ -1043,7 +1043,7 @@ firebase.removeFile = function (arg) {
10431043
fIRStorageFileRef.deleteWithCompletion(onCompletion);
10441044

10451045
} catch (ex) {
1046-
console.log("Error in firebase.removeFile: " + ex);
1046+
console.log("Error in firebase.deleteFile: " + ex);
10471047
reject(ex);
10481048
}
10491049
});

0 commit comments

Comments
 (0)