channel-worker 1.0.15 → 1.0.16

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.
@@ -46,6 +46,9 @@ class CommandPoller {
46
46
  case 'close_profile':
47
47
  await this.handleCloseProfile(command);
48
48
  break;
49
+ case 'save_file':
50
+ await this.handleSaveFile(command);
51
+ break;
49
52
  default:
50
53
  // Other commands (scan_facebook_pages, etc.) handled by extension
51
54
  console.log(`[commands] Skipping ${command.type} — handled by extension`);
@@ -141,6 +144,34 @@ class CommandPoller {
141
144
  }
142
145
  }
143
146
 
147
+ async handleSaveFile(command) {
148
+ const { url, save_path } = command.payload || {};
149
+ console.log(`[commands] Saving file: ${url} → ${save_path}`);
150
+ try {
151
+ const fs = require('fs');
152
+ const path = require('path');
153
+
154
+ // Ensure directory exists
155
+ const dir = path.dirname(save_path);
156
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
157
+
158
+ // Download and save
159
+ const res = await fetch(url);
160
+ if (!res.ok) throw new Error(`Download failed: ${res.status}`);
161
+ const buffer = Buffer.from(await res.arrayBuffer());
162
+ fs.writeFileSync(save_path, buffer);
163
+
164
+ console.log(`[commands] File saved: ${save_path} (${buffer.length} bytes)`);
165
+ await this.api.updateCommand(command._id, {
166
+ status: 'done',
167
+ result: { file_path: save_path, size: buffer.length },
168
+ });
169
+ } catch (err) {
170
+ console.error(`[commands] Save file failed: ${err.message}`);
171
+ await this.api.updateCommand(command._id, { status: 'failed', error: err.message });
172
+ }
173
+ }
174
+
144
175
  async handleCloseProfile(command) {
145
176
  const { profile_id } = command.payload || {};
146
177
  console.log(`[commands] Closing profile: ${profile_id}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "channel-worker",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Channel Manager worker daemon — runs on remote machines to execute video pipeline jobs",
5
5
  "main": "lib/daemon.js",
6
6
  "bin": {