Skip to content

Commit 60a2200

Browse files
committed
fix: detect file ext
fix: add proxy to reddit img
1 parent 8d46494 commit 60a2200

File tree

6 files changed

+47
-16
lines changed

6 files changed

+47
-16
lines changed

src/app/app-routing.module.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const yandereMod = () => import('./yandere/yandere.module').then(m => m.YandereM
4141
const pixivMod = () => import('./pixiv/pixiv.module').then(m => m.PixivModule)
4242
const fileMod = () => import('./file/file.module').then(m => m.FileModule)
4343

44+
const COMPARE_OUTLET_NAME = 'right'
45+
4446
const moduleMap = new Map<string, LoadChildrenCallback>()
4547
.set(IMGUR_PATH, imgurMod)
4648
.set(MANGADEX_PATH, mangadexMod)
@@ -50,17 +52,29 @@ const routes: Routes = [
5052
{ path: '', loadChildren: linkParserMod },
5153
{ path: LIST_PATH, loadChildren: () => import('./list/list.module').then(m => m.ListModule) },
5254
{ path: IMGUR_PATH, loadChildren: imgurMod },
55+
{ outlet: COMPARE_OUTLET_NAME, path: IMGUR_PATH, loadChildren: imgurMod },
5356
{ path: MANGADEX_PATH, loadChildren: mangadexMod },
57+
{ outlet: COMPARE_OUTLET_NAME, path: MANGADEX_PATH, loadChildren: mangadexMod },
5458
{ path: READ_PATH, loadChildren: readMod },
59+
{ outlet: COMPARE_OUTLET_NAME, path: READ_PATH, loadChildren: readMod },
5560
{ path: TELEGRAPH_PATH, loadChildren: telegraphMod },
61+
{ outlet: COMPARE_OUTLET_NAME, path: TELEGRAPH_PATH, loadChildren: telegraphMod },
5662
{ path: REDDIT_PATH, loadChildren: redditMod },
63+
{ outlet: COMPARE_OUTLET_NAME, path: REDDIT_PATH, loadChildren: redditMod },
5764
{ path: ZENKO_PATH, loadChildren: zenkoMod },
65+
{ outlet: COMPARE_OUTLET_NAME, path: ZENKO_PATH, loadChildren: zenkoMod },
5866
{ path: NHENTAI_PATH, loadChildren: nhentaiMod },
67+
{ outlet: COMPARE_OUTLET_NAME, path: NHENTAI_PATH, loadChildren: nhentaiMod },
5968
{ path: COMICK_PATH, loadChildren: comickMod },
69+
{ outlet: COMPARE_OUTLET_NAME, path: COMICK_PATH, loadChildren: comickMod },
6070
{ path: YANDERE_PATH, loadChildren: yandereMod },
71+
{ outlet: COMPARE_OUTLET_NAME, path: YANDERE_PATH, loadChildren: yandereMod },
6172
{ path: PIXIV_PATH, loadChildren: pixivMod },
73+
{ outlet: COMPARE_OUTLET_NAME, path: PIXIV_PATH, loadChildren: pixivMod },
6274
{ path: FILE_PATH, loadChildren: fileMod },
75+
{ outlet: COMPARE_OUTLET_NAME, path: FILE_PATH, loadChildren: fileMod },
6376
{ matcher: urlMatcher, loadChildren: linkParserMod },
77+
{ outlet: COMPARE_OUTLET_NAME, matcher: urlMatcher, loadChildren: linkParserMod },
6478
{ path: '**', component: PageNotFoundComponent }
6579
];
6680

src/app/app.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ const SCALE_GAP = 128;
77

88
@Component({
99
selector: 'app-root',
10-
template: `<router-outlet></router-outlet>`
10+
template: `<div><router-outlet></router-outlet></div><div><router-outlet name="right"></router-outlet></div>`,
11+
styles: [`
12+
// :host {
13+
// display: flex;
14+
// }
15+
`]
1116
})
1217
export class AppComponent {
1318
constructor(public lang: LangService, private route: ActivatedRoute) {
@@ -26,7 +31,7 @@ export class AppComponent {
2631
}
2732
})
2833
}
29-
34+
3035
private readonly document = inject(DOCUMENT);
3136

3237
@HostListener('window:resize')

