@@ -11,18 +11,24 @@ const app = new Hono()
11
11
12
12
app . get ( '/test/:videoId' , async ( c ) => {
13
13
const { videoId } = c . req . param ( )
14
- const awemeId = await scrapeVideoData ( videoId )
15
14
16
- if ( awemeId instanceof Error ) {
17
- return new Response ( ( awemeId as Error ) . message , { status : 500 } )
18
- }
15
+ try {
16
+ const videoData = await scrapeVideoData ( videoId )
19
17
20
- return new Response ( JSON . stringify ( awemeId ) , {
21
- status : 200 ,
22
- headers : {
23
- 'Content-Type' : 'application/json; charset=utf-8'
24
- }
25
- } )
18
+ return new Response ( JSON . stringify ( videoData ) , {
19
+ status : 200 ,
20
+ headers : {
21
+ 'Content-Type' : 'application/json; charset=utf-8'
22
+ }
23
+ } )
24
+ } catch ( e ) {
25
+ return new Response ( ( e as Error ) . message , {
26
+ status : 500 ,
27
+ headers : {
28
+ 'Content-Type' : 'text/plain; charset=utf-8'
29
+ }
30
+ } )
31
+ }
26
32
} )
27
33
28
34
app . get ( '/' , ( c ) => {
@@ -59,7 +65,7 @@ async function handleVideo(c: any): Promise<Response> {
59
65
id = awemeId
60
66
} catch ( e ) {
61
67
const responseContent = await ErrorResponse ( ( e as Error ) . message )
62
- return returnHTMLResponse ( responseContent , 201 )
68
+ return returnHTMLResponse ( responseContent , 500 )
63
69
}
64
70
}
65
71
@@ -68,7 +74,7 @@ async function handleVideo(c: any): Promise<Response> {
68
74
69
75
if ( videoInfo instanceof Error ) {
70
76
const responseContent = await ErrorResponse ( ( videoInfo as Error ) . message )
71
- return returnHTMLResponse ( responseContent , 201 )
77
+ return returnHTMLResponse ( responseContent , 500 )
72
78
}
73
79
74
80
const url = new URL ( c . req . url )
@@ -99,9 +105,8 @@ async function handleVideo(c: any): Promise<Response> {
99
105
return returnHTMLResponse ( responseContent )
100
106
}
101
107
} catch ( e ) {
102
- console . log ( e )
103
108
const responseContent = await ErrorResponse ( ( e as Error ) . message )
104
- return returnHTMLResponse ( responseContent , 201 )
109
+ return returnHTMLResponse ( responseContent , 500 )
105
110
}
106
111
}
107
112
@@ -116,21 +121,13 @@ app.get('/generate/alternate', (c) => {
116
121
} )
117
122
} )
118
123
119
- app . get (
120
- '/generate/*' ,
121
- cache ( {
122
- cacheName : 'my-app' ,
123
- cacheControl : 'max-age=3600'
124
- } )
125
- )
126
-
127
124
app . get ( '/generate/video/:videoId' , async ( c ) => {
128
125
const { videoId } = c . req . param ( )
129
126
130
127
try {
131
- /*
132
- const data = await scrapeVideoData(videoId);
128
+ const data = await scrapeVideoData ( videoId )
133
129
130
+ /*
134
131
if (!(data instanceof Error)) {
135
132
if(data.video.playAddr) {
136
133
return c.redirect(data.video.playAddr)
@@ -143,6 +140,7 @@ app.get('/generate/video/:videoId', async (c) => {
143
140
}
144
141
}
145
142
*/
143
+
146
144
return c . redirect ( `https://tikwm.com/video/media/play/${ videoId } .mp4` )
147
145
} catch ( e ) {
148
146
return new Response ( ( e as Error ) . message , {
@@ -158,9 +156,9 @@ app.get('/generate/image/:videoId', async (c) => {
158
156
const { videoId } = c . req . param ( )
159
157
160
158
try {
161
- /*
162
- const data = await scrapeVideoData(videoId);
159
+ const data = await scrapeVideoData ( videoId )
163
160
161
+ /*
164
162
if (!(data instanceof Error)) {
165
163
if(data.imagePost.images.length > 0) {
166
164
return c.redirect(data.imagePost.images[0].imageURL.urlList[0])
@@ -169,6 +167,7 @@ app.get('/generate/image/:videoId', async (c) => {
169
167
}
170
168
}
171
169
*/
170
+
172
171
return c . redirect ( `https://tikwm.com/video/cover/${ videoId } .webp` )
173
172
} catch ( e ) {
174
173
return new Response ( ( e as Error ) . message , {
0 commit comments