-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
/
route.ts
42 lines (33 loc) 路 943 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Imgur } from './imgur';
const updateByImgur = async ({ url, blob }: { blob?: Blob; url?: string }) => {
let imageBlob: Blob;
if (url) {
const res = await fetch(url);
imageBlob = await res.blob();
} else if (blob) {
imageBlob = blob;
} else {
// TODO: error handle
return;
}
const imgur = new Imgur();
return await imgur.upload(imageBlob);
};
export const POST = async (req: Request) => {
const { url } = await req.json();
const cdnUrl = await updateByImgur({ url });
return new Response(JSON.stringify({ url: cdnUrl }));
};
// import { Imgur } from './imgur';
export const runtime = 'edge';
// export const POST = async (req: Request) => {
// const { url } = await req.json();
//
// const imgur = new Imgur();
//
// const image = await fetch(url);
//
// const cdnUrl = await imgur.upload(await image.blob());
//
// return new Response(JSON.stringify({ url: cdnUrl }));
// };