generated from taylorbryant/gatsby-starter-tailwind
-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathroute.ts
24 lines (21 loc) · 787 Bytes
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { NextRequest, NextResponse } from 'next/server'
import { withUserAuth } from '@/js/auth/withUserAuth'
import { deleteMediaFromBucket } from '@/js/media/storageClient'
import { getBucketPathFromRequest } from '../get-signed-url/route'
/**
* Endpoint for removing a media object from remote cloud storage
*/
const postHandler = async (req: NextRequest): Promise<any> => {
try {
const filename = getBucketPathFromRequest(req)
if (filename == null) {
return NextResponse.json({ status: 400 })
}
await deleteMediaFromBucket(filename)
return NextResponse.json({ status: 200 })
} catch (e) {
console.log('Removing file from media server failed', e)
return NextResponse.json({ status: 500 })
}
}
export const POST = withUserAuth(postHandler)