Skip to content

Commit

Permalink
Add HTTP2, Add support for multiple parts download using range requests
Browse files Browse the repository at this point in the history
  • Loading branch information
normalllll committed Oct 22, 2024
1 parent f0c9b43 commit ae0cf59
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 320 deletions.
1 change: 1 addition & 0 deletions lib/components/yande_image/image_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class YandeExtendedImageProvider extends ImageProvider<ExtendedNetworkImageProvi

final Uint8List bytes = await yandeClient.downloadToMemory(
url: url,
autoMultiplePart: false,
progressCallback: (BigInt received, BigInt total) async {
// print('received: $received, total: $total');
chunkEvents?.add(
Expand Down
1 change: 0 additions & 1 deletion lib/data_list_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ abstract class DataListSource<T> extends LoadingMoreBase<T> {
nextClear = false;
}
addAll(list);
print(length);
_page++;
if (!_initialized) {
_initialized = true;
Expand Down
8 changes: 7 additions & 1 deletion lib/pages/downloads/logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ class DownloadTask extends _$DownloadTask {
} else {
EasyLoading.showToast(i18n.downloads.messages.downloadStartWithId(state.post.id));
}
yandeClient.downloadToMemory(url: state.post.fileUrl ?? state.post.jpegUrl, progressCallback: (received, total) => updateProgress(received, total)).then((bytes) {
yandeClient
.downloadToMemory(
url: state.post.fileUrl ?? state.post.jpegUrl,
autoMultiplePart: true,
progressCallback: (received, total) => updateProgress(received, total),
)
.then((bytes) {
try {
ImageSaver.saveImage(bytes, '${state.post.id}.${state.post.fileExt}');
EasyLoading.showSuccess(i18n.downloads.messages.downloadCompletedWithId(state.post.id));
Expand Down
65 changes: 2 additions & 63 deletions lib/pages/post_search/post_search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import 'package:flutter/material.dart';
import 'package:yande_gui/components/translated_tag/translated_tag.dart';
import 'package:yande_gui/i18n.dart';
import 'package:yande_gui/pages/post_list/post_list_page.dart';
import 'package:yande_gui/services/tag_translations_service.dart';
import 'package:yande_gui/widgets/auto_scaffold/auto_scaffold.dart';
import 'package:yande_gui/widgets/tag/tag.dart';

class PostSearchPage extends StatefulWidget {
const PostSearchPage({super.key});

Expand All @@ -17,61 +16,7 @@ class _PostSearchPageState extends State<PostSearchPage> {
final ScrollController _textScrollController = ScrollController();
bool _showClearButton = false;

static const _tags = [
'rating:s',
'rating:q',
'rating:e',
'uncensored',
'nekomimi',
'animal_ears',
'loli',
'tail',
'indie_virtual_youtuber',
'character_design',
'hololive',
'hololive_english',
'azur_lane',
'blue_archive',
'honkai:_star_rail',
'genshin_impact',
'breasts',
'nipples',
'erect_nipples',
'cameltoe',
'feet',
'pussy',
'pussy_juice',
'masturbation',
'bondage',
'dildo',
'anal_beads',
'vibrator',
'ass',
'anal',
'anus',
'no_bra',
'nopan',
'naked',
'topless',
'bottomless',
'stockings',
'pantyhose',
'swimsuits',
'fishnets',
'thighhighs',
'torn_clothes',
'dakimakura',
'seifuku',
'dress',
'bikini',
'thong',
'pantsu',
'open_shirt',
'selfie',
'see_through',
'wet',
'yuri',
];
static final _tags = TagTranslationsService.knowTags;

Widget _buildSearchField() {
return TextField(
Expand Down Expand Up @@ -152,12 +97,6 @@ class _PostSearchPageState extends State<PostSearchPage> {
),
);
},
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => PostListPage(tags: _textController.text.split(' '))));
},
child: const Icon(Icons.search_outlined, color: Colors.white),
),
);
}
}
3 changes: 2 additions & 1 deletion lib/services/tag_translations_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:ui';

import 'package:flutter/services.dart';

Expand All @@ -21,6 +20,8 @@ class TagTranslationsService {
_ => _en,
};

static List<String> get knowTags => _en.entries.map((e)=>e.key).toList();

static Future<void> loadAll() async {
String enJsonString = await rootBundle.loadString('assets/tag_translations/en.json');
String jaJsonString = await rootBundle.loadString('assets/tag_translations/ja.json');
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rust/api/rustc.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.4.0.
// @generated by `flutter_rust_bridge`@ 2.5.0.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

Expand Down
8 changes: 2 additions & 6 deletions lib/src/rust/api/yande_client.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.4.0.
// @generated by `flutter_rust_bridge`@ 2.5.0.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

Expand All @@ -11,13 +11,9 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<YandeClient>>
abstract class YandeClient implements RustOpaqueInterface {
Future<void> downloadToFile(
{required String url,
required String filePath,
required FutureOr<void> Function(BigInt, BigInt) progressCallback});

Future<Uint8List> downloadToMemory(
{required String url,
required bool autoMultiplePart,
required FutureOr<void> Function(BigInt, BigInt) progressCallback});

Future<List<Post>> getPosts(
Expand Down
75 changes: 16 additions & 59 deletions lib/src/rust/frb_generated.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.4.0.
// @generated by `flutter_rust_bridge`@ 2.5.0.

// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field

Expand Down Expand Up @@ -66,10 +66,10 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
kDefaultExternalLibraryLoaderConfig;

@override
String get codegenVersion => '2.4.0';
String get codegenVersion => '2.5.0';

@override
int get rustContentHash => -323707379;
int get rustContentHash => -1062816985;

static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig(
Expand All @@ -82,15 +82,10 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
abstract class RustLibApi extends BaseApi {
String crateApiRustcRustcVersion();

Future<void> crateApiYandeClientYandeClientDownloadToFile(
{required YandeClient that,
required String url,
required String filePath,
required FutureOr<void> Function(BigInt, BigInt) progressCallback});

Future<Uint8List> crateApiYandeClientYandeClientDownloadToMemory(
{required YandeClient that,
required String url,
required bool autoMultiplePart,
required FutureOr<void> Function(BigInt, BigInt) progressCallback});

Future<List<Post>> crateApiYandeClientYandeClientGetPosts(
Expand Down Expand Up @@ -143,70 +138,38 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: [],
);

@override
Future<void> crateApiYandeClientYandeClientDownloadToFile(
{required YandeClient that,
required String url,
required String filePath,
required FutureOr<void> Function(BigInt, BigInt) progressCallback}) {
return handler.executeNormal(NormalTask(
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerYandeClient(
that, serializer);
sse_encode_String(url, serializer);
sse_encode_String(filePath, serializer);
sse_encode_DartFn_Inputs_usize_usize_Output_unit_AnyhowException(
progressCallback, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 2, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_unit,
decodeErrorData: sse_decode_AnyhowException,
),
constMeta: kCrateApiYandeClientYandeClientDownloadToFileConstMeta,
argValues: [that, url, filePath, progressCallback],
apiImpl: this,
));
}

TaskConstMeta get kCrateApiYandeClientYandeClientDownloadToFileConstMeta =>
const TaskConstMeta(
debugName: "YandeClient_download_to_file",
argNames: ["that", "url", "filePath", "progressCallback"],
);

@override
Future<Uint8List> crateApiYandeClientYandeClientDownloadToMemory(
{required YandeClient that,
required String url,
required bool autoMultiplePart,
required FutureOr<void> Function(BigInt, BigInt) progressCallback}) {
return handler.executeNormal(NormalTask(
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerYandeClient(
that, serializer);
sse_encode_String(url, serializer);
sse_encode_bool(autoMultiplePart, serializer);
sse_encode_DartFn_Inputs_usize_usize_Output_unit_AnyhowException(
progressCallback, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 3, port: port_);
funcId: 2, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_list_prim_u_8_strict,
decodeErrorData: sse_decode_AnyhowException,
),
constMeta: kCrateApiYandeClientYandeClientDownloadToMemoryConstMeta,
argValues: [that, url, progressCallback],
argValues: [that, url, autoMultiplePart, progressCallback],
apiImpl: this,
));
}

TaskConstMeta get kCrateApiYandeClientYandeClientDownloadToMemoryConstMeta =>
const TaskConstMeta(
debugName: "YandeClient_download_to_memory",
argNames: ["that", "url", "progressCallback"],
argNames: ["that", "url", "autoMultiplePart", "progressCallback"],
);

@override
Expand All @@ -224,7 +187,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_u_32(limit, serializer);
sse_encode_u_32(page, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 4, port: port_);
funcId: 3, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_list_post,
Expand Down Expand Up @@ -252,7 +215,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
that, serializer);
sse_encode_i_64(postId, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 5, port: port_);
funcId: 4, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_similar,
Expand All @@ -277,7 +240,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_opt_String_array_3(ips, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 6, port: port_);
funcId: 5, port: port_);
},
codec: SseCodec(
decodeSuccessData:
Expand Down Expand Up @@ -1043,22 +1006,16 @@ class YandeClientImpl extends RustOpaque implements YandeClient {
RustLib.instance.api.rust_arc_decrement_strong_count_YandeClientPtr,
);

Future<void> downloadToFile(
Future<Uint8List> downloadToMemory(
{required String url,
required String filePath,
required bool autoMultiplePart,
required FutureOr<void> Function(BigInt, BigInt) progressCallback}) =>
RustLib.instance.api.crateApiYandeClientYandeClientDownloadToFile(
RustLib.instance.api.crateApiYandeClientYandeClientDownloadToMemory(
that: this,
url: url,
filePath: filePath,
autoMultiplePart: autoMultiplePart,
progressCallback: progressCallback);

Future<Uint8List> downloadToMemory(
{required String url,
required FutureOr<void> Function(BigInt, BigInt) progressCallback}) =>
RustLib.instance.api.crateApiYandeClientYandeClientDownloadToMemory(
that: this, url: url, progressCallback: progressCallback);

Future<List<Post>> getPosts(
{required List<String> tags,
required int limit,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rust/frb_generated.io.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.4.0.
// @generated by `flutter_rust_bridge`@ 2.5.0.

// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field

Expand Down
2 changes: 1 addition & 1 deletion lib/src/rust/yande/model/post.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.4.0.
// @generated by `flutter_rust_bridge`@ 2.5.0.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

Expand Down
2 changes: 1 addition & 1 deletion lib/src/rust/yande/model/similar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.4.0.
// @generated by `flutter_rust_bridge`@ 2.5.0.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: yande_gui
description: "Cross-platform GUI for yande"
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 0.5.8+24
version: 0.6.0+25

environment:
sdk: '>=3.5.0 <4.0.0'
Expand Down
Loading

0 comments on commit ae0cf59

Please sign in to comment.