@threadbase-sh/streamer 1.22.0 → 1.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -324,8 +324,12 @@ var import_crypto = require("crypto");
324
324
  var import_fs = require("fs");
325
325
  var import_os = require("os");
326
326
  var import_path = require("path");
327
- var CONFIG_DIR = (0, import_path.join)((0, import_os.homedir)(), ".threadbase");
328
- var CONFIG_FILE = (0, import_path.join)(CONFIG_DIR, "server.yaml");
327
+ function configDir() {
328
+ return process.env.THREADBASE_CONFIG_DIR ?? (0, import_path.join)((0, import_os.homedir)(), ".threadbase");
329
+ }
330
+ function configFile() {
331
+ return (0, import_path.join)(configDir(), "server.yaml");
332
+ }
329
333
  function generateApiKey() {
330
334
  return `tb_${(0, import_crypto.randomBytes)(16).toString("hex")}`;
331
335
  }
@@ -337,20 +341,20 @@ function validateApiKey(provided, expected) {
337
341
  }
338
342
  function loadOrCreateApiKey() {
339
343
  try {
340
- const content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
344
+ const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
341
345
  const match = content.match(/api_key:\s*(.+)/);
342
346
  if (match?.[1]) return match[1].trim();
343
347
  } catch {
344
348
  }
345
349
  const key = generateApiKey();
346
- (0, import_fs.mkdirSync)(CONFIG_DIR, { recursive: true });
347
- (0, import_fs.writeFileSync)(CONFIG_FILE, `api_key: ${key}
350
+ (0, import_fs.mkdirSync)(configDir(), { recursive: true });
351
+ (0, import_fs.writeFileSync)(configFile(), `api_key: ${key}
348
352
  `, "utf-8");
349
353
  return key;
350
354
  }
351
355
  function loadBrowseRoot() {
352
356
  try {
353
- const content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
357
+ const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
354
358
  const match = content.match(/browse_root:\s*(.+)/);
355
359
  if (match?.[1]) return match[1].trim();
356
360
  } catch {
@@ -359,7 +363,7 @@ function loadBrowseRoot() {
359
363
  }
360
364
  function loadPublicUrl() {
361
365
  try {
362
- const content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
366
+ const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
363
367
  const match = content.match(/public_url:\s*(.+)/);
364
368
  if (match?.[1]) return match[1].trim();
365
369
  } catch {
@@ -368,7 +372,7 @@ function loadPublicUrl() {
368
372
  }
369
373
  function loadCacheDir() {
370
374
  try {
371
- const content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
375
+ const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
372
376
  const match = content.match(/cache_dir:\s*(.+)/);
373
377
  if (match?.[1]) return match[1].trim();
374
378
  } catch {
@@ -377,7 +381,7 @@ function loadCacheDir() {
377
381
  }
378
382
  function loadTailSize() {
379
383
  try {
380
- const content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
384
+ const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
381
385
  const match = content.match(/tail_size:\s*(\d+)/);
382
386
  if (match?.[1]) return Number.parseInt(match[1], 10);
383
387
  } catch {
@@ -407,10 +411,11 @@ function stripTrailingSlash(url) {
407
411
  return url.endsWith("/") ? url.slice(0, -1) : url;
408
412
  }
409
413
  function setApiKey(key) {
410
- (0, import_fs.mkdirSync)(CONFIG_DIR, { recursive: true });
414
+ const file = configFile();
415
+ (0, import_fs.mkdirSync)(configDir(), { recursive: true });
411
416
  let content = "";
412
417
  try {
413
- content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
418
+ content = (0, import_fs.readFileSync)(file, "utf-8");
414
419
  } catch (err) {
415
420
  if (err.code !== "ENOENT") throw err;
416
421
  }
@@ -426,10 +431,10 @@ function setApiKey(key) {
426
431
  ${apiKeyLine}
427
432
  `;
428
433
  }
429
- const tmpFile = `${CONFIG_FILE}.tmp`;
434
+ const tmpFile = `${file}.tmp`;
430
435
  (0, import_fs.writeFileSync)(tmpFile, updated, { encoding: "utf-8", mode: 384 });
431
436
  (0, import_fs.chmodSync)(tmpFile, 384);
432
- (0, import_fs.renameSync)(tmpFile, CONFIG_FILE);
437
+ (0, import_fs.renameSync)(tmpFile, file);
433
438
  }
434
439
 
435
440
  // src/db/config.ts