Skip to content

Commit

Permalink
update image match rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ying_123 committed Aug 7, 2023
1 parent b7a9986 commit 734c23b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 34 deletions.
13 changes: 5 additions & 8 deletions lib/tools/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import 'package:http/http.dart';

Future<List<String>> getImages(String url) async {
Response response = await get(Uri.parse(url));
Iterable<RegExpMatch> matches = RegExp(
r'(https?://)?[\w\u4e00-\u9fa5-./@%?=]+?\.((jpe?|pn)g|gif|webp)',
caseSensitive: false)
.allMatches(response.body.replaceAll(RegExp(r'\\/'), '/'));
Iterable<RegExpMatch> matches =
RegExp(r'(https?://)?[\w\u4e00-\u9fa5-./@%?:=]+?\.((jpe?|pn)g|gif|webp)', caseSensitive: false)
.allMatches(response.body.replaceAll(RegExp(r'\\/'), '/'));
List<String> images = matches.map((m) => m.group(0)!).toSet().toList();
Uri uri = Uri.parse(url);
for (int i = 0; i < images.length; i++) {
Expand All @@ -18,8 +17,7 @@ Future<List<String>> getImages(String url) async {
images[i] = uri.origin + images[i];
}
} else {
images[i] =
uri.origin + (uri.path.isNotEmpty ? uri.path : '/') + images[i];
images[i] = uri.origin + (uri.path.isNotEmpty ? uri.path : '/') + images[i];
}
}
}
Expand All @@ -32,8 +30,7 @@ String proxyUrl(String url) {
return '$proxyUrl?url=$encoded';
}

Future<void> downloadImage(String url, String path,
{Function(double)? onProcess}) async {
Future<void> downloadImage(String url, String path, {Function(double)? onProcess}) async {
HttpClient client = HttpClient();
Uri target = Uri.parse(url);
HttpClientRequest request = await client.getUrl(target);
Expand Down
27 changes: 1 addition & 26 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
name: image_downloader
description: A app for download image from any website.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.5.0+6
version: 1.5.1+7

environment:
sdk: '>=3.0.0-122.0.dev <4.0.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
Expand All @@ -50,11 +30,6 @@ dev_dependencies:
flutter_test:
sdk: flutter

# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.0

# For information on the generic Dart part of this file, see the
Expand Down

0 comments on commit 734c23b

Please sign in to comment.