Skip to content

Commit 0edd4c3

Browse files
committed
feat(settings): add an option to enable/disable fetching cover images using CORS proxy
1 parent 67a1a54 commit 0edd4c3

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/app/models/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface ProxySettings {
2525
enabled: boolean;
2626
name?: string;
2727
apiKey?: string;
28+
shouldFetchImages?: boolean;
2829
}
2930

3031
export enum View {

src/app/modules/settings/general/general.component.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@
4848
/>
4949
</div>
5050
</li>
51+
<li *ngIf="settings.proxy.enabled" mdcListItem>
52+
<i mdcListItemGraphic class="material-icons">image</i>
53+
<span mdcListItemText>
54+
Use the proxy to fetch images
55+
<span mdcListItemSecondaryText
56+
>Will fetch the episodes cover images using the proxy on loading
57+
failures</span
58+
>
59+
</span>
60+
<div mdcListItemMeta mdcSwitch>
61+
<input
62+
mdcSwitchInput
63+
type="checkbox"
64+
[(ngModel)]="settings.proxy.shouldFetchImages"
65+
/>
66+
</div>
67+
</li>
5168
<li *ngIf="browser.isWebExtension" mdcListItem>
5269
<i mdcListItemGraphic class="material-icons">open_in_new</i>
5370
<span mdcListItemText>

src/app/modules/shared/pipes/proxy.pipe.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Pipe, PipeTransform } from '@angular/core';
22
import { ScraperService } from 'src/app/services/scraper.service';
3+
import { SettingsService } from 'src/app/services/settings.service';
34

45
export type ProxyPipeAction = 'resolveUrl';
56
export type ProxyPipeValueType = 'image';
@@ -9,7 +10,10 @@ export type ProxyPipeValueType = 'image';
910
pure: true,
1011
})
1112
export class ProxyPipe implements PipeTransform {
12-
constructor(protected scraper: ScraperService) {}
13+
constructor(
14+
protected settings: SettingsService,
15+
protected scraper: ScraperService
16+
) {}
1317

1418
private getImageOrFallback = (
1519
path: string,
@@ -30,12 +34,15 @@ export class ProxyPipe implements PipeTransform {
3034
): Promise<string> {
3135
switch (action) {
3236
case 'resolveUrl': {
33-
const url = this.scraper.resolveUrl(value);
3437
switch (type) {
3538
case 'image':
36-
return await this.getImageOrFallback(value, url);
39+
if (!this.settings.proxy.shouldFetchImages) {
40+
return value;
41+
}
42+
const fallback = this.scraper.resolveUrl(value);
43+
return await this.getImageOrFallback(value, fallback);
3744
default:
38-
return url;
45+
return this.scraper.resolveUrl(value);
3946
}
4047
}
4148
default:

src/app/services/settings.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class SettingsService {
8080
: {
8181
enabled: true,
8282
name: CORSProxies[0].name,
83+
shouldFetchImages: false,
8384
},
8485
openInNewTab:
8586
!this.browser.isWebExtension || this.browser.isFirefox ? true : false,

0 commit comments

Comments
 (0)