Spaces:
Running
Running
JOHN SILLVESTOR commited on
Accept /stream/id.mp4 for phone players
Browse files
server.js
CHANGED
|
@@ -289,9 +289,25 @@ function limited(ip) {
|
|
| 289 |
}
|
| 290 |
|
| 291 |
function isBlogOrigin(o) {
|
| 292 |
-
o = String(o || "").
|
| 293 |
-
if (o ===
|
| 294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
}
|
| 296 |
|
| 297 |
function fromBlog(req) {
|
|
@@ -981,7 +997,7 @@ async function handleGenerate(req, res, url) {
|
|
| 981 |
const k = sealTicket({ m: msgId, h: hash, u: uid || "anon", l: lvl, b: bot.idx, e: exp, s: rec.size, n: playMime, p: ipTag(ip) });
|
| 982 |
const host = "https://" + (req.headers.host || "localhost");
|
| 983 |
json(res, 200, {
|
| 984 |
-
url: host + "/stream/" + msgId + "?k=" + k,
|
| 985 |
fileSize: rec.size,
|
| 986 |
mime: playMime,
|
| 987 |
duration: rec.duration || 0,
|
|
@@ -1308,7 +1324,7 @@ async function onReq(req, res) {
|
|
| 1308 |
sweepBots();
|
| 1309 |
cors(req, res);
|
| 1310 |
if (req.method === "OPTIONS") {
|
| 1311 |
-
res.writeHead(204);
|
| 1312 |
return res.end();
|
| 1313 |
}
|
| 1314 |
let url;
|
|
@@ -1325,7 +1341,7 @@ async function onReq(req, res) {
|
|
| 1325 |
if (url.pathname === "/vip/start" && req.method === "POST") return handleVipStart(req, res);
|
| 1326 |
if (url.pathname === "/vip/go" && req.method === "POST") return handleVipGo(req, res);
|
| 1327 |
if (url.pathname === "/vip/stripe" && req.method === "POST") return handleStripeWebhook(req, res);
|
| 1328 |
-
const sm = /^\/stream\/(\d+)$/.exec(url.pathname);
|
| 1329 |
if (sm && (req.method === "GET" || req.method === "HEAD")) return handleStream(req, res, url, Number(sm[1]));
|
| 1330 |
res.writeHead(404);
|
| 1331 |
res.end();
|
|
|
|
| 289 |
}
|
| 290 |
|
| 291 |
function isBlogOrigin(o) {
|
| 292 |
+
o = String(o || "").trim();
|
| 293 |
+
if (!o || o.toLowerCase() === "null") return false;
|
| 294 |
+
try {
|
| 295 |
+
const u = new URL(o.includes("://") ? o : "https://" + o);
|
| 296 |
+
if (u.protocol !== "https:") return false;
|
| 297 |
+
const h = u.hostname.toLowerCase();
|
| 298 |
+
if (h === "dublk2000.blogspot.com" || h.endsWith(".dublk2000.blogspot.com")) return true;
|
| 299 |
+
const allow = String(ORIGIN || "").replace(/\/$/, "");
|
| 300 |
+
return allow && u.origin === allow;
|
| 301 |
+
} catch {
|
| 302 |
+
return false;
|
| 303 |
+
}
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
function playExt(mime, name) {
|
| 307 |
+
const t = httpVideoType(mime, name);
|
| 308 |
+
if (t.includes("webm")) return ".webm";
|
| 309 |
+
if (t.includes("ogg")) return ".ogv";
|
| 310 |
+
return ".mp4";
|
| 311 |
}
|
| 312 |
|
| 313 |
function fromBlog(req) {
|
|
|
|
| 997 |
const k = sealTicket({ m: msgId, h: hash, u: uid || "anon", l: lvl, b: bot.idx, e: exp, s: rec.size, n: playMime, p: ipTag(ip) });
|
| 998 |
const host = "https://" + (req.headers.host || "localhost");
|
| 999 |
json(res, 200, {
|
| 1000 |
+
url: host + "/stream/" + msgId + playExt(playMime, rec.name) + "?k=" + k,
|
| 1001 |
fileSize: rec.size,
|
| 1002 |
mime: playMime,
|
| 1003 |
duration: rec.duration || 0,
|
|
|
|
| 1324 |
sweepBots();
|
| 1325 |
cors(req, res);
|
| 1326 |
if (req.method === "OPTIONS") {
|
| 1327 |
+
res.writeHead(204, { "Content-Length": "0" });
|
| 1328 |
return res.end();
|
| 1329 |
}
|
| 1330 |
let url;
|
|
|
|
| 1341 |
if (url.pathname === "/vip/start" && req.method === "POST") return handleVipStart(req, res);
|
| 1342 |
if (url.pathname === "/vip/go" && req.method === "POST") return handleVipGo(req, res);
|
| 1343 |
if (url.pathname === "/vip/stripe" && req.method === "POST") return handleStripeWebhook(req, res);
|
| 1344 |
+
const sm = /^\/stream\/(\d+)(?:\.(?:mp4|m4v|webm|ogv|ogg))?$/.exec(url.pathname);
|
| 1345 |
if (sm && (req.method === "GET" || req.method === "HEAD")) return handleStream(req, res, url, Number(sm[1]));
|
| 1346 |
res.writeHead(404);
|
| 1347 |
res.end();
|