mirror of
https://github.com/FranP-code/spooky-spotify-showcase.git
synced 2025-10-13 00:02:36 +00:00
Entry endpoints
This commit is contained in:
37
src/server/utils/index.ts
Normal file
37
src/server/utils/index.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user