mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 01:31:12 -05:00
Refactor: Implement avatar cleanup plan
This commit is contained in:
@@ -20,6 +20,54 @@ serve(async (req) => {
|
||||
throw new Error('Missing Cloudflare credentials')
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
// Delete image from Cloudflare
|
||||
const { imageId } = await req.json()
|
||||
|
||||
if (!imageId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Image ID is required for deletion' }),
|
||||
{
|
||||
status: 400,
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const deleteResponse = await fetch(
|
||||
`https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/images/v1/${imageId}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${CLOUDFLARE_IMAGES_API_TOKEN}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const deleteResult = await deleteResponse.json()
|
||||
|
||||
if (!deleteResponse.ok) {
|
||||
console.error('Cloudflare delete error:', deleteResult)
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: 'Failed to delete image',
|
||||
details: deleteResult.errors || deleteResult.error
|
||||
}),
|
||||
{
|
||||
status: 500,
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({ success: true, deleted: true }),
|
||||
{
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
// Request a direct upload URL from Cloudflare
|
||||
const { metadata = {}, variant = 'public' } = await req.json().catch(() => ({}))
|
||||
|
||||
Reference in New Issue
Block a user