Skip to content

feat: update product #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open
14 changes: 7 additions & 7 deletions src/config/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from ".";

const APP_CONFIG = Object.freeze({
USE_HTTPS: config.NODE_ENV !== "development" ? true : false,
});

export default APP_CONFIG;
import config from ".";
const APP_CONFIG = Object.freeze({
USE_HTTPS: config.NODE_ENV !== "development" ? true : false,
});
export default APP_CONFIG;
32 changes: 16 additions & 16 deletions src/config/cloudinary.ts
Original file line number Diff line number Diff line change
@@ -1,16 +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;
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;
92 changes: 46 additions & 46 deletions src/config/google.passport.config.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import passport from "passport";
import {
Strategy as GoogleStrategy,
Profile,
VerifyCallback,
} from "passport-google-oauth2";
import config from ".";

import { OAuth2Client } from "google-auth-library";
const client = new OAuth2Client();

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 async function verifyToken(idToken: string) {
const ticket = await client.verifyIdToken({
idToken,
audience: process.env.GOOGLE_CLIENT_ID,
});
const payload = ticket.getPayload();
if (!payload) {
throw new Error("Unable to verify token");
}
return payload;
}
import passport from "passport";
import {
Strategy as GoogleStrategy,
Profile,
VerifyCallback,
} from "passport-google-oauth2";
import config from ".";
import { OAuth2Client } from "google-auth-library";
const client = new OAuth2Client();
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 async function verifyToken(idToken: string) {
const ticket = await client.verifyIdToken({
idToken,
audience: process.env.GOOGLE_CLIENT_ID,
});
const payload = ticket.getPayload();
if (!payload) {
throw new Error("Unable to verify token");
}
return payload;
}
94 changes: 47 additions & 47 deletions src/config/multer.ts
Original file line number Diff line number Diff line change
@@ -1,47 +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 };
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 };
Loading
Loading