Skip to content

Commit

Permalink
Merge branch 'dev' into bump-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-dev authored Sep 8, 2024
2 parents 0970d45 + ab01b99 commit d2d0a60
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 52 deletions.
6 changes: 5 additions & 1 deletion violet-server/.dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ REFRESH_EXPIRES=31536000
SALT=1234
REDIS_HOST=localhost
REDIS_PORT=6379
IS_MASTER_NODE=true
IS_MASTER_NODE=true

DISCORD_CLIENT_ID=1234
DISCORD_CLIENT_SECRET=1234
DISCORD_REDIRECT_URI=http://localhost:3000/api/v2/auth/discord/redirect
10 changes: 7 additions & 3 deletions violet/lib/component/hentai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,13 @@ class HentaiManager {

case 'Hitomi':
{
var urls = await HitomiManager.getImageList(qr.id().toString());
if (urls.$1.isEmpty || urls.$2.isEmpty) break;
return HitomiImageProvider(urls, qr.id().toString());
final imgList =
await HitomiManager.getImageList(qr.id().toString());
if (imgList.bigThumbnails.isEmpty ||
imgList.bigThumbnails.isEmpty) {
break;
}
return HitomiImageProvider(imgList, qr.id().toString());
}

case 'Hisoki':
Expand Down
17 changes: 14 additions & 3 deletions violet/lib/component/hitomi/hitomi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@ import 'package:violet/script/script_manager.dart';
import 'package:violet/settings/settings.dart';
import 'package:violet/variables.dart';

class ImageList {
final List<String> urls;
final List<String> bigThumbnails;
final List<String>? smallThumbnails;

const ImageList({
required this.urls,
required this.bigThumbnails,
this.smallThumbnails,
});
}

class HitomiManager {
// [Image List], [Big Thumbnail List (Perhaps only two are valid.)], [Small Thubmnail List]
static Future<(List<String>, List<String>, List<String>)> getImageList(
String id) async {
static Future<ImageList> getImageList(String id) async {
final result = await ScriptManager.runHitomiGetImageList(int.parse(id));
if (result != null) return result;
return const (<String>[], <String>[], <String>[]);
return const ImageList(urls: [], bigThumbnails: []);
}

static int? getArticleCount(String classification, String name) {
Expand Down
38 changes: 22 additions & 16 deletions violet/lib/component/hitomi/hitomi_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import 'package:violet/network/wrapper.dart' as http;
import 'package:violet/script/script_manager.dart';

class HitomiImageProvider extends VioletImageProvider {
(List<String>, List<String>, List<String>?) urls;
ImageList imageList;
String id;

HitomiImageProvider(this.urls, this.id);
HitomiImageProvider(this.imageList, this.id);

@override
Future<void> init() async {}

@override
Future<List<String>> getSmallImagesUrl() async {
return urls.$3 ?? [];
return imageList.smallThumbnails ?? [];
}

@override
Future<String> getThumbnailUrl() async {
return urls.$2[0];
return imageList.bigThumbnails[0];
}

@override
Expand All @@ -41,35 +41,41 @@ class HitomiImageProvider extends VioletImageProvider {

@override
Future<String> getImageUrl(int page) async {
return urls.$1[page];
return imageList.urls[page];
}

@override
bool canGetImageUrlSync() => true;

@override
String getImageUrlSync(int page) => urls.$1[page];
String getImageUrlSync(int page) => imageList.urls[page];

@override
int length() {
return urls.$1.length;
return imageList.urls.length;
}

List<double>? _heightCache;
List<double>? _estimatedCache;

@override
Future<double> getEstimatedImageHeight(int page, double baseWidth) async {
if (urls.$3 == null || urls.$3!.length <= page) return -1;
if (imageList.smallThumbnails == null ||
imageList.smallThumbnails!.length <= page) {
return -1;
}

if (_estimatedCache == null) {
_estimatedCache = List<double>.filled(urls.$3!.length, 0);
_estimatedCache =
List<double>.filled(imageList.smallThumbnails!.length, 0);
} else if (_estimatedCache![page] != 0) {
return _estimatedCache![page];
}

final header = await getHeader(page);
final image = (await http.get(urls.$3![page], headers: header)).bodyBytes;
final image =
(await http.get(imageList.smallThumbnails![page], headers: header))
.bodyBytes;
final thumbSize = ImageSizeGetter.getSize(MemoryInput(image));

// w1:h1=w2:h2
Expand All @@ -91,34 +97,34 @@ class HitomiImageProvider extends VioletImageProvider {

@override
Future<void> refresh() async {
urls = await HitomiManager.getImageList(id);
imageList = await HitomiManager.getImageList(id);
}

@override
Future<void> refreshPartial(List<bool> target) async {
if (urls.$1.length != target.length) {
if (imageList.urls.length != target.length) {
await refresh();
return;
}

final turls = await HitomiManager.getImageList(id);

for (var i = 0; i < turls.$1.length; i++) {
if (target[i]) urls.$1[i] = turls.$1[i];
for (var i = 0; i < turls.urls.length; i++) {
if (target[i]) imageList.urls[i] = turls.urls[i];
}
}

@override
Future<double> getOriginalImageHeight(int page) async {
if (_heightCache == null) {
_heightCache = List<double>.filled(urls.$3!.length, 0);
_heightCache = List<double>.filled(imageList.smallThumbnails!.length, 0);
} else if (_heightCache![page] != 0) {
return _heightCache![page];
}

final info = await ScriptManager.getGalleryInfo(id);
if (info == null) {
_heightCache = List<double>.filled(urls.$3!.length, -1);
_heightCache = List<double>.filled(imageList.smallThumbnails!.length, -1);
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/download/download_item_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ class _ThumbnailWidget extends StatelessWidget {
future: HitomiManager.getImageList(id.toString()).then((value) async {
var header =
await ScriptManager.runHitomiGetHeaderContent(id.toString());
return (value.$1[0], header);
return (value.urls[0], header);
}),
builder:
(context, AsyncSnapshot<(String, Map<String, String>)> snapshot) {
Expand Down
7 changes: 4 additions & 3 deletions violet/lib/pages/viewer/overlay/viewer_thumbnails.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ class _ViewerThumbnailState extends State<ViewerThumbnail> {
ProviderManager.insert(_pageInfo.id * 1000000, prov);
} else {
try {
var urls =
var imgList =
await HitomiManager.getImageList(_pageInfo.id.toString());
if (urls.$1.isNotEmpty && urls.$2.isNotEmpty) {
prov = HitomiImageProvider(urls, _pageInfo.id.toString());
if (imgList.urls.isNotEmpty &&
imgList.bigThumbnails.isNotEmpty) {
prov = HitomiImageProvider(imgList, _pageInfo.id.toString());
ProviderManager.insert(_pageInfo.id * 1000000, prov);
}
} catch (_) {}
Expand Down
20 changes: 20 additions & 0 deletions violet/lib/script/freezed/script_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This source code is a part of Project Violet.
// Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License.

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:flutter/foundation.dart';

part 'script_model.freezed.dart';
part 'script_model.g.dart';

@freezed
class ScriptImageList with _$ScriptImageList {
const factory ScriptImageList({
required List<String> result,
required List<String> btresult,
required List<String> stresult,
}) = _ScriptImageList;

factory ScriptImageList.fromJson(Map<String, Object?> json) =>
_$ScriptImageListFromJson(json);
}
Loading

0 comments on commit d2d0a60

Please sign in to comment.