|
@@ -1,5 +1,7 @@
|
|
|
import { ArrayList, HashMap } from '@kit.ArkTS';
|
|
|
import http from '@ohos.net.http';
|
|
|
+import { LocalStorageHelper } from '../utils/LocalStorageHelper';
|
|
|
+import { LocalStorageKeys } from '../utils/LocalStorageKeys';
|
|
|
|
|
|
|
|
|
type HttpParamsGet = {
|
|
@@ -39,6 +41,8 @@ export class HttpHelper {
|
|
|
|
|
|
constructor() {
|
|
|
this.httpHandlerList = new HashMap<string, http.HttpRequest>();
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
this.concurrentList.clear()
|
|
|
}
|
|
|
|
|
@@ -72,11 +76,15 @@ export class HttpHelper {
|
|
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
this.httpHandlerList.get(apiNo ?? params.url).destroy()
|
|
|
this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
let httpRequest = http.createHttp();
|
|
|
|
|
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
|
|
|
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
|
|
|
const header = {
|
|
@@ -106,6 +114,8 @@ export class HttpHelper {
|
|
|
|
|
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
if (data.responseCode === 200) {
|
|
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
|
@@ -118,6 +128,8 @@ export class HttpHelper {
|
|
|
}).catch((err: Error) => {
|
|
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
if (err.message === 'Failed writing received data to disk/application') {
|
|
|
reject('cancel')
|
|
@@ -142,11 +154,15 @@ export class HttpHelper {
|
|
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
this.httpHandlerList.get(apiNo ?? params.url).destroy()
|
|
|
this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
let httpRequest = http.createHttp();
|
|
|
|
|
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
|
|
|
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
|
|
|
const header = {
|
|
@@ -178,6 +194,8 @@ export class HttpHelper {
|
|
|
|
|
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
if (data.responseCode === 200) {
|
|
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
|
@@ -190,6 +208,8 @@ export class HttpHelper {
|
|
|
}).catch((err: Error) => {
|
|
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
if (err.message === 'Failed writing received data to disk/application') {
|
|
|
reject('cancel')
|
|
@@ -216,11 +236,15 @@ export class HttpHelper {
|
|
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
this.httpHandlerList.get(apiNo ?? params.url).destroy()
|
|
|
this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
let httpRequest = http.createHttp();
|
|
|
|
|
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
|
|
|
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
|
|
|
const header = {
|
|
@@ -247,6 +271,8 @@ export class HttpHelper {
|
|
|
|
|
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
if (data.responseCode === 200) {
|
|
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
|
@@ -259,6 +285,8 @@ export class HttpHelper {
|
|
|
}).catch((err: Error) => {
|
|
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
|
|
+ LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
|
|
}
|
|
|
if (err.message === 'Failed writing received data to disk/application') {
|
|
|
reject('cancel')
|