|
1 | | -import { deleteGiftThumbnail } from '@/services/deleteImage'; |
2 | | -import { uploadGiftThumbnail } from '@/services/uploadImage'; |
| 1 | +import { deleteImageFromBucket } from '@/services/deleteImage'; |
| 2 | +import { uploadFileToBucket } from '@/services/uploadImage'; |
3 | 3 |
|
4 | 4 | /** |
5 | 5 | * Updates an image in Supabase storage by deleting the old image and uploading a new one. |
6 | 6 | * @param oldImageUrl - The public URL of the old image to delete. |
7 | 7 | * @param newImageUri - The URI of the new image to upload. |
8 | | - * @param bucketName - The name of the Supabase storage bucket (default: 'gift-thumbnail'). |
| 8 | + * @param bucketName - The name of the Supabase storage bucket. |
9 | 9 | * @returns The public URL of the new image. |
10 | 10 | */ |
11 | | -export const updateGiftThumbnail = async ( |
| 11 | +export const updateImageInBucket = async ( |
12 | 12 | oldImageUrl: string, |
13 | 13 | newImageUri: string, |
14 | | - bucketName: string = 'gift-thumbnail', |
| 14 | + bucketName: string, |
15 | 15 | ): Promise<string> => { |
16 | 16 | try { |
17 | 17 | if (oldImageUrl) { |
18 | | - await deleteGiftThumbnail(oldImageUrl, bucketName); |
| 18 | + await deleteImageFromBucket(oldImageUrl, bucketName); |
19 | 19 | } |
20 | 20 |
|
21 | | - const newImageUrl = await uploadGiftThumbnail(newImageUri, bucketName); |
| 21 | + const newImageUrl = await uploadFileToBucket(newImageUri, bucketName); |
22 | 22 |
|
23 | 23 | return newImageUrl; |
24 | 24 | } catch (error) { |
25 | 25 | console.error('Error updating image:', error); |
26 | 26 | throw new Error('Failed to update image'); |
27 | 27 | } |
28 | 28 | }; |
| 29 | + |
| 30 | +/** |
| 31 | + * Updates a gift thumbnail in Supabase storage. |
| 32 | + * @param oldImageUrl - The public URL of the old gift thumbnail to delete. |
| 33 | + * @param newImageUri - The URI of the new gift thumbnail to upload. |
| 34 | + * @param bucketName - The name of the Supabase storage bucket (default: 'gift-thumbnail'). |
| 35 | + * @returns The public URL of the new gift thumbnail. |
| 36 | + */ |
| 37 | +export const updateGiftThumbnail = async ( |
| 38 | + oldImageUrl: string, |
| 39 | + newImageUri: string, |
| 40 | + bucketName: string = 'gift-thumbnail', |
| 41 | +): Promise<string> => { |
| 42 | + return updateImageInBucket(oldImageUrl, newImageUri, bucketName); |
| 43 | +}; |
| 44 | + |
| 45 | +/** |
| 46 | + * Updates a recipient avatar in Supabase storage. |
| 47 | + * @param oldImageUrl - The public URL of the old recipient avatar to delete. |
| 48 | + * @param newImageUri - The URI of the new recipient avatar to upload. |
| 49 | + * @param bucketName - The name of the Supabase storage bucket (default: 'recipient-avatar'). |
| 50 | + * @returns The public URL of the new recipient avatar. |
| 51 | + */ |
| 52 | +export const updateRecipientAvatar = async ( |
| 53 | + oldImageUrl: string, |
| 54 | + newImageUri: string, |
| 55 | + bucketName: string = 'recipient-avatar', |
| 56 | +): Promise<string> => { |
| 57 | + return updateImageInBucket(oldImageUrl, newImageUri, bucketName); |
| 58 | +}; |
0 commit comments