mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
improve network request
This commit is contained in:
@@ -58,8 +58,9 @@ class ImageDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
if (configs['onResponse'] != null) {
|
||||
buffer = configs['onResponse'](buffer);
|
||||
if (configs['onResponse'] is JSInvokable) {
|
||||
buffer = (configs['onResponse'] as JSInvokable)([buffer]);
|
||||
(configs['onResponse'] as JSInvokable).free();
|
||||
}
|
||||
|
||||
await CacheManager().writeCache(cacheKey, buffer);
|
||||
@@ -102,7 +103,7 @@ class ImageDownloader {
|
||||
|
||||
if (configs['onLoadFailed'] is JSInvokable) {
|
||||
onLoadFailed = () async {
|
||||
dynamic result = configs['onLoadFailed']();
|
||||
dynamic result = (configs['onLoadFailed'] as JSInvokable)([]);
|
||||
if (result is Future) {
|
||||
result = await result;
|
||||
}
|
||||
@@ -135,8 +136,9 @@ class ImageDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
if (configs['onResponse'] != null) {
|
||||
buffer = configs['onResponse'](buffer);
|
||||
if (configs['onResponse'] is JSInvokable) {
|
||||
buffer = (configs['onResponse'] as JSInvokable)([buffer]);
|
||||
(configs['onResponse'] as JSInvokable).free();
|
||||
}
|
||||
|
||||
var data = Uint8List.fromList(buffer);
|
||||
@@ -158,17 +160,23 @@ class ImageDownloader {
|
||||
);
|
||||
return;
|
||||
} catch (e) {
|
||||
if(retryLimit < 0 || onLoadFailed == null) {
|
||||
if (retryLimit < 0 || onLoadFailed == null) {
|
||||
rethrow;
|
||||
}
|
||||
var newConfig = await onLoadFailed();
|
||||
(configs['onLoadFailed'] as JSInvokable).free();
|
||||
onLoadFailed = null;
|
||||
if(newConfig == null) {
|
||||
if (newConfig == null) {
|
||||
rethrow;
|
||||
}
|
||||
configs = newConfig;
|
||||
retryLimit--;
|
||||
}
|
||||
finally {
|
||||
if(onLoadFailed != null) {
|
||||
(configs['onLoadFailed'] as JSInvokable).free();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user