@threadbase-sh/streamer 1.22.0 → 1.22.1

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/cli.cjs CHANGED
@@ -1484,6 +1484,12 @@ var require_main2 = __commonJS({
1484
1484
  });
1485
1485
 
1486
1486
  // src/auth.ts
1487
+ function configDir() {
1488
+ return process.env.THREADBASE_CONFIG_DIR ?? (0, import_path.join)((0, import_os.homedir)(), ".threadbase");
1489
+ }
1490
+ function configFile() {
1491
+ return (0, import_path.join)(configDir(), "server.yaml");
1492
+ }
1487
1493
  function generateApiKey() {
1488
1494
  return `tb_${(0, import_crypto.randomBytes)(16).toString("hex")}`;
1489
1495
  }
@@ -1495,20 +1501,20 @@ function validateApiKey(provided, expected) {
1495
1501
  }
1496
1502
  function loadOrCreateApiKey() {
1497
1503
  try {
1498
- const content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
1504
+ const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
1499
1505
  const match2 = content.match(/api_key:\s*(.+)/);
1500
1506
  if (match2?.[1]) return match2[1].trim();
1501
1507
  } catch {
1502
1508
  }
1503
1509
  const key = generateApiKey();
1504
- (0, import_fs.mkdirSync)(CONFIG_DIR, { recursive: true });
1505
- (0, import_fs.writeFileSync)(CONFIG_FILE, `api_key: ${key}
1510
+ (0, import_fs.mkdirSync)(configDir(), { recursive: true });
1511
+ (0, import_fs.writeFileSync)(configFile(), `api_key: ${key}
1506
1512
  `, "utf-8");
1507
1513
  return key;
1508
1514
  }
1509
1515
  function loadBrowseRoot() {
1510
1516
  try {
1511
- const content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
1517
+ const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
1512
1518
  const match2 = content.match(/browse_root:\s*(.+)/);
1513
1519
  if (match2?.[1]) return match2[1].trim();
1514
1520
  } catch {
@@ -1517,7 +1523,7 @@ function loadBrowseRoot() {
1517
1523
  }
1518
1524
  function loadPublicUrl() {
1519
1525
  try {
1520
- const content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
1526
+ const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
1521
1527
  const match2 = content.match(/public_url:\s*(.+)/);
1522
1528
  if (match2?.[1]) return match2[1].trim();
1523
1529
  } catch {
@@ -1526,7 +1532,7 @@ function loadPublicUrl() {
1526
1532
  }
1527
1533
  function loadCacheDir() {
1528
1534
  try {
1529
- const content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
1535
+ const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
1530
1536
  const match2 = content.match(/cache_dir:\s*(.+)/);
1531
1537
  if (match2?.[1]) return match2[1].trim();
1532
1538
  } catch {
@@ -1535,7 +1541,7 @@ function loadCacheDir() {
1535
1541
  }
1536
1542
  function loadTailSize() {
1537
1543
  try {
1538
- const content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
1544
+ const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
1539
1545
  const match2 = content.match(/tail_size:\s*(\d+)/);
1540
1546
  if (match2?.[1]) return Number.parseInt(match2[1], 10);
1541
1547
  } catch {
@@ -1565,10 +1571,11 @@ function stripTrailingSlash(url2) {
1565
1571
  return url2.endsWith("/") ? url2.slice(0, -1) : url2;
1566
1572
  }
1567
1573
  function setApiKey(key) {
1568
- (0, import_fs.mkdirSync)(CONFIG_DIR, { recursive: true });
1574
+ const file2 = configFile();
1575
+ (0, import_fs.mkdirSync)(configDir(), { recursive: true });
1569
1576
  let content = "";
1570
1577
  try {
1571
- content = (0, import_fs.readFileSync)(CONFIG_FILE, "utf-8");
1578
+ content = (0, import_fs.readFileSync)(file2, "utf-8");
1572
1579
  } catch (err) {
1573
1580
  if (err.code !== "ENOENT") throw err;
1574
1581
  }
@@ -1584,12 +1591,12 @@ function setApiKey(key) {
1584
1591
  ${apiKeyLine}
1585
1592
  `;
1586
1593
  }
1587
- const tmpFile = `${CONFIG_FILE}.tmp`;
1594
+ const tmpFile = `${file2}.tmp`;
1588
1595
  (0, import_fs.writeFileSync)(tmpFile, updated, { encoding: "utf-8", mode: 384 });
1589
1596
  (0, import_fs.chmodSync)(tmpFile, 384);
1590
- (0, import_fs.renameSync)(tmpFile, CONFIG_FILE);
1597
+ (0, import_fs.renameSync)(tmpFile, file2);
1591
1598
  }
1592
- var import_crypto, import_fs, import_os, import_path, CONFIG_DIR, CONFIG_FILE;
1599
+ var import_crypto, import_fs, import_os, import_path;
1593
1600
  var init_auth = __esm({
1594
1601
  "src/auth.ts"() {
1595
1602
  "use strict";
@@ -1597,8 +1604,6 @@ var init_auth = __esm({
1597
1604
  import_fs = require("fs");
1598
1605
  import_os = require("os");
1599
1606
  import_path = require("path");
1600
- CONFIG_DIR = (0, import_path.join)((0, import_os.homedir)(), ".threadbase");
1601
- CONFIG_FILE = (0, import_path.join)(CONFIG_DIR, "server.yaml");
1602
1607
  }
1603
1608
  });
1604
1609
 
@@ -131423,8 +131428,8 @@ function writeSidecar(jsonlPath, sidecar) {
131423
131428
  }
131424
131429
  }
131425
131430
  var PROFILES_FILE = "profiles.json";
131426
- function resolveConfigDir(configDir) {
131427
- return configDir.replace(/^~/, (0, import_os4.homedir)());
131431
+ function resolveConfigDir(configDir2) {
131432
+ return configDir2.replace(/^~/, (0, import_os4.homedir)());
131428
131433
  }
131429
131434
  function getProjectsDir(profile) {
131430
131435
  return (0, import_path3.join)(resolveConfigDir(profile.configDir), "projects");