chattransfer 2.0.17 → 3.0.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.
@@ -1,5 +1,14 @@
1
1
  const os = require('os');
2
2
 
3
+ function isLoopbackAddress(address) {
4
+ if (!address) return false;
5
+
6
+ const normalized = String(address).replace(/^::ffff:/, '').trim().toLowerCase();
7
+ return normalized === '127.0.0.1'
8
+ || normalized === '::1'
9
+ || normalized === 'localhost';
10
+ }
11
+
3
12
  function getIPAddress() {
4
13
  const interfaces = os.networkInterfaces();
5
14
 
@@ -17,5 +26,6 @@ function getIPAddress() {
17
26
  }
18
27
 
19
28
  module.exports = {
20
- getIPAddress
29
+ getIPAddress,
30
+ isLoopbackAddress
21
31
  };
@@ -2,6 +2,8 @@ const path = require('path');
2
2
 
3
3
  const DEFAULT_HOST = '0.0.0.0';
4
4
  const DEFAULT_PORT = 55556;
5
+ const DEFAULT_ROOM_IDLE_RETENTION_DAYS = 7;
6
+ const DEFAULT_PUBLIC_ROOM_RETENTION_DAYS = 7;
5
7
 
6
8
  function isTruthy(value) {
7
9
  return ['1', 'true', 'yes', 'on'].includes(String(value).toLowerCase());
@@ -17,6 +19,19 @@ function parsePort(value, source) {
17
19
  return port;
18
20
  }
19
21
 
22
+ function parseRetentionDays(value, source, defaultValue) {
23
+ if (value === undefined || value === null || value === '') {
24
+ return defaultValue;
25
+ }
26
+
27
+ const days = Number(value);
28
+ if (!Number.isInteger(days) || days < 0 || days > 365) {
29
+ throw new Error(`Invalid ${source}: ${value}`);
30
+ }
31
+
32
+ return days;
33
+ }
34
+
20
35
  function normalizePublicUrl(value) {
21
36
  if (!value) return null;
22
37
 
@@ -58,6 +73,16 @@ function resolveStartOptions(overrides = {}, env = process.env) {
58
73
  const host = overrides.host ?? env.CHATTRANSFER_HOST ?? DEFAULT_HOST;
59
74
  const dataDir = overrides.dataDir ?? env.CHATTRANSFER_DATA_DIR;
60
75
  const publicUrl = normalizePublicUrl(overrides.publicUrl ?? env.CHATTRANSFER_PUBLIC_URL);
76
+ const roomIdleRetentionDays = parseRetentionDays(
77
+ overrides.roomIdleRetentionDays ?? env.CHATTRANSFER_ROOM_IDLE_RETENTION_DAYS,
78
+ 'room idle retention days',
79
+ DEFAULT_ROOM_IDLE_RETENTION_DAYS
80
+ );
81
+ const publicRoomRetentionDays = parseRetentionDays(
82
+ overrides.publicRoomRetentionDays ?? env.CHATTRANSFER_PUBLIC_ROOM_RETENTION_DAYS,
83
+ 'public room retention days',
84
+ DEFAULT_PUBLIC_ROOM_RETENTION_DAYS
85
+ );
61
86
  const openBrowser = shouldOpenBrowser({
62
87
  env,
63
88
  explicitValue: overrides.openBrowser
@@ -75,6 +100,8 @@ function resolveStartOptions(overrides = {}, env = process.env) {
75
100
  ),
76
101
  dataDir: dataDir ? path.resolve(String(dataDir)) : null,
77
102
  publicUrl,
103
+ roomIdleRetentionDays,
104
+ publicRoomRetentionDays,
78
105
  openBrowser
79
106
  };
80
107
  }
@@ -82,8 +109,11 @@ function resolveStartOptions(overrides = {}, env = process.env) {
82
109
  module.exports = {
83
110
  DEFAULT_HOST,
84
111
  DEFAULT_PORT,
112
+ DEFAULT_PUBLIC_ROOM_RETENTION_DAYS,
113
+ DEFAULT_ROOM_IDLE_RETENTION_DAYS,
85
114
  isTruthy,
86
115
  normalizePublicUrl,
116
+ parseRetentionDays,
87
117
  parsePort,
88
118
  resolveStartOptions,
89
119
  shouldOpenBrowser