forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.ts
More file actions
43 lines (35 loc) · 1.29 KB
/
Copy pathclient.ts
File metadata and controls
43 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { CreateShareRequest, CreateShareResponse, ListSharesResponse } from './types'
import { ApiError, MdApiClient } from '@/services/account/client'
import { ACCOUNT_API_URL, CAPABILITY_API_URL } from '@/services/account/config'
import { isShareFeatureEnabled } from '@/services/product/features'
export function isShareConfigured(): boolean {
return Boolean(CAPABILITY_API_URL)
}
/** 是否在 UI 中展示分享入口 */
export function isShareUiEnabled(): boolean {
return isShareFeatureEnabled() && isShareConfigured()
}
export function getSharePageUrl(id: string): string {
return `${CAPABILITY_API_URL}/s/${id}`
}
export class ShareClient extends MdApiClient {
constructor(getToken: () => string | null) {
super(
() => CAPABILITY_API_URL === ACCOUNT_API_URL ? getToken() : null,
{
baseUrl: CAPABILITY_API_URL,
authorization: `bearer`,
},
)
}
list(): Promise<ListSharesResponse> {
return this.request<ListSharesResponse>(`GET`, `/share`)
}
create(payload: CreateShareRequest): Promise<CreateShareResponse> {
return this.request<CreateShareResponse>(`POST`, `/share`, payload)
}
revoke(id: string): Promise<{ ok: true }> {
return this.request<{ ok: true }>(`DELETE`, `/share/${id}`)
}
}
export { ApiError as ShareApiError }