mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-06 05:49:03 +08:00
Support download zip on web
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import '../globals.dart';
|
||||
import '../platform/save_file.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
Future<void> downloadZip(int gid,
|
||||
{bool? jpnTitle, int? maxLength, bool? exportAd}) async {
|
||||
if (kIsWeb) {
|
||||
saveUriWeb(api.exportGalleryZipUrl(gid,
|
||||
jpnTitle: jpnTitle, maxLength: maxLength, exportAd: exportAd));
|
||||
return;
|
||||
}
|
||||
final cancel = CancelToken();
|
||||
final re = await api.exportGalleryZip(gid,
|
||||
jpnTitle: jpnTitle,
|
||||
@@ -16,12 +23,11 @@ Future<void> downloadZip(int gid,
|
||||
throw Exception("${data.statusCode} ${data.statusMessage}.");
|
||||
}
|
||||
final fileName = re.response.headers.value("content-disposition");
|
||||
final filenameWithoutExtension = fileName?.substring(
|
||||
fileName.indexOf("filename=\"") + 10, fileName.lastIndexOf(".")) ??
|
||||
"$gid";
|
||||
final filenameWithoutExtension = path.basenameWithoutExtension(
|
||||
getFilenameFromContentDisposition(fileName) ?? "$gid");
|
||||
try {
|
||||
final f = await platformPath.openFile(
|
||||
Uri.decodeComponent(filenameWithoutExtension), "application/zip");
|
||||
filenameWithoutExtension, "application/zip");
|
||||
try {
|
||||
await data.stream.forEach((data) {
|
||||
f.write(data);
|
||||
|
||||
Reference in New Issue
Block a user