a
File size: 2,604 Bytes
2c8ae4e
 
7e7d412
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6db0b76
5283e2c
7e7d412
 
 
 
 
70cc48f
 
7e7d412
 
 
 
 
 
 
c165e10
 
 
 
 
 
 
 
7e7d412
 
2c8ae4e
 
 
7e7d412
 
2c8ae4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c38a8d
 
 
 
 
 
2c8ae4e
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const BASE_URL = import.meta.env.VITE_API_URL || ''

/**
 * Global default render settings the free API key serves with, returned by
 * `GET /api/free-key/settings`. Enum-coded fields use the same short codes as
 * the image query params (e.g. badge style `h`/`v`/`d`, image source `t`/`f`).
 */
export interface FreeKeyDefaults {
  image_source: string
  lang: string
  textless: boolean
  ratings_limit: number
  ratings_order: string
  ratings_exclude: string
  poster_position: string
  logo_ratings_limit: number
  backdrop_ratings_limit: number
  poster_badge_style: string
  logo_badge_style: string
  backdrop_badge_style: string
  poster_label_style: string
  logo_label_style: string
  backdrop_label_style: string
  poster_badge_direction: string
  poster_badge_split: boolean
  poster_fit: string
  poster_badge_size: string
  logo_badge_size: string
  backdrop_badge_size: string
  backdrop_position: string
  backdrop_badge_direction: string
  backdrop_edge_inset_x: number
  backdrop_edge_inset_y: number
  episode_ratings_limit: number
  episode_badge_style: string
  episode_label_style: string
  episode_badge_size: string
  episode_position: string
  episode_badge_direction: string
  episode_blur: boolean
  poster_badge_shape: string
  logo_badge_shape: string
  backdrop_badge_shape: string
  episode_badge_shape: string
  poster_badge_background: string
  logo_badge_background: string
  backdrop_badge_background: string
  episode_badge_background: string
}

export const authApi = {
  status: (): Promise<Response> =>
    fetch(`${BASE_URL}/api/auth/status`),
  freeKeySettings: (): Promise<Response> =>
    fetch(`${BASE_URL}/api/free-key/settings`),
  setup: (username: string, password: string): Promise<Response> =>
    fetch(`${BASE_URL}/api/auth/setup`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ username, password }),
      credentials: 'include',
    }),
  login: (username: string, password: string): Promise<Response> =>
    fetch(`${BASE_URL}/api/auth/login`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ username, password }),
      credentials: 'include',
    }),
  refresh: (): Promise<Response> =>
    fetch(`${BASE_URL}/api/auth/refresh`, {
      method: 'POST',
      credentials: 'include',
    }),
  keyLogin: (apiKey: string): Promise<Response> =>
    fetch(`${BASE_URL}/api/auth/key-login`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ api_key: apiKey }),
    }),
}