@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/README.md +79 -116
- package/dist/cli.cjs +21 -16
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +18 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -278,8 +278,12 @@ import { randomBytes, timingSafeEqual } from "crypto";
|
|
|
278
278
|
import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
279
279
|
import { homedir } from "os";
|
|
280
280
|
import { join as join2 } from "path";
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
function configDir() {
|
|
282
|
+
return process.env.THREADBASE_CONFIG_DIR ?? join2(homedir(), ".threadbase");
|
|
283
|
+
}
|
|
284
|
+
function configFile() {
|
|
285
|
+
return join2(configDir(), "server.yaml");
|
|
286
|
+
}
|
|
283
287
|
function generateApiKey() {
|
|
284
288
|
return `tb_${randomBytes(16).toString("hex")}`;
|
|
285
289
|
}
|
|
@@ -291,20 +295,20 @@ function validateApiKey(provided, expected) {
|
|
|
291
295
|
}
|
|
292
296
|
function loadOrCreateApiKey() {
|
|
293
297
|
try {
|
|
294
|
-
const content = readFileSync(
|
|
298
|
+
const content = readFileSync(configFile(), "utf-8");
|
|
295
299
|
const match = content.match(/api_key:\s*(.+)/);
|
|
296
300
|
if (match?.[1]) return match[1].trim();
|
|
297
301
|
} catch {
|
|
298
302
|
}
|
|
299
303
|
const key = generateApiKey();
|
|
300
|
-
mkdirSync(
|
|
301
|
-
writeFileSync(
|
|
304
|
+
mkdirSync(configDir(), { recursive: true });
|
|
305
|
+
writeFileSync(configFile(), `api_key: ${key}
|
|
302
306
|
`, "utf-8");
|
|
303
307
|
return key;
|
|
304
308
|
}
|
|
305
309
|
function loadBrowseRoot() {
|
|
306
310
|
try {
|
|
307
|
-
const content = readFileSync(
|
|
311
|
+
const content = readFileSync(configFile(), "utf-8");
|
|
308
312
|
const match = content.match(/browse_root:\s*(.+)/);
|
|
309
313
|
if (match?.[1]) return match[1].trim();
|
|
310
314
|
} catch {
|
|
@@ -313,7 +317,7 @@ function loadBrowseRoot() {
|
|
|
313
317
|
}
|
|
314
318
|
function loadPublicUrl() {
|
|
315
319
|
try {
|
|
316
|
-
const content = readFileSync(
|
|
320
|
+
const content = readFileSync(configFile(), "utf-8");
|
|
317
321
|
const match = content.match(/public_url:\s*(.+)/);
|
|
318
322
|
if (match?.[1]) return match[1].trim();
|
|
319
323
|
} catch {
|
|
@@ -322,7 +326,7 @@ function loadPublicUrl() {
|
|
|
322
326
|
}
|
|
323
327
|
function loadCacheDir() {
|
|
324
328
|
try {
|
|
325
|
-
const content = readFileSync(
|
|
329
|
+
const content = readFileSync(configFile(), "utf-8");
|
|
326
330
|
const match = content.match(/cache_dir:\s*(.+)/);
|
|
327
331
|
if (match?.[1]) return match[1].trim();
|
|
328
332
|
} catch {
|
|
@@ -331,7 +335,7 @@ function loadCacheDir() {
|
|
|
331
335
|
}
|
|
332
336
|
function loadTailSize() {
|
|
333
337
|
try {
|
|
334
|
-
const content = readFileSync(
|
|
338
|
+
const content = readFileSync(configFile(), "utf-8");
|
|
335
339
|
const match = content.match(/tail_size:\s*(\d+)/);
|
|
336
340
|
if (match?.[1]) return Number.parseInt(match[1], 10);
|
|
337
341
|
} catch {
|
|
@@ -361,10 +365,11 @@ function stripTrailingSlash(url) {
|
|
|
361
365
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
362
366
|
}
|
|
363
367
|
function setApiKey(key) {
|
|
364
|
-
|
|
368
|
+
const file = configFile();
|
|
369
|
+
mkdirSync(configDir(), { recursive: true });
|
|
365
370
|
let content = "";
|
|
366
371
|
try {
|
|
367
|
-
content = readFileSync(
|
|
372
|
+
content = readFileSync(file, "utf-8");
|
|
368
373
|
} catch (err) {
|
|
369
374
|
if (err.code !== "ENOENT") throw err;
|
|
370
375
|
}
|
|
@@ -380,10 +385,10 @@ function setApiKey(key) {
|
|
|
380
385
|
${apiKeyLine}
|
|
381
386
|
`;
|
|
382
387
|
}
|
|
383
|
-
const tmpFile = `${
|
|
388
|
+
const tmpFile = `${file}.tmp`;
|
|
384
389
|
writeFileSync(tmpFile, updated, { encoding: "utf-8", mode: 384 });
|
|
385
390
|
chmodSync(tmpFile, 384);
|
|
386
|
-
renameSync(tmpFile,
|
|
391
|
+
renameSync(tmpFile, file);
|
|
387
392
|
}
|
|
388
393
|
|
|
389
394
|
// src/db/config.ts
|