JOHN SILLVESTOR commited on
Commit
3641cdd
·
verified ·
1 Parent(s): b497134

Stream: 206 for Range, warm tail, ETag, 15m tickets

Browse files
Files changed (1) hide show
  1. server.js +7 -5
server.js CHANGED
@@ -13,7 +13,7 @@ const API_HASH = process.env.TELEGRAM_API_HASH || "";
13
  const STREAM_SECRET = process.env.STREAM_SECRET || "";
14
  const ROLE = (process.env.NODE_ROLE || "stream").toLowerCase();
15
  const HASH_LEN = 6;
16
- const TOKEN_TTL = 600;
17
  const MIN_ALIGN = 4096;
18
  const MB = 1024 * 1024;
19
  const GET_SIZES = [524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096];
@@ -1067,26 +1067,28 @@ async function handleStream(req, res, url, msgId) {
1067
  return res.end();
1068
  }
1069
  const size = rec.size;
 
1070
  const rng = parseRange(req.headers.range, size);
 
1071
  const headers = {
1072
  "Content-Type": httpVideoType(rec.mime, rec.name),
1073
  "Accept-Ranges": "bytes",
1074
  "Cache-Control": "private, no-store, no-transform",
1075
  "Content-Disposition": "inline",
1076
  "Content-Encoding": "identity",
 
1077
  "X-Content-Type-Options": "nosniff",
1078
  "X-Accel-Buffering": "no"
1079
  };
1080
- const partial = rng.partial;
1081
  headers["Content-Length"] = String(rng.end - rng.start + 1);
1082
- if (partial) {
1083
  headers["Content-Range"] = "bytes " + rng.start + "-" + rng.end + "/" + size;
1084
  }
1085
  if (req.method === "HEAD") {
1086
- res.writeHead(partial ? 206 : 200, headers);
1087
  return res.end();
1088
  }
1089
- const status = partial ? 206 : 200;
1090
  try {
1091
  await pipeRange(bot, rec, rng.start, rng.end, req, res, status, headers, msgId);
1092
  } catch (e) {
 
13
  const STREAM_SECRET = process.env.STREAM_SECRET || "";
14
  const ROLE = (process.env.NODE_ROLE || "stream").toLowerCase();
15
  const HASH_LEN = 6;
16
+ const TOKEN_TTL = 900;
17
  const MIN_ALIGN = 4096;
18
  const MB = 1024 * 1024;
19
  const GET_SIZES = [524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096];
 
1067
  return res.end();
1068
  }
1069
  const size = rec.size;
1070
+ warmHot(bot, rec, msgId).catch(function () {});
1071
  const rng = parseRange(req.headers.range, size);
1072
+ const ranged = !!req.headers.range;
1073
  const headers = {
1074
  "Content-Type": httpVideoType(rec.mime, rec.name),
1075
  "Accept-Ranges": "bytes",
1076
  "Cache-Control": "private, no-store, no-transform",
1077
  "Content-Disposition": "inline",
1078
  "Content-Encoding": "identity",
1079
+ "ETag": '"' + msgId + "-" + size + "-" + (rec.hash || "x") + '"',
1080
  "X-Content-Type-Options": "nosniff",
1081
  "X-Accel-Buffering": "no"
1082
  };
 
1083
  headers["Content-Length"] = String(rng.end - rng.start + 1);
1084
+ if (ranged) {
1085
  headers["Content-Range"] = "bytes " + rng.start + "-" + rng.end + "/" + size;
1086
  }
1087
  if (req.method === "HEAD") {
1088
+ res.writeHead(ranged ? 206 : 200, headers);
1089
  return res.end();
1090
  }
1091
+ const status = ranged ? 206 : 200;
1092
  try {
1093
  await pipeRange(bot, rec, rng.start, rng.end, req, res, status, headers, msgId);
1094
  } catch (e) {