Something went wrong. Try again.
A comprehensive digital solution dedicated to bridging the gap between those offering services and those seeking them, providing a centrali… gigwork.co.in
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
import { Hono } from 'hono';const router = new Hono();
import { verifyToken } from '../../middleware/authentication';
import { nanoid } from 'nanoid';import { profileMedia } from '../../config/database/schema';import { ProfileMedia } from '../../config/database/interfaces';
import { generatePreSignedUrl, addProfileMedia } from '../../services/media';
/** * @route GET /api/v1/media/get-presigned-url * @desc Generate a pre-signed URL for uploading media * @access Public * @params name, type * @return message, data * @error 400, { error } * @status 201, 400 * * @example /api/v1/media **/
router.get('/get-presigned-url', async (c) => { try { const type = c.req.query('type'); const category = c.req.query('category');
const categories = ['avatar', 'banner', 'media', 'license', 'identity']; const allowedFileTypes = ['image', 'video'];
if (!type || !category) { return c.json({ message: 'Type and Category are required' }, 400); }
if (!categories.includes(category)) { return c.json({ message: 'Invalid category' }, 400); }
if (!allowedFileTypes.includes(type.split('/')[0])) { return c.json({ message: 'Invalid file type' }, 400); }
const fileExtension = type.split('/')[1]; const path = `${category}/${nanoid()}${fileExtension ? `.${fileExtension}` : ''}`; const url = await generatePreSignedUrl(path, type, c.env);
if (!url) { return c.json({ message: 'Error generating pre-signed URL' }, 400); } return c.json({ message: 'Presigned URL generated successfully', data: { assetPath: path, presignedUrl: url } }, 201); } catch (error) { return c.json({ message: 'Internal Server Error', error: error.message }, 500); }});
module.exports = router;