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

Commit

Permalink
#75 feat(Storage): file removal ability.
Browse files Browse the repository at this point in the history
- Added TS definition
- Fixed an issue on iOS where error was never set as the method only supports 1 param
  • Loading branch information
EddyVerbruggen committed Jul 17, 2016
1 parent 0b774a8 commit 206e4fd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
10 changes: 5 additions & 5 deletions docs/STORAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,21 @@ In this example we'll determine the remote URL of the previously uploaded file.
);
```

### removeFile
You can pass in remote file path to remove it.
### deleteFile
You can pass in remote file path to delete it.

```js
firebase.removeFile({
firebase.deleteFile({
// optional, can also be passed during init() as 'storageBucket' param so we can cache it
bucket: 'gs://n-plugin-test.appspot.com',
// the full path of an existing file in your Firebase storage
remoteFullPath: 'uploads/images/telerik-logo-uploaded.png'
}).then(
function ()
console.log("File removed.");
console.log("File deleted.");
},
function (error) {
console.log("File removal Error: " + error);
console.log("File deletion Error: " + error);
}
);
```
11 changes: 4 additions & 7 deletions firebase.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -1025,14 +1025,13 @@ firebase.getDownloadUrl = function (arg) {

var onSuccessListener = new com.google.android.gms.tasks.OnSuccessListener({
onSuccess: function(uri) {
console.log("uri: " + uri);
resolve(uri);
}
});

var onFailureListener = new com.google.android.gms.tasks.OnFailureListener({
onFailure: function (exception) {
reject(exception);
reject(exception.getMessage());
}
});

Expand All @@ -1047,7 +1046,7 @@ firebase.getDownloadUrl = function (arg) {
});
};

firebase.removeFile = function (arg) {
firebase.deleteFile = function (arg) {
return new Promise(function (resolve, reject) {
try {

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

var onSuccessListener = new com.google.android.gms.tasks.OnSuccessListener({
onSuccess: function() {
console.log("Removed file.");
resolve();
}
});

var onFailureListener = new com.google.android.gms.tasks.OnFailureListener({
onFailure: function (exception) {
console.log("Error removing file.");
reject(exception);
reject(exception.getMessage());
}
});

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

} catch (ex) {
console.log("Error in firebase.removeFile: " + ex);
console.log("Error in firebase.deleteFile: " + ex);
reject(ex);
}
});
Expand Down
4 changes: 2 additions & 2 deletions firebase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ declare module "nativescript-plugin-firebase" {
remoteFullPath: string;
}

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

// crash logging
// export function sendCrashLog(options: SendCrashLogOptions): Promise<any>;
Expand Down
18 changes: 9 additions & 9 deletions firebase.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ firebase._processPendingNotifications = function() {
// Firebase notifications (FCM)
if (firebase._messagingConnected !== null) {
FIRMessaging.messaging().connectWithCompletion(function(error) {
if (error !== null) {
if (error) {
console.log("Firebase was unable to connect to FCM. Error: " + error);
} else {
firebase._messagingConnected = true;
Expand Down Expand Up @@ -326,7 +326,7 @@ firebase._onTokenRefreshNotification = function (notification) {
}

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

var onCompletion = function(metadata, error) {
if (error !== null) {
if (error) {
reject(error.localizedDescription);
} else {
resolve({
Expand Down Expand Up @@ -947,7 +947,7 @@ firebase.downloadFile = function (arg) {
try {

var onCompletion = function(url, error) {
if (error !== null) {
if (error) {
reject(error.localizedDescription);
} else {
resolve(url.absoluteURL);
Expand Down Expand Up @@ -996,7 +996,7 @@ firebase.getDownloadUrl = function (arg) {
try {

var onCompletion = function(url, error) {
if (error !== null) {
if (error) {
reject(error.localizedDescription);
} else {
resolve(url.absoluteURL);
Expand All @@ -1020,12 +1020,12 @@ firebase.getDownloadUrl = function (arg) {
});
};

firebase.removeFile = function (arg) {
firebase.deleteFile = function (arg) {
return new Promise(function (resolve, reject) {
try {

var onCompletion = function(metadata, error) {
if (error !== null) {
var onCompletion = function(error) {
if (error) {
reject(error.localizedDescription);
} else {
resolve();
Expand All @@ -1043,7 +1043,7 @@ firebase.removeFile = function (arg) {
fIRStorageFileRef.deleteWithCompletion(onCompletion);

} catch (ex) {
console.log("Error in firebase.removeFile: " + ex);
console.log("Error in firebase.deleteFile: " + ex);
reject(ex);
}
});
Expand Down

0 comments on commit 206e4fd

Please sign in to comment.