@oxiaom/adoremix 1.0.65 → 1.0.67

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxiaom/adoremix",
3
- "version": "1.0.65",
3
+ "version": "1.0.67",
4
4
  "description": "AdoreMix broadcast server - cross-platform installer, runner and service manager",
5
5
  "bin": {
6
6
  "adoremix": "./bin/adoremix.js"
@@ -92,6 +92,8 @@ function startServer(opts) {
92
92
  let fd = null;
93
93
  let audioStart = 0;
94
94
  let fileSize = 0;
95
+ let totalSize = 0;
96
+ let offset = 0;
95
97
  let filePath = '';
96
98
  let state = 'path'; // path → chunks
97
99
  let pending = Buffer.alloc(0);
@@ -114,6 +116,7 @@ function startServer(opts) {
114
116
  sock.on('close', () => { cleanup(); log(`[info] ${peer} 断开`); });
115
117
 
116
118
  const handleLine = (lineRaw) => {
119
+ if (closed) return;
117
120
  const line = lineRaw.trim();
118
121
  if (state === 'path') {
119
122
  const abs = validateRelPath(line, root);
@@ -128,7 +131,9 @@ function startServer(opts) {
128
131
  return fail('Invalid MP3 file format');
129
132
  }
130
133
  filePath = line;
134
+ totalSize = st.size;
131
135
  fileSize = st.size - audioStart;
136
+ offset = audioStart;
132
137
  state = 'chunks';
133
138
  log(`[info] ${peer} 推送 ${line} 起始=${audioStart} 大小=${fileSize}`);
134
139
  sock.write(String(fileSize) + '\n');
@@ -147,7 +152,7 @@ function startServer(opts) {
147
152
 
148
153
  const buf = Buffer.alloc(n);
149
154
  let got;
150
- try { got = fs.readSync(fd, buf, 0, n, null); } catch (e) { return fail('File read error'); }
155
+ try { got = fs.readSync(fd, buf, 0, n, offset); } catch (e) { return fail('File read error'); }
151
156
  if (got === 0) {
152
157
  // 到文件尾:回 close 并断开(与 C++ 一致)
153
158
  try { sock.write('close\n', () => sock.end()); } catch (e) {}
@@ -155,8 +160,17 @@ function startServer(opts) {
155
160
  log(`[info] ${peer} 完成 ${filePath}`);
156
161
  return;
157
162
  }
163
+ offset += got;
164
+ const atEnd = offset >= totalSize;
165
+ if (atEnd) {
166
+ // 与 C++ 一致:尾块发出后紧跟 "close\n" 并断开
167
+ try { sock.write(buf.subarray(0, got)); sock.end('close\n'); } catch (e) {}
168
+ cleanup();
169
+ log(`[info] ${peer} 完成 ${filePath}`);
170
+ return;
171
+ }
158
172
  if (!sock.write(buf.subarray(0, got))) {
159
- // 背压:等 drain 再继续读下一行(简单起见暂停处理)
173
+ // 背压:等 drain 再继续读下一行
160
174
  sock.pause();
161
175
  sock.once('drain', () => sock.resume());
162
176
  }