Guest User

Untitled

a guest
Sep 18th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import { action } from "./_generated/server";
  2. import { v } from "convex/values";
  3.  
  4. export const generateThumbnailAction = action({
  5. args: { prompt: v.string() },
  6. handler: async (_, { prompt }) => {
  7. try {
  8. const options = {
  9. method: 'POST',
  10. headers: { 'x-freepik-api-key': `${process.env.FREEPIK_API_KEY}`, 'Content-Type': 'application/json', Accept: 'application/json' },
  11. body: JSON.stringify({ prompt, num_images: 1 }),
  12. };
  13.  
  14. const response = await fetch('https://api.freepik.com/v1/ai/text-to-image', options);
  15. const resJson = await response.json();
  16. const base64 = resJson.data[0].base64
  17. const imgUrl = `data:image/png;base64,${base64}`
  18. console.log(imgUrl);
  19. return imgUrl;
  20.  
  21. } catch (error) {
  22. console.error('Error generating Thumbnail:', error);
  23. throw error;
  24. }
  25. }
  26. })
Add Comment
Please, Sign In to add comment