diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
commit | 88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch) | |
tree | b242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /client/src/app/shared/blocklist | |
parent | 53a94c7cfa8368da4cd248d65df8346905938f0c (diff) | |
parent | 9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff) | |
download | PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip |
Merge branch 'develop' into pr/1217
Diffstat (limited to 'client/src/app/shared/blocklist')
-rw-r--r-- | client/src/app/shared/blocklist/account-block.model.ts | 14 | ||||
-rw-r--r-- | client/src/app/shared/blocklist/blocklist.service.ts | 135 | ||||
-rw-r--r-- | client/src/app/shared/blocklist/index.ts | 2 |
3 files changed, 151 insertions, 0 deletions
diff --git a/client/src/app/shared/blocklist/account-block.model.ts b/client/src/app/shared/blocklist/account-block.model.ts new file mode 100644 index 000000000..e7b433d88 --- /dev/null +++ b/client/src/app/shared/blocklist/account-block.model.ts | |||
@@ -0,0 +1,14 @@ | |||
1 | import { AccountBlock as AccountBlockServer } from '../../../../../shared' | ||
2 | import { Account } from '../account/account.model' | ||
3 | |||
4 | export class AccountBlock implements AccountBlockServer { | ||
5 | byAccount: Account | ||
6 | blockedAccount: Account | ||
7 | createdAt: Date | string | ||
8 | |||
9 | constructor (block: AccountBlockServer) { | ||
10 | this.byAccount = new Account(block.byAccount) | ||
11 | this.blockedAccount = new Account(block.blockedAccount) | ||
12 | this.createdAt = block.createdAt | ||
13 | } | ||
14 | } | ||
diff --git a/client/src/app/shared/blocklist/blocklist.service.ts b/client/src/app/shared/blocklist/blocklist.service.ts new file mode 100644 index 000000000..c1f7312f0 --- /dev/null +++ b/client/src/app/shared/blocklist/blocklist.service.ts | |||
@@ -0,0 +1,135 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { environment } from '../../../environments/environment' | ||
3 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
4 | import { RestExtractor, RestPagination, RestService } from '../rest' | ||
5 | import { SortMeta } from 'primeng/api' | ||
6 | import { catchError, map } from 'rxjs/operators' | ||
7 | import { AccountBlock as AccountBlockServer, ResultList, ServerBlock } from '../../../../../shared' | ||
8 | import { Account } from '@app/shared/account/account.model' | ||
9 | import { AccountBlock } from '@app/shared/blocklist/account-block.model' | ||
10 | |||
11 | @Injectable() | ||
12 | export class BlocklistService { | ||
13 | static BASE_USER_BLOCKLIST_URL = environment.apiUrl + '/api/v1/users/me/blocklist' | ||
14 | static BASE_SERVER_BLOCKLIST_URL = environment.apiUrl + '/api/v1/server/blocklist' | ||
15 | |||
16 | constructor ( | ||
17 | private authHttp: HttpClient, | ||
18 | private restExtractor: RestExtractor, | ||
19 | private restService: RestService | ||
20 | ) { } | ||
21 | |||
22 | /*********************** User -> Account blocklist ***********************/ | ||
23 | |||
24 | getUserAccountBlocklist (pagination: RestPagination, sort: SortMeta) { | ||
25 | let params = new HttpParams() | ||
26 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
27 | |||
28 | return this.authHttp.get<ResultList<AccountBlock>>(BlocklistService.BASE_USER_BLOCKLIST_URL + '/accounts', { params }) | ||
29 | .pipe( | ||
30 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
31 | map(res => this.restExtractor.applyToResultListData(res, this.formatAccountBlock.bind(this))), | ||
32 | catchError(err => this.restExtractor.handleError(err)) | ||
33 | ) | ||
34 | } | ||
35 | |||
36 | blockAccountByUser (account: Account) { | ||
37 | const body = { accountName: account.nameWithHost } | ||
38 | |||
39 | return this.authHttp.post(BlocklistService.BASE_USER_BLOCKLIST_URL + '/accounts', body) | ||
40 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
41 | } | ||
42 | |||
43 | unblockAccountByUser (account: Account) { | ||
44 | const path = BlocklistService.BASE_USER_BLOCKLIST_URL + '/accounts/' + account.nameWithHost | ||
45 | |||
46 | return this.authHttp.delete(path) | ||
47 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
48 | } | ||
49 | |||
50 | /*********************** User -> Server blocklist ***********************/ | ||
51 | |||
52 | getUserServerBlocklist (pagination: RestPagination, sort: SortMeta) { | ||
53 | let params = new HttpParams() | ||
54 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
55 | |||
56 | return this.authHttp.get<ResultList<ServerBlock>>(BlocklistService.BASE_USER_BLOCKLIST_URL + '/servers', { params }) | ||
57 | .pipe( | ||
58 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
59 | catchError(err => this.restExtractor.handleError(err)) | ||
60 | ) | ||
61 | } | ||
62 | |||
63 | blockServerByUser (host: string) { | ||
64 | const body = { host } | ||
65 | |||
66 | return this.authHttp.post(BlocklistService.BASE_USER_BLOCKLIST_URL + '/servers', body) | ||
67 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
68 | } | ||
69 | |||
70 | unblockServerByUser (host: string) { | ||
71 | const path = BlocklistService.BASE_USER_BLOCKLIST_URL + '/servers/' + host | ||
72 | |||
73 | return this.authHttp.delete(path) | ||
74 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
75 | } | ||
76 | |||
77 | /*********************** Instance -> Account blocklist ***********************/ | ||
78 | |||
79 | getInstanceAccountBlocklist (pagination: RestPagination, sort: SortMeta) { | ||
80 | let params = new HttpParams() | ||
81 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
82 | |||
83 | return this.authHttp.get<ResultList<AccountBlock>>(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts', { params }) | ||
84 | .pipe( | ||
85 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
86 | map(res => this.restExtractor.applyToResultListData(res, this.formatAccountBlock.bind(this))), | ||
87 | catchError(err => this.restExtractor.handleError(err)) | ||
88 | ) | ||
89 | } | ||
90 | |||
91 | blockAccountByInstance (account: Account) { | ||
92 | const body = { accountName: account.nameWithHost } | ||
93 | |||
94 | return this.authHttp.post(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts', body) | ||
95 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
96 | } | ||
97 | |||
98 | unblockAccountByInstance (account: Account) { | ||
99 | const path = BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts/' + account.nameWithHost | ||
100 | |||
101 | return this.authHttp.delete(path) | ||
102 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
103 | } | ||
104 | |||
105 | /*********************** Instance -> Server blocklist ***********************/ | ||
106 | |||
107 | getInstanceServerBlocklist (pagination: RestPagination, sort: SortMeta) { | ||
108 | let params = new HttpParams() | ||
109 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
110 | |||
111 | return this.authHttp.get<ResultList<ServerBlock>>(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers', { params }) | ||
112 | .pipe( | ||
113 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
114 | catchError(err => this.restExtractor.handleError(err)) | ||
115 | ) | ||
116 | } | ||
117 | |||
118 | blockServerByInstance (host: string) { | ||
119 | const body = { host } | ||
120 | |||
121 | return this.authHttp.post(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers', body) | ||
122 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
123 | } | ||
124 | |||
125 | unblockServerByInstance (host: string) { | ||
126 | const path = BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers/' + host | ||
127 | |||
128 | return this.authHttp.delete(path) | ||
129 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
130 | } | ||
131 | |||
132 | private formatAccountBlock (accountBlock: AccountBlockServer) { | ||
133 | return new AccountBlock(accountBlock) | ||
134 | } | ||
135 | } | ||
diff --git a/client/src/app/shared/blocklist/index.ts b/client/src/app/shared/blocklist/index.ts new file mode 100644 index 000000000..5886ca07e --- /dev/null +++ b/client/src/app/shared/blocklist/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | export * from './blocklist.service' | ||
2 | export * from './account-block.model' | ||