Skip to content
This repository has been archived by the owner on Sep 17, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/v1.4.15-beta.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
hanerx committed May 29, 2021
2 parents 15e32ee + 0f1f8eb commit 95418d8
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 24 deletions.
40 changes: 27 additions & 13 deletions lib/component/comic_viewer/ComicPage.dart
Expand Up @@ -4,6 +4,7 @@ import 'dart:typed_data';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:dcomic/model/comic_source/baseSourceModel.dart';
import 'package:dcomic/model/ipfsSettingProvider.dart';
import 'package:dcomic/utils/ProxyCacheManager.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -191,19 +192,32 @@ class _ComicPage extends State<ComicPage> {
child: CircularProgressIndicator(value: downloadProgress.progress),
),
)),
errorWidget: (context, url, error) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.error,
color: Colors.redAccent,
),
Text(
'$error',
style: TextStyle(color: Colors.redAccent),
)
],
errorWidget: (context, url, error) => CachedNetworkImage(
fit: widget.cover ? BoxFit.cover : BoxFit.contain,
imageUrl: widget.url,
httpHeaders: widget.headers,
cacheManager: BadCertificateCacheManager(),
progressIndicatorBuilder: (context, url, downloadProgress) => Center(
child: Container(
height: 500,
child: Center(
child: CircularProgressIndicator(value: downloadProgress.progress),
),
)),
errorWidget: (context, url, error) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.error,
color: Colors.redAccent,
),
Text(
'$error',
style: TextStyle(color: Colors.redAccent),
)
],
),
),
),
),
Expand Down
3 changes: 3 additions & 0 deletions lib/model/comicViewerSettingModel.dart
Expand Up @@ -12,6 +12,9 @@ class ComicViewerSettingModel extends BaseModel {
bool _animation = true;
bool _autoDark = false;
bool _enableViewpoint = false;



ViewerConfigDatabaseProvider _databaseProvider =
ViewerConfigDatabaseProvider();
static const List backgroundColors = [
Expand Down
11 changes: 10 additions & 1 deletion lib/utils/HttpProxyAdapter.dart
Expand Up @@ -17,4 +17,13 @@ class HttpProxyAdapter extends DefaultHttpClientAdapter {
(X509Certificate cert, String host, int port) => true;
};
}
}
}

class BadCertificateAdapter extends DefaultHttpClientAdapter {
BadCertificateAdapter() {
onHttpClientCreate = (client) {
client.badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
};
}
}
87 changes: 83 additions & 4 deletions lib/utils/ProxyCacheManager.dart
@@ -1,31 +1,110 @@

import 'dart:io';

import 'package:dcomic/http/UniversalRequestModel.dart';
import 'package:dio/dio.dart';
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:http/http.dart' as http;
import'package:http/io_client.dart';

import 'HttpProxyAdapter.dart';