src/app/reddit/data-access/reddit.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Injectable } from '@angular/core';
33
import { Observable, map } from 'rxjs';
44
import { environment } from '../../../environments/environment';
55
import { CompositionEpisode } from '../../common/common-read';
6+
import { Base64 } from '../../shared/utils';
67

78
@Injectable({
89
providedIn: 'root'
@@ -29,8 +30,9 @@ export class RedditService {
2930
nsfw: post.thumbnail == "nsfw" || post.over_18,
3031
images: imgs.map((i: any): any => {
3132
const ext = (media_metadata[i.media_id]?.m).replace('image/', '');
33+
const imgSrc = `https://i.redd.it/${i.media_id}.${ext ?? 'jpg'}`
3234
return {
33-
src: `https://i.redd.it/${i.media_id}.${ext ?? 'jpg'}`,
35+
src: environment.proxy + Base64.toBase64(imgSrc),
3436
height: (media_metadata[i.media_id]?.s).y,
3537
width: (media_metadata[i.media_id]?.s).x,
3638
}

src/app/shared/ui/file-change/file-change.component.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { FileService } from '../../../file/data-access/file.service';
33
import { Router } from '@angular/router';
44
import { FILE_PATH } from '../../../app-routing.module';
55
import { LangService } from '../../data-access/lang.service';
6-
import { DomManipulationService } from '../../data-access';
76

87
@Component({
98
selector: 'app-file-change',
@@ -13,8 +12,10 @@ import { DomManipulationService } from '../../data-access';
1312
export class FileChangeComponent implements OnInit {
1413
ngOnInit(): void {
1514
this.initFileInput();
16-
15+
1716
if ("launchQueue" in window) {
17+
console.log(`"launchQueue" in window`);
18+
1819
(window as any).launchQueue.setConsumer(async (launchParams: any) => {
1920
const file: File = launchParams.files[0];
2021
this.fileHandler(file)
@@ -41,17 +42,26 @@ export class FileChangeComponent implements OnInit {
4142
this.fs.file = file;
4243

4344
// should be output
44-
const t = this.getRouteType(file.type)
45+
const t = this.getRouteType(file)
4546

4647
if (t) {
4748
const url = `/${FILE_PATH}/${t}`;
4849
this.router.navigateByUrl(url)
4950
}
5051
}
5152

52-
getRouteType(fileType: string): string | undefined {
53-
if (fileType.search(/zip|cbz/) >= 0) return "zip"
54-
else if (fileType.includes('pdf')) return "pdf"
53+
getRouteType(file: File): string | undefined {
54+
const fileType = file.type
55+
56+
if (fileType) {
57+
if (fileType.search(/zip|cbz/) >= 0) return "zip"
58+
else if (fileType.includes('pdf')) return "pdf"
59+
} else {
60+
const fileName = file.name
61+
const extension = fileName.substring(fileName.lastIndexOf('.')).toLowerCase();
62+
63+
return ['cbz', 'zip', 'pdf'].includes(extension) ? extension : undefined
64+
}
5565

5666
return;
5767
}
@@ -70,18 +80,18 @@ export class FileChangeComponent implements OnInit {
7080
}
7181

7282
openFileDialog() {
73-
83+
7484
this.input.click();
7585
}
76-
86+
7787
@HostListener('window:keydown', ['$event'])
7888
handleKeyboardEvent(event: KeyboardEvent) {
7989

8090
const code = event.ctrlKey ? `Ctrl+${event.code}` : event.code
8191

82-
if(code == "Ctrl+KeyO") {
92+
if (code == "Ctrl+KeyO") {
8393
event.preventDefault();
84-
94+
8595
this.openFileDialog()
8696
}
8797
}

src/app/shared/ui/viewer/viewer.component.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
:host {
2-
--W: 100vw;
2+
// --W: 100vw;
33
--H: 100dvh;
44
display: block;
55
container-type: size;
66
container-name: view;
7-
width: var(--W);
7+
// width: var(--W);
88
height: var(--H);
99
transition: all var(--t) ease-in-out;
1010

src/environments/environment.development.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const PROXY = `http://localhost:3000/api/?url=`
1+
const PROXY = `https://proxy-seven-xi.vercel.app/api?url=`
22

33
export const environment = {
44
proxy: PROXY,

0 commit comments

Comments
 (0)