fix(premiere-plugin): inject Bearer in downloadFile + add 15s timeout

downloadFile() uses native https.get which bypasses the window.fetch interceptor that injects Authorization. Same-server URLs (proxy /video) hit requireAuth and 401. Inject the Bearer header manually when url starts with state.serverUrl.

Also add a 15s setTimeout so an unreachable presigned URL (or CEP-Node TLS hiccup on broadcastmgmt.cloud) fails fast with an error instead of hanging the spinner forever.
This commit is contained in:
Claude 2026-05-28 03:00:02 +00:00
parent ac7730195d
commit e8ceb991a3

View file

@ -1894,7 +1894,24 @@ function downloadFile(url, filename) {
var file = fs.createWriteStream(tempPath); var file = fs.createWriteStream(tempPath);
var protocol = url.startsWith('https') ? https : http; var protocol = url.startsWith('https') ? https : http;
protocol.get(url, function (res) { // Native http.get bypasses window.fetch, so the Bearer
// interceptor never fires. Inject Authorization manually for
// same-server URLs (proxy /video etc.); off-host presigned URLs
// don't need it.
var reqOpts = url;
if (state.apiToken && state.serverUrl && url.startsWith(state.serverUrl)) {
try {
var p = new URL(url);
reqOpts = {
hostname: p.hostname,
port: p.port || (p.protocol === 'https:' ? 443 : 80),
path: p.pathname + (p.search || ''),
headers: { 'Authorization': 'Bearer ' + state.apiToken },
};
} catch (_) { /* fall back to url string */ }
}
var req = protocol.get(reqOpts, function (res) {
if (res.statusCode !== 200) { if (res.statusCode !== 200) {
file.close(); file.close();
fs.unlink(tempPath, function () {}); fs.unlink(tempPath, function () {});
@ -1923,7 +1940,17 @@ function downloadFile(url, filename) {
fs.unlink(tempPath, function () {}); fs.unlink(tempPath, function () {});
reject(err); reject(err);
}); });
}).on('error', function (err) { });
// Without a timeout an unreachable host or a CEP-Node TLS hiccup
// makes this Promise sit forever. 15s covers slow LTE connect +
// handshake; once bytes flow there's no cap.
req.setTimeout(15000, function () {
var host = (typeof reqOpts === 'string') ? reqOpts : reqOpts.hostname;
req.destroy(new Error('Download timed out after 15s (no response from ' + host + ')'));
});
req.on('error', function (err) {
fs.unlink(tempPath, function () {}); fs.unlink(tempPath, function () {});
reject(err); reject(err);
}); });