{"size": 1071, "ext": "js", "max_stars_repo_path": "server/v2/src/utils/cloudinary.js", "max_stars_repo_name": "pin4eva/edfhr", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/v2/src/utils/cloudinary.js", "max_issues_repo_name": "pin4eva/edfhr", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/v2/src/utils/cloudinary.js", "max_forks_repo_name": "pin4eva/edfhr", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.42, "max_line_length": 70, "alphanum_fraction": 0.6255835668}
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */

import * as Cloudinary from "cloudinary";
import config from "./config";

export const cloudinary = Cloudinary.v2;

const options = {
  cloud_name: config.CLOUDINARY_NAME,
  api_key: config.CLOUDINARY_API_KEY,
  api_secret: config.CLOUDINARY_API_SECRET,
};

cloudinary.config(options);

export const cloudinaryUpload = async (image) => {
  try {
    const res = await cloudinary.uploader.upload(image, {
      fetch_format: "auto",
      crop: "scale",
      quality: "auto",
    });
    return res.secure_url;
  } catch (error) {
    console.log(error);
    throw new Error(error);
  }
};

export const uploadPDF = async (pdf) => {
  try {
    const res = await cloudinary.uploader.upload(pdf, {
      format: "pdf",
      fetch_format: "auto",
      crop: "scale",
      quality: "auto",
      transformation: {
        width: 800,
        crop: "scale",
        gravity: "auto",
      },
    });

    return res.url;
  } catch (error) {
    console.log(error);
    throw new Error(error);
  }
};
