@psychout98/tadaima 1.0.11 → 1.1.0

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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- var pkg = { version: "1.0.11" };
4
+ var pkg = { version: "1.1.0" };
5
5
  var args = process.argv.slice(2);
6
6
  var command = args[0];
7
7
  async function main() {
@@ -23,12 +23,11 @@ async function main() {
23
23
  const { DownloadHandler } = await import("./download-handler-3RP5BP6P.js");
24
24
  const { TUI } = await import("./tui-ZE4672PT.js");
25
25
  const { shouldCheckNow, checkForUpdate, applyUpdate, logUpdateAdvisory } = await import("./updater-LSMAQIFU.js");
26
- const { writeStatus, removeStatus } = await import("./status-writer-RGH2PULB.js");
26
+ const { writeStatusFile, removeStatusFile, STATUS_HEARTBEAT_INTERVAL_MS } = await import("./status-file-JMCUSEZR.js");
27
27
  const ws = new AgentWebSocket();
28
28
  const handler = new DownloadHandler(ws);
29
29
  const tui = new TUI(pkg.version);
30
30
  let wsConnected = false;
31
- let pendingUpdateVersion = null;
32
31
  let pendingUpdate = null;
33
32
  const tryApplyUpdate = async () => {
34
33
  if (!pendingUpdate) return;
@@ -42,7 +41,6 @@ async function main() {
42
41
  );
43
42
  }
44
43
  pendingUpdate = null;
45
- pendingUpdateVersion = null;
46
44
  };
47
45
  const runUpdateCheck = async () => {
48
46
  try {
@@ -54,7 +52,6 @@ async function main() {
54
52
  return;
55
53
  }
56
54
  pendingUpdate = result;
57
- pendingUpdateVersion = result.version;
58
55
  await tryApplyUpdate();
59
56
  }
60
57
  } catch (err) {
@@ -85,35 +82,35 @@ async function main() {
85
82
  });
86
83
  ws.connect();
87
84
  const { config: agentConfig } = await import("./config-YQZEYLLR.js");
88
- const statusInterval = setInterval(() => {
89
- writeStatus({
90
- pid: process.pid,
91
- version: pkg.version,
92
- connected: wsConnected,
93
- relay: agentConfig.get("relay"),
94
- deviceName: agentConfig.get("deviceName"),
95
- activeDownloads: handler.activeCount,
96
- lastHeartbeat: (/* @__PURE__ */ new Date()).toISOString(),
97
- updateAvailable: pendingUpdateVersion
98
- });
99
- }, 1e4);
100
- writeStatus({
101
- pid: process.pid,
85
+ const snapshotStatus = (connected) => ({
102
86
  version: pkg.version,
103
- connected: false,
104
- relay: agentConfig.get("relay"),
87
+ pid: process.pid,
88
+ connected,
89
+ relayUrl: agentConfig.get("relay"),
90
+ deviceId: agentConfig.get("deviceId"),
105
91
  deviceName: agentConfig.get("deviceName"),
106
- activeDownloads: 0,
107
- lastHeartbeat: (/* @__PURE__ */ new Date()).toISOString(),
108
- updateAvailable: null
92
+ activeDownloads: handler.activeCount,
93
+ lastHeartbeat: (/* @__PURE__ */ new Date()).toISOString()
109
94
  });
95
+ const writeStatusSafe = (connected) => {
96
+ writeStatusFile(snapshotStatus(connected)).catch((err) => {
97
+ console.warn(
98
+ "status.json write failed:",
99
+ err instanceof Error ? err.message : err
100
+ );
101
+ });
102
+ };
103
+ const statusInterval = setInterval(() => {
104
+ writeStatusSafe(wsConnected);
105
+ }, STATUS_HEARTBEAT_INTERVAL_MS);
106
+ writeStatusSafe(false);
110
107
  if (!process.env.TADAIMA_DAEMON) {
111
108
  tui.start();
112
109
  }
113
110
  process.on("SIGINT", () => {
114
111
  clearInterval(updateInterval);
115
112
  clearInterval(statusInterval);
116
- removeStatus();
113
+ removeStatusFile();
117
114
  tui.stop();
118
115
  ws.stop();
119
116
  process.exit(0);
@@ -121,7 +118,7 @@ async function main() {
121
118
  process.on("SIGTERM", () => {
122
119
  clearInterval(updateInterval);
123
120
  clearInterval(statusInterval);
124
- removeStatus();
121
+ removeStatusFile();
125
122
  tui.stop();
126
123
  ws.stop();
127
124
  process.exit(0);
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ config
4
+ } from "./chunk-7TPZ4T2V.js";
5
+
6
+ // src/status-file.ts
7
+ import { mkdirSync, unlinkSync } from "fs";
8
+ import { writeFile, rename } from "fs/promises";
9
+ import { dirname, join } from "path";
10
+ var STATUS_HEARTBEAT_INTERVAL_MS = 1e4;
11
+ function getStatusFilePath() {
12
+ return join(dirname(config.path), "status.json");
13
+ }
14
+ async function writeStatusFile(status) {
15
+ const statusPath = getStatusFilePath();
16
+ const tmpPath = statusPath + ".tmp";
17
+ mkdirSync(dirname(statusPath), { recursive: true });
18
+ await writeFile(tmpPath, JSON.stringify(status, null, 2));
19
+ await rename(tmpPath, statusPath);
20
+ }
21
+ function removeStatusFile() {
22
+ try {
23
+ unlinkSync(getStatusFilePath());
24
+ } catch {
25
+ }
26
+ }
27
+ export {
28
+ STATUS_HEARTBEAT_INTERVAL_MS,
29
+ getStatusFilePath,
30
+ removeStatusFile,
31
+ writeStatusFile
32
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psychout98/tadaima",
3
- "version": "1.0.11",
3
+ "version": "1.1.0",
4
4
  "description": "CLI download agent for Tadaima — a self-hosted media download orchestrator",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- config
4
- } from "./chunk-7TPZ4T2V.js";
5
-
6
- // src/status-writer.ts
7
- import { writeFileSync, unlinkSync, renameSync, mkdirSync } from "fs";
8
- import { dirname, join } from "path";
9
- function getStatusPath() {
10
- return join(dirname(config.path), "status.json");
11
- }
12
- function writeStatus(status) {
13
- const statusPath = getStatusPath();
14
- const tmpPath = statusPath + ".tmp";
15
- try {
16
- mkdirSync(dirname(statusPath), { recursive: true });
17
- writeFileSync(tmpPath, JSON.stringify(status, null, 2));
18
- renameSync(tmpPath, statusPath);
19
- } catch {
20
- }
21
- }
22
- function removeStatus() {
23
- try {
24
- unlinkSync(getStatusPath());
25
- } catch {
26
- }
27
- }
28
- export {
29
- removeStatus,
30
- writeStatus
31
- };