Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
add referer to the download task
Browse files Browse the repository at this point in the history
should fix #148
  • Loading branch information
nullxception committed Jul 5, 2024
1 parent 3da55ae commit 12d954b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/presentation/provider/booru/post_headers_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'post_headers_factory.g.dart';

String _createReferer(String url) {
String createReferer(String url) {
final uri = Uri.parse(url);
final path = uri.path.replaceAll(RegExp('/+'), '/');
return uri.replace(path: uri.hasAbsolutePath ? path : '/').toString();
Expand All @@ -22,7 +22,7 @@ Map<String, String> postHeadersFactory(
}) {
final versionRepo = ref.watch(versionRepoProvider);
final url = post.postUrl.isEmpty ? post.content.url : post.postUrl;
final referer = _createReferer(url);
final referer = createReferer(url);

return HeadersFactory.builder()
.setCookies(cookies)
Expand Down
7 changes: 5 additions & 2 deletions lib/presentation/provider/download/downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:boorusphere/data/dio/headers_factory.dart';
import 'package:boorusphere/data/repository/booru/entity/post.dart';
import 'package:boorusphere/data/repository/downloads/entity/download_entry.dart';
import 'package:boorusphere/domain/provider.dart';
import 'package:boorusphere/presentation/provider/booru/post_headers_factory.dart';
import 'package:boorusphere/presentation/provider/download/download_state.dart';
import 'package:boorusphere/presentation/provider/shared_storage_handle.dart';
import 'package:boorusphere/utils/extensions/string.dart';
Expand Down Expand Up @@ -41,8 +42,10 @@ class Downloader {
savedDir: targetPath ?? sharedStorageHandle.path,
showNotification: true,
openFileFromNotification: true,
headers:
HeadersFactory.builder().setUserAgent(versionRepo.current).build(),
headers: HeadersFactory.builder()
.setUserAgent(versionRepo.current)
.setReferer(createReferer(fileUrl))
.build(),
);

if (taskId != null) {
Expand Down

0 comments on commit 12d954b

Please # to comment.