From 55cb71fefce9c34b1f09416b1302b687bc2d32c7 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 19 Jun 2024 03:24:50 +0900 Subject: [PATCH] make fetchlog limit to 20 --- src/ts/storage/globalApi.ts | 48 ++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/ts/storage/globalApi.ts b/src/ts/storage/globalApi.ts index 391bfe09..89a4c23a 100644 --- a/src/ts/storage/globalApi.ts +++ b/src/ts/storage/globalApi.ts @@ -624,28 +624,32 @@ export async function globalFetch(url: string, arg: GlobalFetchArgs = {}): Promi // Decoupled globalFetch built-in function function addFetchLogInGlobalFetch(response:any, success:boolean, url:string, arg:GlobalFetchArgs){ - try{ - fetchLog.unshift({ - body: JSON.stringify(arg.body, null, 2), - header: JSON.stringify(arg.headers ?? {}, null, 2), - response: JSON.stringify(response, null, 2), - success: success, - date: (new Date()).toLocaleTimeString(), - url: url, - chatId: arg.chatId - }) - } - catch{ - fetchLog.unshift({ - body: JSON.stringify(arg.body, null, 2), - header: JSON.stringify(arg.headers ?? {}, null, 2), - response: `${response}`, - success: success, - date: (new Date()).toLocaleTimeString(), - url: url, - chatId: arg.chatId - }) - } + try{ + fetchLog.unshift({ + body: JSON.stringify(arg.body, null, 2), + header: JSON.stringify(arg.headers ?? {}, null, 2), + response: JSON.stringify(response, null, 2), + success: success, + date: (new Date()).toLocaleTimeString(), + url: url, + chatId: arg.chatId + }) + } + catch{ + fetchLog.unshift({ + body: JSON.stringify(arg.body, null, 2), + header: JSON.stringify(arg.headers ?? {}, null, 2), + response: `${response}`, + success: success, + date: (new Date()).toLocaleTimeString(), + url: url, + chatId: arg.chatId + }) + } + + if(fetchLog.length > 20){ + fetchLog.pop() + } } // Decoupled globalFetch built-in function