JOHN SILLVESTOR commited on
Commit
6ccedcb
·
verified ·
1 Parent(s): 75e9d7e

Improve stream range lookahead and pipe error resilience

Browse files
Files changed (1) hide show
  1. server.js +26 -9
server.js CHANGED
@@ -11,7 +11,7 @@ const { TelegramClient, Api } = require("teleproto");
11
  const { StringSession } = require("teleproto/sessions");
12
 
13
  const PORT = Number(process.env.PORT || 7860);
14
- const ORIGIN = process.env.ALLOWED_ORIGIN || "https://dublk2000.blogspot.com";
15
  const CHANNEL_ID = process.env.TELEGRAM_CHANNEL_ID || "";
16
  const API_ID = Number(process.env.TELEGRAM_API_ID || 0);
17
  const API_HASH = process.env.TELEGRAM_API_HASH || "";
@@ -87,7 +87,7 @@ const PLANS = {
87
  week: { amount: 199, label: "1 Week VIP", sec: 604800, price: "1.99" },
88
  month: { amount: 599, label: "1 Month VIP", sec: 2592000, price: "5.99" }
89
  };
90
- const HOME_URL = "https://dublk2000.blogspot.com/";
91
  const BRAND_FILE = path.join(__dirname, "brand.png");
92
  const BRAND_URL = (SPACE_URLS[0] || SPACE_FALLBACK[0]) + "/public/brand.png";
93
 
