forked from x-dr/telegraph-Image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtencent.js
76 lines (62 loc) · 2.03 KB
/
tencent.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
export async function onRequestPost(context) {
const { request, env } = context;
const url = new URL(request.url);
const clientIP = request.headers.get("x-forwarded-for") || request.headers.get("clientIP");
const Referer = request.headers.get('Referer') || "Referer";
const res_img = await fetch('https://openai.weixin.qq.com/weixinh5/webapp/h774yvzC2xlB4bIgGfX2stc4kvC85J/cos/upload', {
method: "POST",
headers: request.headers,
body: request.body
});
const options = {
timeZone: 'Asia/Shanghai',
year: 'numeric',
month: 'long',
day: 'numeric',
hour12: false,
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
const timedata = new Date();
const formattedDate = new Intl.DateTimeFormat('zh-CN', options).format(timedata);
const responseData = await res_img.json();
// console.log(responseData);
try {
const name = responseData.filekey;
const _URL = responseData.url;
if (env.IMG) {
await insertImageData(env.IMG, _URL, Referer, clientIP, 7, formattedDate);
}
return Response.json({
"success": true,
"data": {
"msg": "success",
"uploadPath": _URL,
"filename": name
}
}, {
headers: { 'Content-Type': 'application/json' }
});
} catch (e) {
return Response.json({
"success": false,
"data": {
"msg": e,
"filename": "",
"uploadPath": "_URL",
}
}, {
headers: { 'Content-Type': 'application/json' }
});
}
}
async function insertImageData(env, src, referer, ip, rating, time) {
try {
const instdata = await env.prepare(
`INSERT INTO imginfo (url, referer, ip, rating, total, time)
VALUES ('${src}', '${referer}', '${ip}', ${rating}, 1, '${time}')`
).run();
} catch (error) {
}
}