flowscale 2.1.0-beta.4 → 2.1.0-beta.5
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/operator-server.js +68 -47
- package/package.json +1 -1
package/dist/operator-server.js
CHANGED
|
@@ -100,10 +100,11 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
100
100
|
if (this.server)
|
|
101
101
|
return;
|
|
102
102
|
this.server = http.createServer(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
103
|
-
var url, query, pods, podMatch, pod, uploadMatch, podId,
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
var url, query, pods, podMatch, pod, uploadMatch, podId, port_1, executeMatch, podId, body, _a, _b, result, viewMatch, podId, port, params, upstream, imageBuffer, err_1;
|
|
104
|
+
var _this = this;
|
|
105
|
+
var _c, _d, _e, _f, _g, _h;
|
|
106
|
+
return __generator(this, function (_j) {
|
|
107
|
+
switch (_j.label) {
|
|
107
108
|
case 0:
|
|
108
109
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
109
110
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
@@ -115,92 +116,112 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
115
116
|
}
|
|
116
117
|
url = ((_c = req.url) !== null && _c !== void 0 ? _c : '/').split('?')[0];
|
|
117
118
|
query = new URLSearchParams((_e = ((_d = req.url) !== null && _d !== void 0 ? _d : '').split('?')[1]) !== null && _e !== void 0 ? _e : '');
|
|
118
|
-
|
|
119
|
+
_j.label = 1;
|
|
119
120
|
case 1:
|
|
120
|
-
|
|
121
|
+
_j.trys.push([1, 16, , 17]);
|
|
121
122
|
if (!(req.method === 'GET' && (url === '/api/pods' || url === '/api/pods/'))) return [3 /*break*/, 3];
|
|
122
123
|
return [4 /*yield*/, this.transport.list()];
|
|
123
124
|
case 2:
|
|
124
|
-
pods =
|
|
125
|
+
pods = _j.sent();
|
|
125
126
|
return [2 /*return*/, this._json(res, 200, pods)];
|
|
126
127
|
case 3:
|
|
127
128
|
podMatch = url.match(/^\/api\/pods\/([^/]+)$/);
|
|
128
129
|
if (!(req.method === 'GET' && podMatch)) return [3 /*break*/, 5];
|
|
129
130
|
return [4 /*yield*/, this.transport.get(decodeURIComponent(podMatch[1]))];
|
|
130
131
|
case 4:
|
|
131
|
-
pod =
|
|
132
|
+
pod = _j.sent();
|
|
132
133
|
if (!pod)
|
|
133
134
|
return [2 /*return*/, this._json(res, 404, { error: 'Pod not found' })];
|
|
134
135
|
return [2 /*return*/, this._json(res, 200, pod)];
|
|
135
136
|
case 5:
|
|
136
137
|
uploadMatch = url.match(/^\/api\/pods\/([^/]+)\/upload$/);
|
|
137
|
-
if (!(req.method === 'POST' && uploadMatch)) return [3 /*break*/,
|
|
138
|
+
if (!(req.method === 'POST' && uploadMatch)) return [3 /*break*/, 8];
|
|
138
139
|
podId = decodeURIComponent(uploadMatch[1]);
|
|
139
|
-
return [4 /*yield*/, this._runningPort(podId)
|
|
140
|
+
return [4 /*yield*/, this._runningPort(podId)
|
|
141
|
+
// Pipe the multipart body directly to ComfyUI to preserve boundary and encoding
|
|
142
|
+
];
|
|
140
143
|
case 6:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
headers
|
|
149
|
-
|
|
144
|
+
port_1 = _j.sent();
|
|
145
|
+
// Pipe the multipart body directly to ComfyUI to preserve boundary and encoding
|
|
146
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
147
|
+
var _a;
|
|
148
|
+
var headers = {
|
|
149
|
+
'content-type': (_a = req.headers['content-type']) !== null && _a !== void 0 ? _a : 'application/octet-stream',
|
|
150
|
+
};
|
|
151
|
+
if (req.headers['content-length'])
|
|
152
|
+
headers['content-length'] = req.headers['content-length'];
|
|
153
|
+
if (req.headers['transfer-encoding'])
|
|
154
|
+
headers['transfer-encoding'] = req.headers['transfer-encoding'];
|
|
155
|
+
var upstreamReq = http.request({ hostname: 'localhost', port: port_1, path: '/upload/image', method: 'POST', headers: headers }, function (upstreamRes) {
|
|
156
|
+
var chunks = [];
|
|
157
|
+
upstreamRes.on('data', function (chunk) { return chunks.push(chunk); });
|
|
158
|
+
upstreamRes.on('end', function () {
|
|
159
|
+
var _a;
|
|
160
|
+
try {
|
|
161
|
+
var data = JSON.parse(Buffer.concat(chunks).toString());
|
|
162
|
+
_this._json(res, (_a = upstreamRes.statusCode) !== null && _a !== void 0 ? _a : 500, data);
|
|
163
|
+
resolve();
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
reject(e);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
upstreamRes.on('error', reject);
|
|
170
|
+
});
|
|
171
|
+
upstreamReq.on('error', reject);
|
|
172
|
+
req.pipe(upstreamReq);
|
|
150
173
|
})];
|
|
174
|
+
case 7:
|
|
175
|
+
// Pipe the multipart body directly to ComfyUI to preserve boundary and encoding
|
|
176
|
+
_j.sent();
|
|
177
|
+
return [2 /*return*/];
|
|
151
178
|
case 8:
|
|
152
|
-
upstream = _k.sent();
|
|
153
|
-
return [4 /*yield*/, upstream.json()];
|
|
154
|
-
case 9:
|
|
155
|
-
data = _k.sent();
|
|
156
|
-
return [2 /*return*/, this._json(res, upstream.status, data)];
|
|
157
|
-
case 10:
|
|
158
179
|
executeMatch = url.match(/^\/api\/pods\/([^/]+)\/execute$/);
|
|
159
|
-
if (!(req.method === 'POST' && executeMatch)) return [3 /*break*/,
|
|
180
|
+
if (!(req.method === 'POST' && executeMatch)) return [3 /*break*/, 11];
|
|
160
181
|
podId = decodeURIComponent(executeMatch[1]);
|
|
161
182
|
_b = (_a = JSON).parse;
|
|
162
183
|
return [4 /*yield*/, this._readBody(req)];
|
|
163
|
-
case
|
|
164
|
-
body = _b.apply(_a, [(
|
|
165
|
-
return [4 /*yield*/, this.api.executeWorkflowAndWait(podId, body.workflow, (
|
|
166
|
-
case
|
|
167
|
-
result =
|
|
184
|
+
case 9:
|
|
185
|
+
body = _b.apply(_a, [(_j.sent()).toString()]);
|
|
186
|
+
return [4 /*yield*/, this.api.executeWorkflowAndWait(podId, body.workflow, (_f = body.options) !== null && _f !== void 0 ? _f : {})];
|
|
187
|
+
case 10:
|
|
188
|
+
result = _j.sent();
|
|
168
189
|
return [2 /*return*/, this._json(res, 200, result)];
|
|
169
|
-
case
|
|
190
|
+
case 11:
|
|
170
191
|
viewMatch = url.match(/^\/api\/pods\/([^/]+)\/view$/);
|
|
171
|
-
if (!(req.method === 'GET' && viewMatch)) return [3 /*break*/,
|
|
192
|
+
if (!(req.method === 'GET' && viewMatch)) return [3 /*break*/, 15];
|
|
172
193
|
podId = decodeURIComponent(viewMatch[1]);
|
|
173
194
|
return [4 /*yield*/, this._runningPort(podId)];
|
|
174
|
-
case
|
|
175
|
-
port =
|
|
195
|
+
case 12:
|
|
196
|
+
port = _j.sent();
|
|
176
197
|
params = new URLSearchParams(query.toString());
|
|
177
198
|
return [4 /*yield*/, fetch("http://localhost:".concat(port, "/view?").concat(params))];
|
|
178
|
-
case
|
|
179
|
-
upstream =
|
|
199
|
+
case 13:
|
|
200
|
+
upstream = _j.sent();
|
|
180
201
|
if (!upstream.ok) {
|
|
181
202
|
res.writeHead(upstream.status);
|
|
182
203
|
res.end();
|
|
183
204
|
return [2 /*return*/];
|
|
184
205
|
}
|
|
185
206
|
return [4 /*yield*/, upstream.arrayBuffer()];
|
|
186
|
-
case
|
|
187
|
-
imageBuffer =
|
|
207
|
+
case 14:
|
|
208
|
+
imageBuffer = _j.sent();
|
|
188
209
|
res.writeHead(200, {
|
|
189
|
-
'Content-Type': (
|
|
210
|
+
'Content-Type': (_g = upstream.headers.get('content-type')) !== null && _g !== void 0 ? _g : 'image/png',
|
|
190
211
|
'Cache-Control': 'public, max-age=3600',
|
|
191
212
|
});
|
|
192
213
|
res.end(Buffer.from(imageBuffer));
|
|
193
214
|
return [2 /*return*/];
|
|
194
|
-
case
|
|
215
|
+
case 15:
|
|
195
216
|
res.writeHead(404);
|
|
196
217
|
res.end('Not found');
|
|
197
|
-
return [3 /*break*/,
|
|
198
|
-
case
|
|
199
|
-
err_1 =
|
|
218
|
+
return [3 /*break*/, 17];
|
|
219
|
+
case 16:
|
|
220
|
+
err_1 = _j.sent();
|
|
200
221
|
console.error('[PodsOperatorServer] Error handling request:', err_1);
|
|
201
|
-
this._json(res, 500, { error: (
|
|
202
|
-
return [3 /*break*/,
|
|
203
|
-
case
|
|
222
|
+
this._json(res, 500, { error: (_h = err_1 === null || err_1 === void 0 ? void 0 : err_1.message) !== null && _h !== void 0 ? _h : 'Internal server error' });
|
|
223
|
+
return [3 /*break*/, 17];
|
|
224
|
+
case 17: return [2 /*return*/];
|
|
204
225
|
}
|
|
205
226
|
});
|
|
206
227
|
}); });
|