mirror of
https://github.com/koush/scrypted.git
synced 2026-03-20 16:40:24 +00:00
cameras: fix fetch timeout bugs
This commit is contained in:
4
plugins/amcrest/package-lock.json
generated
4
plugins/amcrest/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/amcrest",
|
||||
"version": "0.0.142",
|
||||
"version": "0.0.143",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/amcrest",
|
||||
"version": "0.0.142",
|
||||
"version": "0.0.143",
|
||||
"license": "Apache",
|
||||
"dependencies": {
|
||||
"@scrypted/common": "file:../../common",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/amcrest",
|
||||
"version": "0.0.142",
|
||||
"version": "0.0.143",
|
||||
"description": "Amcrest Plugin for Scrypted",
|
||||
"author": "Scrypted",
|
||||
"license": "Apache",
|
||||
|
||||
4
plugins/hikvision/package-lock.json
generated
4
plugins/hikvision/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/hikvision",
|
||||
"version": "0.0.144",
|
||||
"version": "0.0.145",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/hikvision",
|
||||
"version": "0.0.144",
|
||||
"version": "0.0.145",
|
||||
"license": "Apache",
|
||||
"dependencies": {
|
||||
"@scrypted/common": "file:../../common",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/hikvision",
|
||||
"version": "0.0.144",
|
||||
"version": "0.0.145",
|
||||
"description": "Hikvision Plugin for Scrypted",
|
||||
"author": "Scrypted",
|
||||
"license": "Apache",
|
||||
|
||||
4
plugins/onvif/package-lock.json
generated
4
plugins/onvif/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/onvif",
|
||||
"version": "0.1.11",
|
||||
"version": "0.1.12",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/onvif",
|
||||
"version": "0.1.11",
|
||||
"version": "0.1.12",
|
||||
"license": "Apache",
|
||||
"dependencies": {
|
||||
"@scrypted/common": "file:../../common",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/onvif",
|
||||
"version": "0.1.11",
|
||||
"version": "0.1.12",
|
||||
"description": "ONVIF Camera Plugin for Scrypted",
|
||||
"author": "Scrypted",
|
||||
"license": "Apache",
|
||||
|
||||
4
plugins/reolink/package-lock.json
generated
4
plugins/reolink/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/reolink",
|
||||
"version": "0.0.63",
|
||||
"version": "0.0.64",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/reolink",
|
||||
"version": "0.0.63",
|
||||
"version": "0.0.64",
|
||||
"license": "Apache",
|
||||
"dependencies": {
|
||||
"@scrypted/common": "file:../../common",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/reolink",
|
||||
"version": "0.0.63",
|
||||
"version": "0.0.64",
|
||||
"description": "Reolink Plugin for Scrypted",
|
||||
"author": "Scrypted",
|
||||
"license": "Apache",
|
||||
|
||||
4
plugins/snapshot/package-lock.json
generated
4
plugins/snapshot/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/snapshot",
|
||||
"version": "0.2.40",
|
||||
"version": "0.2.41",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/snapshot",
|
||||
"version": "0.2.40",
|
||||
"version": "0.2.41",
|
||||
"dependencies": {
|
||||
"@types/node": "^20.10.6",
|
||||
"sharp": "^0.33.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/snapshot",
|
||||
"version": "0.2.40",
|
||||
"version": "0.2.41",
|
||||
"description": "Snapshot Plugin for Scrypted",
|
||||
"scripts": {
|
||||
"scrypted-setup-project": "scrypted-setup-project",
|
||||
|
||||
@@ -93,44 +93,61 @@ export async function httpFetch<T extends HttpFetchOptions<Readable>>(options: T
|
||||
}
|
||||
}
|
||||
|
||||
let controller: AbortController;
|
||||
let timeout: NodeJS.Timeout;
|
||||
if (options.timeout) {
|
||||
controller = new AbortController();
|
||||
timeout = setTimeout(() => controller.abort(), options.timeout);
|
||||
}
|
||||
|
||||
const request = proto.request(url, {
|
||||
method: getFetchMethod(options),
|
||||
rejectUnauthorized: options.rejectUnauthorized,
|
||||
family: options.family,
|
||||
headers: nodeHeaders,
|
||||
signal: controller?.signal || options.signal,
|
||||
timeout: options.timeout,
|
||||
});
|
||||
|
||||
options.signal?.addEventListener('abort', () => request.destroy(new Error('abort')));
|
||||
if (controller)
|
||||
options.signal?.addEventListener('abort', () => controller.abort('abort'));
|
||||
else
|
||||
options.signal?.addEventListener('abort', () => request.destroy(new Error('abort')));
|
||||
|
||||
if (body)
|
||||
body.pipe(request);
|
||||
else
|
||||
request.end();
|
||||
const [response] = await once(request, 'response') as [IncomingMessage];
|
||||
|
||||
if (!options?.ignoreStatusCode) {
|
||||
try {
|
||||
checkStatus(response.statusCode);
|
||||
try {
|
||||
const [response] = await once(request, 'response') as [IncomingMessage];
|
||||
|
||||
if (!options?.ignoreStatusCode) {
|
||||
try {
|
||||
checkStatus(response.statusCode);
|
||||
}
|
||||
catch (e) {
|
||||
readMessageBuffer(response).catch(() => { });
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
readMessageBuffer(response).catch(() => { });
|
||||
throw e;
|
||||
|
||||
const incomingHeaders = new Headers();
|
||||
for (const [k, v] of Object.entries(response.headers)) {
|
||||
for (const vv of (typeof v === 'string' ? [v] : v)) {
|
||||
incomingHeaders.append(k, vv)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: response.statusCode,
|
||||
headers: incomingHeaders,
|
||||
body: await httpFetchParseIncomingMessage(response, options.responseType),
|
||||
};
|
||||
}
|
||||
|
||||
const incomingHeaders = new Headers();
|
||||
for (const [k, v] of Object.entries(response.headers)) {
|
||||
for (const vv of (typeof v === 'string' ? [v] : v)) {
|
||||
incomingHeaders.append(k, vv)
|
||||
}
|
||||
finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: response.statusCode,
|
||||
headers: incomingHeaders,
|
||||
body: await httpFetchParseIncomingMessage(response, options.responseType),
|
||||
};
|
||||
}
|
||||
|
||||
function ensureType<T>(v: T) {
|
||||
|
||||
@@ -124,30 +124,42 @@ export async function domFetch<T extends HttpFetchOptions<BodyInit>>(options: T)
|
||||
body = createStringOrBufferBody(headers, body);
|
||||
}
|
||||
|
||||
const { url } = options;
|
||||
const response = await fetch(url, {
|
||||
method: getFetchMethod(options),
|
||||
credentials: options.withCredentials ? 'include' : undefined,
|
||||
headers,
|
||||
signal: options.signal || options.timeout ? AbortSignal.timeout(options.timeout) : undefined,
|
||||
body,
|
||||
});
|
||||
|
||||
if (!options?.ignoreStatusCode) {
|
||||
try {
|
||||
checkStatus(response.status);
|
||||
}
|
||||
catch (e) {
|
||||
response.arrayBuffer().catch(() => { });
|
||||
throw e;
|
||||
}
|
||||
let controller: AbortController;
|
||||
let timeout: NodeJS.Timeout;
|
||||
if (options.timeout) {
|
||||
controller = new AbortController();
|
||||
timeout = setTimeout(() => controller.abort(), options.timeout);
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: response.status,
|
||||
headers: response.headers,
|
||||
body: await domFetchParseIncomingMessage(response, options.responseType),
|
||||
};
|
||||
try {
|
||||
const { url } = options;
|
||||
const response = await fetch(url, {
|
||||
method: getFetchMethod(options),
|
||||
credentials: options.withCredentials ? 'include' : undefined,
|
||||
headers,
|
||||
signal: controller?.signal || options.signal,
|
||||
body,
|
||||
});
|
||||
|
||||
if (!options?.ignoreStatusCode) {
|
||||
try {
|
||||
checkStatus(response.status);
|
||||
}
|
||||
catch (e) {
|
||||
response.arrayBuffer().catch(() => { });
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: response.status,
|
||||
headers: response.headers,
|
||||
body: await domFetchParseIncomingMessage(response, options.responseType),
|
||||
};
|
||||
}
|
||||
finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
function ensureType<T>(v: T) {
|
||||
|
||||
Reference in New Issue
Block a user