Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX : SushiScans : cloudflare workaround #5939

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/web/mjs/connectors/SushiScans.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import WordPressMangastream from './templates/WordPressMangastream.mjs';
import HeaderGenerator from '../engine/HeaderGenerator.mjs';

export default class SushiScans extends WordPressMangastream {

Expand All @@ -9,6 +10,7 @@ export default class SushiScans extends WordPressMangastream {
this.tags = [ 'manga', 'french' ];
this.url = 'https://sushiscan.net';
this.path = '/manga/list-mode/';
this.requestOptions.headers.set('x-referer', this.url);
}

async _getPages(chapter) {
Expand All @@ -26,7 +28,21 @@ export default class SushiScans extends WordPressMangastream {
const uri = new URL(chapter.id, this.url);
let request = new Request(uri, this.requestOptions);
let data = await Engine.Request.fetchUI(request, script);
data = data.filter(link => !link.includes('histats.com'));

// HACK: bypass 'i0.wp.com' image CDN to ensure original images are loaded directly from host
return data.map(link => this.getAbsolutePath(link, request.url).replace(/\/i\d+\.wp\.com/, '')).filter(link => !link.includes('histats.com'));
return data.map(link => this.createConnectorURI(this.getAbsolutePath(link, request.url).replace(/\/i\d+\.wp\.com/, '')));
}

async _handleConnectorURI(payload) {
await this.wait(1500);
let request = new Request(payload, this.requestOptions);
request.headers.set('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8');
request.headers.set('x-user-agent', HeaderGenerator.randomUA());
let response = await fetch(request);
let data = await response.blob();
data = await this._blobToBuffer(data);
this._applyRealMime(data);
return data;
}
}