@@ -100,6 +100,22 @@ const adminKey = deriveKey ? Buffer.from(deriveKey("admin-api-v1")).toString("he
100
  const ADMIN_KEY_ENV = String(process.env.ADMIN_API_KEY || "");
101
  const ADMIN_KEY = ADMIN_KEY_ENV || adminKey;
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  const bots = [];
104
  const botSlots = [];
105
  const fileCache = new Map();
@@ -548,7 +564,7 @@ function isBlogOrigin(o) {
548
  if (u.protocol !== "https:" || u.username || u.password) return false;
549
  if (u.port && u.port !== "443") return false;
550
  const h = u.hostname.toLowerCase();
551
- if (h === "dublk2000.blogspot.com") return true;
552
  const allow = String(ORIGIN || "").replace(/\/$/, "");
553
  if (!allow) return false;
554
  const au = new URL(allow);
@@ -2130,8 +2146,8 @@ async function handleGenerate(req, res) {
2130
  try {
2131
  const raw = JSON.parse((await readBody(req, 4096)).toString("utf8") || "{}");
2132
  if (raw && raw.enc) {
2133
- const oHeader = req.headers.origin || req.headers.referer || "";
2134
- let dom = "dublk2000.blogspot.com";
2135
  try { if (oHeader) dom = new URL(oHeader.includes("://") ? oHeader : "https://" + oHeader).hostname; } catch { }
2136
  const decReq = (enc, d) => {
2137
  try {
@@ -2147,7 +2163,7 @@ async function handleGenerate(req, res) {
2147
  return JSON.parse(out.join(""));
2148
  } catch { return null; }
2149
  };
2150
- const parsed = decReq(raw.enc, dom) || decReq(raw.enc, "dublk2000.blogspot.com");
2151
  if (parsed) {
2152
  if (parsed.p) path = String(parsed.p);
2153
  if (parsed.h) hash = String(parsed.h).toLowerCase();
@@ -2491,7 +2507,7 @@ function blogReturn(u) {
2491
  const p = new URL(String(u || ""), ORIGIN);
2492
  if (p.protocol !== "https:" || p.username || p.password) return ORIGIN + "/";
2493
  if (p.port && p.port !== "443") return ORIGIN + "/";
2494
- if (p.hostname.toLowerCase() !== "dublk2000.blogspot.com") return ORIGIN + "/";
2495
  const mobile = p.searchParams.get("m") === "1" ? "?m=1" : "";
2496
  return p.origin + p.pathname + mobile;
2497
  } catch {
@@ -3126,7 +3142,7 @@ async function handleStripeWebhook(req, res) {
3126
  }
3127
 
3128
  const FB_CLIENT_CFG = {
3129
- apiKey: "AIzaSyCho6yF39MqCrWitmDqXnuBtbP6aANQ8EA",
3130
  authDomain: "dublk2000-auth.firebaseapp.com",
3131
  databaseURL: "wss://dublk2000-auth-default-rtdb.firebaseio.com/",
3132
  projectId: "dublk2000-auth",
@@ -3157,8 +3173,9 @@ async function handleBootstrap(req, res, url) {
3157
  fb: FB_CLIENT_CFG,
3158
  gc: G_CLIENT_ID
3159
  };
 
3160
  json(res, 200, {
3161
- p: encDomain(JSON.stringify(bundle), "dublk2000.blogspot.com")
3162
  }, "private, max-age=30");
3163
  }
3164
 
 
11
  const { StringSession } = require("teleproto/sessions");
12
 
13
  const PORT = Number(process.env.PORT || 7860);
14
+ const ORIGIN = process.env.ALLOWED_ORIGIN || "https://dublk20000.blogspot.com";
15
  const CHANNEL_ID = process.env.TELEGRAM_CHANNEL_ID || "";
16
  const API_ID = Number(process.env.TELEGRAM_API_ID || 0);
17
  const API_HASH = process.env.TELEGRAM_API_HASH || "";
 
87
  week: { amount: 199, label: "1 Week VIP", sec: 604800, price: "1.99" },
88
  month: { amount: 599, label: "1 Month VIP", sec: 2592000, price: "5.99" }
89
  };
90
+ const HOME_URL = "https://dublk20000.blogspot.com/";
91
  const BRAND_FILE = path.join(__dirname, "brand.png");
92
  const BRAND_URL = (SPACE_URLS[0] || SPACE_FALLBACK[0]) + "/public/brand.png";
93
 
 
100
  const ADMIN_KEY_ENV = String(process.env.ADMIN_API_KEY || "");
101
  const ADMIN_KEY = ADMIN_KEY_ENV || adminKey;
102
 
103
+ const BLOG_HOSTS = new Set([
104
+ "dublk2000.blogspot.com",
105
+ "dublk20000.blogspot.com",
106
+ "dublk2000.pages.dev"
107
+ ]);
108
+
109
+ function blogHostOf(req) {
110
+ const o = String((req && req.headers && (req.headers.origin || req.headers.referer)) || "");
111
+ try {
112
+ if (!o) return "";
113
+ return new URL(o.includes("://") ? o : "https://" + o).hostname.toLowerCase();
114
+ } catch {
115
+ return "";
116
+ }
117
+ }
118
+
119
  const bots = [];
120
  const botSlots = [];
121
  const fileCache = new Map();
 
564
  if (u.protocol !== "https:" || u.username || u.password) return false;
565
  if (u.port && u.port !== "443") return false;
566
  const h = u.hostname.toLowerCase();
567
+ if (BLOG_HOSTS.has(h)) return true;
568
  const allow = String(ORIGIN || "").replace(/\/$/, "");
569
  if (!allow) return false;
570
  const au = new URL(allow);
 
2146
  try {
2147
  const raw = JSON.parse((await readBody(req, 4096)).toString("utf8") || "{}");
2148
  if (raw && raw.enc) {
2149
+ const reqHost = blogHostOf(req);
2150
+ const dom = BLOG_HOSTS.has(reqHost) ? reqHost : "dublk20000.blogspot.com";
2151
  try { if (oHeader) dom = new URL(oHeader.includes("://") ? oHeader : "https://" + oHeader).hostname; } catch { }
2152
  const decReq = (enc, d) => {
2153
  try {
 
2163
  return JSON.parse(out.join(""));
2164
  } catch { return null; }
2165
  };
2166
+ const parsed = decReq(raw.enc, dom) || decReq(raw.enc, "dublk20000.blogspot.com") || decReq(raw.enc, "dublk2000.blogspot.com");
2167
  if (parsed) {
2168
  if (parsed.p) path = String(parsed.p);
2169
  if (parsed.h) hash = String(parsed.h).toLowerCase();
 
2507
  const p = new URL(String(u || ""), ORIGIN);
2508
  if (p.protocol !== "https:" || p.username || p.password) return ORIGIN + "/";
2509
  if (p.port && p.port !== "443") return ORIGIN + "/";
2510
+ if (!BLOG_HOSTS.has(p.hostname.toLowerCase())) return ORIGIN + "/";
2511
  const mobile = p.searchParams.get("m") === "1" ? "?m=1" : "";
2512
  return p.origin + p.pathname + mobile;
2513
  } catch {
 
3142
  }
3143
 
3144
  const FB_CLIENT_CFG = {
3145
+ apiKey: "AIzaSyAxMYsWapi7dgHq6DBBBF9j3wHHqgmgDjc",
3146
  authDomain: "dublk2000-auth.firebaseapp.com",
3147
  databaseURL: "wss://dublk2000-auth-default-rtdb.firebaseio.com/",
3148
  projectId: "dublk2000-auth",
 
3173
  fb: FB_CLIENT_CFG,
3174
  gc: G_CLIENT_ID
3175
  };
3176
+ const dom = BLOG_HOSTS.has(blogHostOf(req)) ? blogHostOf(req) : "dublk20000.blogspot.com";
3177
  json(res, 200, {
3178
+ p: encDomain(JSON.stringify(bundle), dom)
3179
  }, "private, max-age=30");
3180
  }
3181