class ProxyCacheManager extends CacheManager with ImageCacheManager {
static const key = 'libCachedImageData';

static ProxyCacheManager _instance;
factory ProxyCacheManager(String ipAddr,int port) {
factory ProxyCacheManager({String ipAddr,int port}) {
if(_instance==null){
_instance=ProxyCacheManager._(ipAddr, port);
}
return _instance;

}

ProxyCacheManager._(String ipAddr, int port)
: super(Config(key, fileService: ProxyFileService.proxy(ipAddr, port)));
: super(Config(key, fileService: ProxyFileService.proxy(ipAddr:ipAddr, port:port)));
}

class BadCertificateCacheManager extends CacheManager with ImageCacheManager {
static const key = 'libCachedImageData';

static final BadCertificateCacheManager _instance=BadCertificateCacheManager._();
factory BadCertificateCacheManager() {
return _instance;
}

static http.Client getClient(){
var ioClient = new HttpClient()..badCertificateCallback = (X509Certificate cert, String host, int port) => true;

return IOClient(ioClient);
}

BadCertificateCacheManager._()
: super(Config(key, fileService: HttpFileService(httpClient: getClient())));
}

class DioFileService extends FileService{
Dio _dio;
CacheOptions options;

DioFileService() {
_dio = Dio();
CacheDatabase.store.then((value) {
options = CacheOptions(
store: value,
// Required.
policy: CachePolicy.request,
// Default. Checks cache freshness, requests otherwise and caches response.
hitCacheOnErrorExcept: [401, 403],
// Optional. Returns a cached response on error if available but for statuses 401 & 403.
priority: CachePriority.normal,
// Optional. Default. Allows 3 cache sets and ease cleanup.
maxStale: const Duration(days: 7),
// Very optional. Overrides any HTTP directive to delete entry past this duration.
keyBuilder: CacheOptions.defaultCacheKeyBuilder,
);
_dio.interceptors.add(PerformanceInterceptor(options: options));
});
_dio..httpClientAdapter=BadCertificateAdapter();
}

@override
Future<FileServiceResponse> get(String url,
{Map<String, String> headers = const {}}) async {
var response = await _dio.get(url,
options: Options(headers: headers, responseType: ResponseType.bytes));
return HttpGetResponse(http.StreamedResponse(
http.ByteStream.fromBytes(response.data), response.statusCode));
}
}

class ProxyFileService extends FileService {
Dio _dio;
CacheOptions options;

ProxyFileService.proxy(String ipAddr, int port) {
ProxyFileService.proxy({String ipAddr, int port}) {
_dio = Dio();
_dio..httpClientAdapter = HttpProxyAdapter(ipAddr: ipAddr, port: port);
CacheDatabase.store.then((value) {
options = CacheOptions(
store: value,
// Required.
policy: CachePolicy.request,
// Default. Checks cache freshness, requests otherwise and caches response.
hitCacheOnErrorExcept: [401, 403],
// Optional. Returns a cached response on error if available but for statuses 401 & 403.
priority: CachePriority.normal,
// Optional. Default. Allows 3 cache sets and ease cleanup.
maxStale: const Duration(days: 7),
// Very optional. Overrides any HTTP directive to delete entry past this duration.
keyBuilder: CacheOptions.defaultCacheKeyBuilder,
);
_dio.interceptors.add(PerformanceInterceptor(options: options));
});
if(ipAddr!=null&&port!=null){
_dio..httpClientAdapter = HttpProxyAdapter(ipAddr: ipAddr, port: port);
}
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/view/settings/debug_test_page.dart
Expand Up @@ -241,7 +241,7 @@ class _DebugTestPage extends State<DebugTestPage> {
child: CachedNetworkImage(
imageUrl:
'https://i.pximg.net/img-original/img/2019/08/04/00/12/45/76062188_p0.jpg',
cacheManager: ProxyCacheManager('192.168.123.47', 7890),
cacheManager: ProxyCacheManager(ipAddr:'192.168.123.47', port:7890),
httpHeaders: {'referer': 'https://www.pixiv.net/'},
),
)
Expand Down
18 changes: 16 additions & 2 deletions pubspec.lock
Expand Up @@ -63,7 +63,21 @@ packages:
name: cached_network_image
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.0"
version: "3.1.0-alpha.1"
cached_network_image_platform_interface:
dependency: transitive
description:
name: cached_network_image_platform_interface
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0-alpha.0"
cached_network_image_web:
dependency: transitive
description:
name: cached_network_image_web
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0-alpha.0"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -343,7 +357,7 @@ packages:
name: flutter_cache_manager
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.1"
version: "3.1.0"
flutter_downloader:
dependency: "direct main"
description:
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Expand Up @@ -11,7 +11,7 @@ description: A simple comic viewer application
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.4.15-beta.3+53
version: 1.4.15-beta.4+54

environment:
sdk: ">=2.7.0 <3.0.0"
Expand All @@ -21,8 +21,8 @@ dependencies:
sdk: flutter
dio: "^4.0.0"
flutter_parallax: "^0.1.2"
cached_network_image: "^3.0.0"
flutter_cache_manager: ^3.0.1
cached_network_image: "^3.1.0-alpha.1"
flutter_cache_manager: ^3.1.0
sqflite: ^2.0.0
dio_cache_interceptor: ^2.3.1
flutter_easyloading: ^3.0.0
Expand Down

0 comments on commit 95418d8

Please sign in to comment.