JOHN SILLVESTOR commited on
Commit
97dcff4
·
verified ·
1 Parent(s): c5ad3fb

Include movie duration on stream tickets

Browse files
Files changed (1) hide show
  1. server.js +14 -2
server.js CHANGED
@@ -2112,7 +2112,10 @@ async function handleGenerate(req, res, url) {
2112
  const gk = path + "|" + hash + "|a|" + ipTag(ip) + "|" + uaTag(req.headers["user-agent"]);
2113
  const ghit = genAnonCache.get(gk);
2114
  if (ghit && ghit.body && ghit.body.u && ghit.exp > Date.now() + 8000) {
2115
- return json(res, 200, ghit.body);
 
 
 
2116
  }
2117
  }
2118
  if (limited(ip)) {
@@ -2154,7 +2157,16 @@ async function handleGenerate(req, res, url) {
2154
  durCache.set(hid, fromHot);
2155
  }
2156
  }
2157
- fillDuration(bot, rec, msgId).catch(() => { });
 
 
 
 
 
 
 
 
 
2158
  const cachedDur = durCache.get(hid);
2159
  if (cachedDur > 1) rec.duration = cachedDur;
2160
  const playMime = httpVideoType(rec.mime, rec.name);
 
2112
  const gk = path + "|" + hash + "|a|" + ipTag(ip) + "|" + uaTag(req.headers["user-agent"]);
2113
  const ghit = genAnonCache.get(gk);
2114
  if (ghit && ghit.body && ghit.body.u && ghit.exp > Date.now() + 8000) {
2115
+ const body = Object.assign({}, ghit.body);
2116
+ const cd = durCache.get(String(msgId));
2117
+ if (cd > 1) body.d = Math.floor(cd);
2118
+ return json(res, 200, body);
2119
  }
2120
  }
2121
  if (limited(ip)) {
 
2157
  durCache.set(hid, fromHot);
2158
  }
2159
  }
2160
+ if (!(durCache.get(hid) > 1) && !(Number(rec.duration) > 1)) {
2161
+ try {
2162
+ await Promise.race([
2163
+ fillDuration(bot, rec, msgId),
2164
+ new Promise((r) => setTimeout(r, 380))
2165
+ ]);
2166
+ } catch { }
2167
+ } else {
2168
+ fillDuration(bot, rec, msgId).catch(() => { });
2169
+ }
2170
  const cachedDur = durCache.get(hid);
2171
  if (cachedDur > 1) rec.duration = cachedDur;
2172
  const playMime = httpVideoType(rec.mime, rec.name);