Add default metadata & make replaceFile function

This commit is contained in:
2025-06-01 16:36:29 -05:00
parent dc7cec8539
commit f49488123b
33 changed files with 194 additions and 51 deletions

View File

@ -1,7 +1,7 @@
'use client'
import { useState, useRef } from 'react';
import { deleteFile, uploadFile } from '@/lib/actions';
import { deleteFile, replaceFile, uploadFile } from '@/lib/actions';
import { toast } from 'sonner';
import { useAuth } from '@/components/context/auth';
import { resizeImage } from '@/lib/hooks';
@ -43,6 +43,21 @@ export const useFileUpload = () => {
console.error('Error deleting file:', deleteResult.error);
throw new Error(deleteResult.error || `Failed to delete ${prevPath}`);
} else console.log('Delete sucessful!')
console.log('Deleted file path: ', deleteResult.data)
const updateResult = await replaceFile({
bucket,
prevPath: prevPath,
file,
options: {
contentType: file.type,
},
});
if (!updateResult.success) {
console.error('Error updating file:', updateResult.error);
} else {
console.log('We used the new update function hopefully it worked!');
return { success: true, path: updateResult.data };
}
}
let fileToUpload = file;