init
This commit is contained in:
commit
e3cfb58501
6
Dockerfile
Normal file
6
Dockerfile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
FROM node:18-alpine
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
COPY . .
|
||||||
|
EXPOSE 8888
|
||||||
|
CMD [ "node", "index.js" ]
|
54
index.js
Normal file
54
index.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import http from "http";
|
||||||
|
|
||||||
|
const unicodeToChar = (text) => {
|
||||||
|
return text.replace(/\\u[\dA-F]{4}/gi, function (match) {
|
||||||
|
return String.fromCharCode(parseInt(match.replace(/\\u/g, ""), 16));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
http
|
||||||
|
.createServer(async (request, response) => {
|
||||||
|
const responseBody = {
|
||||||
|
message: "ok",
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
let statusCode = 200;
|
||||||
|
|
||||||
|
let html;
|
||||||
|
try {
|
||||||
|
const res = await fetch("https://live.kankanews.com/live/8029037XEw6");
|
||||||
|
html = await res.text();
|
||||||
|
} catch (error) {
|
||||||
|
response.message = "fetch failed";
|
||||||
|
statusCode = 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pattern = /play_url:"(.*?)"/g;
|
||||||
|
let match = [];
|
||||||
|
let urls = [];
|
||||||
|
|
||||||
|
while ((match = pattern.exec(html)) !== null) {
|
||||||
|
if (match.length > 0) {
|
||||||
|
const playUrl = match[1];
|
||||||
|
const decodedUrl = unicodeToChar(playUrl);
|
||||||
|
|
||||||
|
urls.push(decodedUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (urls.length > 0) {
|
||||||
|
responseBody.data = {
|
||||||
|
urls,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
responseBody.message = "no urls";
|
||||||
|
statusCode = 404;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.writeHead(statusCode, { "Content-Type": "application/json" });
|
||||||
|
response.end(JSON.stringify(responseBody));
|
||||||
|
})
|
||||||
|
.listen(8888);
|
||||||
|
|
||||||
|
console.log("Server running at http://127.0.0.1:8888/");
|
13
package.json
Normal file
13
package.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "live-shanghai",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
Reference in New Issue
Block a user