mirror of
https://bitbucket.org/tagfer_team/tagfer-server.git
synced 2025-12-25 03:37:38 +00:00
T-954157790482076: Code review comments
- removed response variable from utility and dao function signatures
This commit is contained in:
parent
b4c93b96ec
commit
b50fe3e951
@ -44,10 +44,14 @@ function getProfile(profileNumber, tagferId) {
|
||||
* @returns {object} Object containing a Promise that contains the result of uploading profile image, and the image url | {promise, imageURL}
|
||||
*/
|
||||
|
||||
async function updateProfileImage(profileImageData, profileNumber, tagferId, res) {
|
||||
async function updateProfileImage(profileImageData, profileNumber, tagferId) {
|
||||
//persist profile image data to firebase storage
|
||||
var downloadURL = await utils.uploadImage(profileImageData, `${tagferId}-profile${profileNumber}`, appConfig.buckets.profile, res);
|
||||
return { promise: database.ref(`/profiles/${tagferId}/profile${profileNumber}/photoURL`).set(downloadURL), imageURL: downloadURL };
|
||||
try {
|
||||
var downloadURL = await utils.uploadImage(profileImageData, `${tagferId}-profile${profileNumber}`, appConfig.buckets.profile);
|
||||
return { promise: database.ref(`/profiles/${tagferId}/profile${profileNumber}/photoURL`).set(downloadURL), imageURL: downloadURL };
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -3,7 +3,6 @@ const authDao = require('../auth/dao');
|
||||
const utils = require('../utils/utils');
|
||||
const errors = require('../../config/errors');
|
||||
const http = require('../../config/http');
|
||||
const _ = require('lodash');
|
||||
|
||||
// Handlers
|
||||
/**
|
||||
@ -45,7 +44,7 @@ async function updateUserProfileImage(req, res) {
|
||||
|
||||
try {
|
||||
const tagferId = authDao.getSession(sessionId).tagferId;
|
||||
const result = await profileDao.updateProfileImage(profileImageObj, req.params.profileNumber, tagferId, res)
|
||||
const result = await profileDao.updateProfileImage(profileImageObj, req.params.profileNumber, tagferId);
|
||||
result.promise.then(() => {
|
||||
res.status(http.OK).json({ imageURL: result.imageURL });
|
||||
}).catch((error) => {
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
const OAuth = require('oauth-1.0a');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const appConfig = require('../../config/app.json');
|
||||
const http = require('../../config/http');
|
||||
const errors = require('../../config/errors');
|
||||
const UUID = require('uuid/v4');
|
||||
const firebase = require('firebase-admin');
|
||||
|
||||
/**
|
||||
@ -81,22 +79,14 @@ function createOAuthHeader(request, app) {
|
||||
*
|
||||
* @returns {*} imageURL
|
||||
*/
|
||||
async function uploadImage(imageData, path, bucketName, res) {
|
||||
async function uploadImage(imageData, path, bucketName) {
|
||||
try {
|
||||
const bucket = await firebase.storage().bucket(`gs://${bucketName}`);
|
||||
const bucket = firebase.storage().bucket(`gs://${bucketName}`);
|
||||
|
||||
var file = bucket.file(`${path}.${appConfig.imageFormat[imageData.metaData.contentType]}`);
|
||||
const uuid = UUID();
|
||||
var imageBuffer = new Buffer(imageData.base64Data, 'base64');
|
||||
var imageBuffer = Buffer.from(imageData.base64Data, 'base64');
|
||||
|
||||
await file.save(imageBuffer, {
|
||||
metaData: {
|
||||
contentType: imageData.metaData.contentType,
|
||||
metadata: {
|
||||
firebaseStorageDownloadTokens: uuid
|
||||
}
|
||||
},
|
||||
public: true,
|
||||
validation: 'md5',
|
||||
});
|
||||
|
||||
@ -105,8 +95,7 @@ async function uploadImage(imageData, path, bucketName, res) {
|
||||
return fileMetaData[0].mediaLink;
|
||||
|
||||
} catch (error) {
|
||||
res.status(http.INTERNAL_SERVER_ERROR).json({error});
|
||||
return null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user