Skip to content

Commit d866332

Browse files
Removed generateUrl method
1 parent 3685b64 commit d866332

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

services/imageService.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const DatauriParser = require('datauri/parser')
22
const userModel = require('../models/users')
3-
const { upload, generateUrl } = require('../utils/cloudinary')
3+
const { upload } = require('../utils/cloudinary')
44
const cloudinaryMetaData = require('../constants/cloudinary')
55

66
/**
@@ -15,16 +15,12 @@ const uploadProfilePicture = async (file, userId) => {
1515
const imageDataUri = parser.format(file.originalname, file.buffer)
1616
const imageDataInBase64 = imageDataUri.content
1717
const uploadResponse = await upload(imageDataInBase64, {
18-
folder: cloudinaryMetaData.PROFILE.FOLDER,
18+
folder: `${cloudinaryMetaData.PROFILE.FOLDER}/${userId}`,
1919
tags: cloudinaryMetaData.PROFILE.TAGS
2020
})
21-
const url = await generateUrl(uploadResponse.public_id)
22-
const imageData = {
23-
publicId: uploadResponse.public_id,
24-
url
25-
}
26-
await userModel.updateUserPicture(imageData, userId)
27-
return imageData
21+
const { public_id: publicId, secure_url: url } = uploadResponse
22+
await userModel.updateUserPicture({ publicId, url }, userId)
23+
return { publicId, url }
2824
} catch (err) {
2925
logger.error(`Error while uploading profile picture ${err}`)
3026
throw err

utils/cloudinary.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ const upload = async (file, options = {}) => {
88
return response
99
}
1010

11-
const generateUrl = async (publicId, transformations = {}) => {
12-
const url = cloudinary.url(publicId, transformations)
13-
return url
14-
}
15-
1611
module.exports = {
17-
upload,
18-
generateUrl
12+
upload
1913
}

0 commit comments

Comments
 (0)