mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-07-09 15:05:59 +00:00
adding fetch in try to prevent crashes
This commit is contained in:
@@ -140,21 +140,26 @@ async function _fetchSynologyJson<T>(url: string, body: URLSearchParams): Promis
|
|||||||
if (!SsrfResult.allowed) {
|
if (!SsrfResult.allowed) {
|
||||||
return fail(SsrfResult.error, 400);
|
return fail(SsrfResult.error, 400);
|
||||||
}
|
}
|
||||||
const resp = await fetch(endpoint, {
|
try {
|
||||||
method: 'POST',
|
const resp = await fetch(endpoint, {
|
||||||
headers: {
|
method: 'POST',
|
||||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
headers: {
|
||||||
},
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||||
body,
|
},
|
||||||
signal: AbortSignal.timeout(30000),
|
body,
|
||||||
});
|
signal: AbortSignal.timeout(30000),
|
||||||
|
});
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
return fail('Synology API request failed with status ' + resp.status, resp.status);
|
return fail('Synology API request failed with status ' + resp.status, resp.status);
|
||||||
|
}
|
||||||
|
const response = await resp.json() as SynologyApiResponse<T>;
|
||||||
|
return response.success ? success(response.data) : fail('Synology failed with code ' + response.error.code, response.error.code);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return fail('Failed to connect to Synology API', 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await resp.json() as SynologyApiResponse<T>;
|
|
||||||
return response.success ? success(response.data) : fail('Synology failed with code ' + response.error.code, response.error.code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _loginToSynology(url: string, username: string, password: string): Promise<ServiceResult<string>> {
|
async function _loginToSynology(url: string, username: string, password: string): Promise<ServiceResult<string>> {
|
||||||
@@ -382,12 +387,12 @@ export async function syncSynologyAlbumLink(userId: number, tripId: string, link
|
|||||||
asset_ids: allItems.map(item => String(item.additional?.thumbnail?.cache_key || '')).filter(id => id),
|
asset_ids: allItems.map(item => String(item.additional?.thumbnail?.cache_key || '')).filter(id => id),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const result = await addTripPhotos(tripId, userId, true, [selection], sid, linkId);
|
const result = await addTripPhotos(tripId, userId, true, [selection], sid, linkId);
|
||||||
if (!result.success) return result as ServiceResult<SyncAlbumResult>;
|
if (!result.success) return result as ServiceResult<SyncAlbumResult>;
|
||||||
|
|
||||||
updateSyncTimeForAlbumLink(linkId);
|
updateSyncTimeForAlbumLink(linkId);
|
||||||
|
|
||||||
return success({ added: result.data.added, total: allItems.length });
|
return success({ added: result.data.added, total: allItems.length });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user