node-red-contrib-hik-media-buffer 1.1.2 → 1.1.3

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.
@@ -149,23 +149,33 @@ module.exports = function(RED) {
149
149
  if (uriMatch) {
150
150
  const rawUri = uriMatch[1].replace(/&/g, '&');
151
151
  const resDown = await hikRequest({
152
- method: 'GET', url: `${baseUrl}/download`,
152
+ method: 'GET',
153
+ url: `${baseUrl}/download`,
153
154
  data: `<?xml version="1.0" encoding="UTF-8"?><downloadRequest><playbackURI>${rawUri.replace(/&/g, '&amp;')}</playbackURI></downloadRequest>`,
154
- responseType: 'arraybuffer', user: node.user, pass: node.camPass
155
+ responseType: 'arraybuffer',
156
+ user: node.user,
157
+ pass: node.camPass
155
158
  });
156
159
 
157
160
  let buffer = Buffer.from(resDown.data);
161
+
158
162
  if (t.id === "203") {
159
- // SALVATAGGIO IMMAGINE FISICO
163
+ // --- LOGICA FOTO (IDENTICA ALLA TUA) ---
164
+ output.imageBuffer = buffer;
165
+
166
+ // AGGIUNTA: Salviamo fisicamente il file per il sito
160
167
  const imgFileName = `img_${timestamp}.jpg`;
161
168
  const fullImgPath = path.join(imgDir, imgFileName);
162
- fs.writeFileSync(fullImgPath, buffer);
163
- output.imageBuffer = buffer;
164
- output.imagePath = fullImgPath; // Passiamo il path fisico
169
+ fs.writeFileSync(fullImgPath, buffer);
170
+ output.imagePath = fullImgPath;
171
+
165
172
  } else {
173
+ // --- LOGICA VIDEO (IDENTICA ALLA TUA) ---
166
174
  if (buffer.slice(0, 4).toString() === 'IMKH') buffer = buffer.slice(40);
175
+
167
176
  const rawPath = path.join(vidDir, `raw_${timestamp}.mp4`);
168
177
  const fixedPath = path.join(vidDir, `hik_v_${channelID}_${timestamp}.mp4`);
178
+
169
179
  fs.writeFileSync(rawPath, buffer);
170
180
 
171
181
  await new Promise((resolve) => {
@@ -173,10 +183,14 @@ module.exports = function(RED) {
173
183
  if (!err) {
174
184
  output.videoPath = fixedPath;
175
185
  try { fs.unlinkSync(rawPath); } catch(e) {}
176
- } else { output.videoPath = rawPath; }
186
+ } else {
187
+ output.videoPath = rawPath;
188
+ }
177
189
  resolve();
178
190
  });
179
191
  });
192
+
193
+ setTimeout(() => { if (output.videoPath && fs.existsSync(output.videoPath)) fs.unlinkSync(output.videoPath); }, 180000);
180
194
  }
181
195
  }
182
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-hik-media-buffer",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Ottiene buffer video e immagine da camere Hikvision via ISAPI",
5
5
  "keywords": [
6
6
  "node-red",