juice-shop
52 строки · 2.3 Кб
1/*
2* Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3* SPDX-License-Identifier: MIT
4*/
5
6import { environment } from '../../environments/environment'
7import { HttpClient } from '@angular/common/http'
8import { Injectable } from '@angular/core'
9import { type Observable } from 'rxjs'
10import { catchError, map } from 'rxjs/operators'
11import { type Challenge } from '../Models/challenge.model'
12
13@Injectable({
14providedIn: 'root'
15})
16export class ChallengeService {
17private readonly hostServer = environment.hostServer
18private readonly host = this.hostServer + '/api/Challenges'
19constructor (private readonly http: HttpClient) { }
20
21find (params?: any): Observable<Challenge[]> {
22return this.http.get(this.host + '/', { params }).pipe(map((response: any) => response.data), catchError((err) => { throw err }))
23}
24
25repeatNotification (challengeName: string) {
26return this.http.get(this.hostServer + '/rest/repeat-notification', { params: { challenge: challengeName }, responseType: 'text' as const }).pipe(catchError((err) => { throw err }))
27}
28
29continueCode () {
30return this.http.get(this.hostServer + '/rest/continue-code').pipe(map((response: any) => response.continueCode), catchError((err) => { throw err }))
31}
32
33continueCodeFindIt () {
34return this.http.get(this.hostServer + '/rest/continue-code-findIt').pipe(map((response: any) => response.continueCode), catchError((err) => { throw err }))
35}
36
37continueCodeFixIt () {
38return this.http.get(this.hostServer + '/rest/continue-code-fixIt').pipe(map((response: any) => response.continueCode), catchError((err) => { throw err }))
39}
40
41restoreProgress (continueCode: string) {
42return this.http.put(this.hostServer + '/rest/continue-code/apply/' + continueCode, {}).pipe(map((response: any) => response.data), catchError((err) => { throw err }))
43}
44
45restoreProgressFindIt (continueCode: string) {
46return this.http.put(this.hostServer + '/rest/continue-code-findIt/apply/' + continueCode, {}).pipe(map((response: any) => response.data), catchError((err) => { throw err }))
47}
48
49restoreProgressFixIt (continueCode: string) {
50return this.http.put(this.hostServer + '/rest/continue-code-fixIt/apply/' + continueCode, {}).pipe(map((response: any) => response.data), catchError((err) => { throw err }))
51}
52}
53