Enhanced API

This commit is contained in:
Qolzam
2017-07-18 12:47:41 +04:30
parent cb563384e6
commit a0031fdbb8
3 changed files with 44 additions and 83 deletions

View File

@@ -67,24 +67,6 @@ const constraintImage = (file,fileName, maxWidth, maxHeight) => {
} }
} }
// - Delete file from storage
const deleteFile = (folderName, fileName, callBackSuccess, callBackError) => {
// Create a reference to the file to delete
var desertRef = storageRef.child(`${folderName}/${filename}`);
// Delete the file
desertRef.delete().then(function () {
// File deleted successfully
callBackSuccess()
console.log('File has been deleted successfully');
}).catch(function (error) {
// Uh-oh, an error occurred!
callBackError(error)
console.log(error);
});
}
/** /**
* Convert data URL to blob * Convert data URL to blob
@@ -115,73 +97,10 @@ const dataURLToBlob = (dataURL) => {
return new Blob([uInt8Array], {type: contentType}) return new Blob([uInt8Array], {type: contentType})
} }
// - Upload file
const uploadFile = (file, folderName, fileName, progressCallBack, errorCallBack, completeCallBack) => {
// Create a storage refrence
var storegeFile = storageRef.child(folderName + '/' + fileName)
// Upload file
var task = storegeFile.put(file)
// Upload storage bar
task.on('state_changed', (snapshot) => {
var percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100
progressCallBack(percentage)
// Set uploader progress value
}, (error) => {
errorCallBack(error)
}, (complete) => {
completeCallBack(complete)
})
}
const downloadFile = (folderName, fileName, callBack) => {
// Create a reference to the file we want to download
var starsRef = storageRef.child(`${folderName}/${fileName}`);
// Get the download URL
starsRef.getDownloadURL().then((url) => {
// Insert url into an <img> tag to "download"
callBack(url)
}).catch((error) => {
// A full list of error codes is available at
// https://firebase.google.com/docs/storage/web/handle-errors
switch (error.code) {
case 'storage/object_not_found':
// File doesn't exist
console.log('storage/object_not_found');
break;
case 'storage/unauthorized':
// User doesn't have permission to access the object
console.log('storage/unauthorized');
break;
case 'storage/canceled':
// User canceled the upload
console.log('storage/canceled');
break;
case 'storage/unknown':
// Unknown error occurred, inspect the server response
console.log('storage/unknown');
break;
}
});
}
export default { export default {
downloadFile,
uploadFile,
dataURLToBlob, dataURLToBlob,
deleteFile,
convertImageToCanvas, convertImageToCanvas,
getExtension, getExtension,
constraintImage constraintImage

View File

@@ -16,7 +16,7 @@ export const getContentTags = (content) => {
return newTags return newTags
} }
export const sortObjectsDate = function (objects) { export const sortObjectsDate = (objects) => {
var sortedObjects = objects; var sortedObjects = objects;
// Sort posts with creation date // Sort posts with creation date

View File

@@ -22,6 +22,48 @@ Get the user who are in circles. `circles` is the paramater that we get users fr
A set of functions for working with files. A set of functions for working with files.
```javascript
getExtension = (fileName) => {}
```
Get file extension from file name. `fileName` is the name of file.
```javascript
convertImageToCanvas = (image) => {}
```
Conver image to canvas. `image` is the image file should be converted.
```javascript
constraintImage = (file,fileName, maxWidth, maxHeight) => {}
```
Resize an image with specific max-height and max-with. After resizing image, `onSendResizedImage` event will be fired and will send the image resized and file name as arguments . `file` is image file , `fileName` is the name of the image, `maxWidth` is the maximum width and `maxHeight` is the maximum width for the image.
```javascript
dataURLToBlob = (dataURL) => {}
```
Convert [data url file](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) to [blob file](https://developer.mozilla.org/en/docs/Web/API/Blob). `dataURL` is the file with data url type.
## PostAPI.jsx ## PostAPI.jsx
A set of functions for working with user posts. A set of functions for working with user posts.
```javascript
detectTags = (content,character) => {}
```
Detect and get word wich starts with specific `character` in the `content` of a text.
```javascript
getContentTags = (content) => {}
```
Get tag from the `content` of a text.
```javascript
sortObjectsDate = (objects) => {}
```
Sort an java script object based on key/value type.