-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[finishes #187354260] Created feature that will allow sellers to upda…
…te their products in stock modified: src/controllers/productsController.ts modified: src/helpers/claudinary.ts new file: src/helpers/destroyImage.ts new file: src/helpers/extractImageId.ts new file: src/middlewares/handleFileUploads.ts modified: src/routes/productRoutes.ts
- Loading branch information
1 parent
38f3a82
commit dc7bc15
Showing
6 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { v2 as cloudinary } from 'cloudinary'; | ||
|
||
cloudinary.config({ | ||
cloud_name: process.env.CLOUDINARY_NAME, | ||
api_key: process.env.CLOUDINARY_KEY, | ||
api_secret: process.env.CLOUDINARY_SECRET, | ||
}); | ||
|
||
export const destroyImage = async (public_id: string) => { | ||
return await cloudinary.uploader.destroy(public_id); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const extractImageId = (url: string) => { | ||
const regex = /\/([a-zA-Z0-9]+)\.[a-z]+$/; | ||
const match = url.match(regex); | ||
|
||
if (match && match[1]) { | ||
return match[1]; | ||
} else { | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NextFunction, Request, Response } from 'express'; | ||
import multerUpload from '../helpers/multer'; | ||
|
||
export const handleFileUploads = (req: Request, res: Response, next: NextFunction) => { | ||
if (req.files) { | ||
multerUpload.array('images', 8)(req, res, next); | ||
} else { | ||
multerUpload.single('image')(req, res, next); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters