Mxiaodang commited on
Commit
e548a18
·
verified ·
1 Parent(s): 77e09fe

Create serve.ts

Browse files
Files changed (1) hide show
  1. serve.ts +22 -0
serve.ts ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {getVideoUrl,getVideoInfo} from "./douyin.ts";
2
+
3
+ const handler = async (req:Request) => {
4
+ console.log("Method:", req.method);
5
+
6
+ const url = new URL(req.url);
7
+ if (url.searchParams.has("url")) {
8
+ const inputUrl = url.searchParams.get("url")!;
9
+ console.log("inputUrl:", inputUrl);
10
+ // 返回完成json数据
11
+ if (url.searchParams.has("data")) {
12
+ const videoInfo = await getVideoInfo(inputUrl);
13
+ return new Response(JSON.stringify(videoInfo));
14
+ }
15
+ const videoUrl = await getVideoUrl(inputUrl);
16
+ return new Response(videoUrl);
17
+ } else {
18
+ return new Response("请提供url参数");
19
+ }
20
+ }
21
+
22
+ export {handler}