1+ import { HttpClient , HttpHeaders } from '@angular/common/http' ;
2+ import { inject , Injectable , PLATFORM_ID } from '@angular/core' ;
3+ import { environment } from '../../../environments/environment' ;
4+ import { Observable , map } from 'rxjs' ;
5+ import { CompositionEpisode , CompositionImage } from '../@common-read' ;
6+ import { ProxyService } from '../../shared/data-access/proxy.service' ;
7+ import { isPlatformServer } from '@angular/common' ;
8+ interface ImgchestRespCompImage {
9+ id : string ;
10+ description : string ;
11+ link : string ;
12+ position : number
13+ created : string ;
14+ }
15+ interface ImgchestRespComp {
16+ id : string ;
17+ title : string ;
18+ username : string ;
19+ privacy : string ;
20+ report_status : number ;
21+ views : number ;
22+ nsfw : number ;
23+ image_count : number ;
24+ created : string ;
25+ images : Array < ImgchestRespCompImage > ;
26+ }
27+ interface ImgchestResp {
28+ data : any | ImgchestRespComp
29+ }
30+
31+ @Injectable ( {
32+ providedIn : 'root'
33+ } )
34+ export class ImgchestService {
35+ private readonly clientId : string = 'T0eSFX9IOg0Okcg7g3UN7jp8MDreLglRyYKYkw2Gd74de321' ;
36+ platformId = inject ( PLATFORM_ID )
37+
38+ proxy : ProxyService = inject ( ProxyService )
39+ http : HttpClient = inject ( HttpClient )
40+
41+ constructor ( ) { }
42+
43+ getComposition ( id : string ) : Observable < CompositionEpisode > {
44+ const headers = new HttpHeaders ( {
45+ 'Authorization' : `Bearer ${ this . clientId } `
46+ } ) ;
47+
48+ const url = isPlatformServer ( this . platformId )
49+ ? environment . imgchestHost + id
50+ : this . proxy . proxyUrl ( environment . imgchestHost + id ) ;
51+
52+ return this . http . get < ImgchestResp > ( url , { headers } )
53+ . pipe ( map ( ( data : ImgchestResp ) => { return this . map ( data . data ) } ) )
54+ }
55+
56+
57+ map ( data : ImgchestRespComp ) : CompositionEpisode {
58+ const res : CompositionEpisode = {
59+ title : data . title ,
60+ episode : 0 ,
61+ nsfw : ( data . nsfw ) as unknown as boolean ,
62+ images : data . images . map ( ( i ) : CompositionImage => {
63+ return {
64+ src : this . proxy . proxyUrl ( i . link ) ,
65+ alt : i . description ,
66+ }
67+ } )
68+
69+ }
70+ return res ;
71+ }
72+
73+ }
74+
75+ /**
76+ {
77+ "data": {
78+ "id": "wl7l2rvgo4x",
79+ "title": null,
80+ "username": "Anonymous",
81+ "privacy": "hidden",
82+ "report_status": 1,
83+ "views": 1,
84+ "nsfw": 0,
85+ "image_count": 3,
86+ "created": "2025-06-13T13:37:01.000000Z",
87+ "images": [
88+ {
89+ "id": "46acqe3zkk7",
90+ "description": null,
91+ "link": "https:\/\/cdn.imgchest.com\/files\/46acqe3zkk7.jpg",
92+ "position": 1,
93+ "created": "2025-06-13T13:37:01.000000Z"
94+ },
95+ {
96+ "id": "yvdcwog6vpy",
97+ "description": null,
98+ "link": "https:\/\/cdn.imgchest.com\/files\/yvdcwog6vpy.jpg",
99+ "position": 2,
100+ "created": "2025-06-13T13:37:02.000000Z"
101+ },
102+ {
103+ "id": "yxkczok2ro7",
104+ "description": null,
105+ "link": "https:\/\/cdn.imgchest.com\/files\/yxkczok2ro7.jpg",
106+ "position": 3,
107+ "created": "2025-06-13T13:37:03.000000Z"
108+ }
109+ ]
110+ }
111+ }
112+
113+ */
0 commit comments