Entry endpoints

This commit is contained in:
2024-10-11 01:30:52 -03:00
parent 9a245129e7
commit ce6cf91c77
7 changed files with 190 additions and 9 deletions

37
src/server/utils/index.ts Normal file
View File

@@ -0,0 +1,37 @@
import * as cloudinary from "cloudinary";
import { Entry } from "../api/routers/entry";
export const generateEntryUniqueKey = (entry: Entry): string => {
return `${entry.type}:${entry.name.trim().toLowerCase().replace(/\s/g, "-")}`;
};
export const uploadImage = async (
imagePath: string,
): Promise<string | unknown> => {
const options = {
use_filename: true,
unique_filename: false,
overwrite: true,
};
try {
const result = await cloudinary.v2.uploader.upload(imagePath, options);
console.log(result);
return result.public_id;
} catch (error) {
console.error(error);
return error;
}
};
export const makeImageSpooky = (publicId: string) => {
const options = { effect: "gen_background_replace" };
try {
const result = cloudinary.v2.image(publicId, { ...options });
console.log(result);
return result;
} catch (error) {
console.error(error);
}
};