-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bamiwo-API-Doc' of https://github.com/bammietop03/hng_b…
…oilerplate_expressjs into bamiwo-API-Doc
- Loading branch information
Showing
30 changed files
with
1,249 additions
and
463 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
[Nainah23](https://github.com/Nainah23) | ||
Erasmus Tayviah (StarmannRassy) | ||
|
||
- [Nainah23](https://github.com/Nainah23) | ||
- Erasmus Tayviah (StarmannRassy) | ||
- [Adekolu Samuel Samixx](https://github.com/samixYasuke) |
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,16 @@ | ||
import * as cloudinary from "cloudinary"; | ||
import { ConfigOptions } from "cloudinary"; | ||
|
||
const cloudinaryConfig = ( | ||
cloudName: string, | ||
apiKey: string, | ||
apiSecret: string, | ||
): ConfigOptions => { | ||
return cloudinary.v2.config({ | ||
cloud_name: cloudName, | ||
api_key: apiKey, | ||
api_secret: apiSecret, | ||
}); | ||
}; | ||
|
||
export default cloudinaryConfig; |
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 |
---|---|---|
@@ -1,20 +1,31 @@ | ||
import config from "."; | ||
import passport from "passport"; | ||
import { Strategy as GoogleStrategy, Profile, VerifyCallback } from "passport-google-oauth2"; | ||
import { | ||
Strategy as GoogleStrategy, | ||
Profile, | ||
VerifyCallback, | ||
} from "passport-google-oauth2"; | ||
|
||
passport.use(new GoogleStrategy({ | ||
clientID: config.GOOGLE_CLIENT_ID, | ||
clientSecret: config.GOOGLE_CLIENT_SECRET, | ||
callbackURL: config.GOOGLE_AUTH_CALLBACK_URL | ||
}, | ||
async (_accessToken: string, _refreshToken: string, profile: Profile, done: VerifyCallback) => { | ||
try { | ||
return done(null, profile); | ||
} catch (error) { | ||
return done(error); | ||
} | ||
} | ||
)); | ||
passport.use( | ||
new GoogleStrategy( | ||
{ | ||
clientID: config.GOOGLE_CLIENT_ID, | ||
clientSecret: config.GOOGLE_CLIENT_SECRET, | ||
callbackURL: config.GOOGLE_AUTH_CALLBACK_URL, | ||
}, | ||
async ( | ||
_accessToken: string, | ||
_refreshToken: string, | ||
profile: Profile, | ||
done: VerifyCallback, | ||
) => { | ||
try { | ||
return done(null, profile); | ||
} catch (error) { | ||
return done(error); | ||
} | ||
}, | ||
), | ||
); | ||
|
||
|
||
export default passport; | ||
export default passport; |
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,47 @@ | ||
import multer from "multer"; | ||
import { v2 as cloudinary } from "cloudinary"; | ||
import { CloudinaryStorage } from "multer-storage-cloudinary"; | ||
import cloudinaryConfig from "./cloudinary"; | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
interface CustomParams { | ||
folder: string; | ||
allowedFormats: string[]; | ||
} | ||
|
||
const cloudinaryConfigOptions = cloudinaryConfig( | ||
process.env["CLOUDINARY_CLOUD_NAME"] as string, | ||
process.env["CLOUDINARY_API_KEY"] as string, | ||
process.env["CLOUDINARY_API_SECRET"] as string, | ||
); | ||
|
||
cloudinary.config(cloudinaryConfigOptions); | ||
|
||
const storage = new CloudinaryStorage({ | ||
cloudinary, | ||
params: { | ||
folder: "images", | ||
allowedFormats: ["jpg", "png", "jpeg"], | ||
} as CustomParams, | ||
}); | ||
|
||
const FILE_SIZE = 1024 * 1024 * 2; // 2MB | ||
|
||
export const multerConfig = multer({ | ||
storage, | ||
limits: { | ||
fileSize: FILE_SIZE, | ||
}, | ||
fileFilter: (_req, file, cb) => { | ||
if (!file.mimetype.startsWith("image/")) { | ||
return cb(new Error("Only images are allowed")); | ||
} | ||
if (file.size > FILE_SIZE) { | ||
return cb(new Error("Image should not be more than 4MB")); | ||
} | ||
cb(null, true); | ||
}, | ||
}); | ||
|
||
export { cloudinary }; |
Oops, something went wrong.