forked from LukeChannings/moviematch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moviematch.ts
283 lines (237 loc) · 6.16 KB
/
moviematch.ts
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/**
* Shared API interfaces between the frontend and backend
*/
export interface BasicAuth {
userName: string;
password: string;
}
export interface Config {
hostname: string;
port: number;
logLevel: "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL";
rootPath: string;
servers: Array<{
type?: "plex";
url: string;
token: string;
libraryTitleFilter?: string[];
libraryTypeFilter: LibraryType[];
linkType?: "app" | "webLocal" | "webExternal";
}>;
requirePlexTvLogin: boolean;
basicAuth?: BasicAuth;
tlsConfig?: {
certFile: string;
keyFile: string;
};
}
export type Message = ServerMessage | ClientMessage;
// Messages intended for the Server
export type ServerMessage =
| { type: "login"; payload: Login }
| { type: "logout" }
| { type: "createRoom"; payload: CreateRoomRequest }
| { type: "joinRoom"; payload: JoinRoomRequest }
| { type: "leaveRoom" }
| { type: "rate"; payload: Rate }
| { type: "setLocale"; payload: Locale }
| { type: "setup"; payload: Config }
| { type: "requestFilters" }
| { type: "requestFilterValues"; payload: FilterValueRequest };
// Messages intended for the UI
export type ClientMessage =
| { type: "loginError"; payload: LoginError }
| { type: "loginSuccess"; payload: User }
| { type: "logoutError"; payload: LogoutError }
| { type: "logoutSuccess" }
| { type: "createRoomError"; payload: CreateRoomError }
| { type: "createRoomSuccess"; payload: JoinRoomSuccess }
| { type: "joinRoomError"; payload: JoinRoomError }
| { type: "joinRoomSuccess"; payload: JoinRoomSuccess }
| { type: "leaveRoomSuccess" }
| { type: "leaveRoomError"; payload: LeaveRoomError }
| { type: "match"; payload: Match }
| { type: "media"; payload: Media[] }
| { type: "config"; payload: AppConfig }
| { type: "translations"; payload: Translations }
| { type: "setupSuccess"; payload: SetupSuccess }
| { type: "setupError"; payload: SetupError }
| { type: "requestFiltersSuccess"; payload: Filters }
| { type: "requestFiltersError" }
| {
type: "requestFilterValuesSuccess";
payload: { request: FilterValueRequest; values: FilterValue[] };
}
| { type: "requestFilterValuesError" }
| { type: "userJoinedRoom"; payload: UserProgress }
| { type: "userLeftRoom"; payload: User }
| { type: "userProgress"; payload: UserProgress };
// Translations
export type TranslationKey =
| "LANG"
| "LOGIN_NAME"
| "LOGIN_ROOM_NAME"
| "LOGIN_SIGN_IN"
| "LOGIN_SIGN_IN_PLEX"
| "CREATE_ROOM"
| "RATE_SECTION_LOADING"
| "RATE_SECTION_EXHAUSTED_CARDS"
| "MATCHES_SECTION_TITLE"
| "MATCHES_SECTION_NO_MATCHES"
| "MATCHES_SECTION_CARD_LIKERS"
| "LIST_CONJUNCTION"
| "BACK"
| "SHARE_ROOM_TITLE"
| "JOIN_ROOM"
| "FIELD_REQUIRED_ERROR"
| "COPY_LINK_SUCCESS"
| "COPY_LINK_FAILURE"
| "LOGOUT";
// Configure message
export interface AppConfig {
requiresConfiguration: boolean;
requirePlexLogin: boolean;
initialConfiguration?: Partial<Config>;
}
// Translations message
export interface Locale {
language: string;
}
export type Translations = Record<TranslationKey, string>;
// Login (when login is required to create a new room)
export type Login =
| { userName: string }
| { plexClientId: string; plexToken: string };
export interface LoginError {
name: "MalformedMessage" | "PlexLoginRequired";
message: string;
}
export interface LogoutError {
name: "NotLoggedIn";
message: string;
}
export type Permissions = "CanCreateRoom";
export interface User {
userName: string;
permissions?: Permissions[]; // Not available in user*Room messages
avatarImage?: string;
}
// Create Room
export type RoomOption = "EndOnFirstMatch";
export interface Filter {
key: string;
operator: string;
value: string[];
}
export type RoomSort = "random" | "rating";
export interface CreateRoomRequest {
roomName: string;
password?: string;
options?: RoomOption[];
filters?: Filter[];
sort?: RoomSort;
}
export interface CreateRoomError {
name:
| "RoomExistsError"
| "UnauthorizedError"
| "NotLoggedInError"
| "NoMedia";
message: string;
}
// Contains metadata for Create Room filters
export interface CreateRoomFilterMetadata {
availableFilters: Array<{ key: string; value: string; operator: string }>;
}
// Join
export interface JoinRoomRequest {
roomName: string;
password?: string;
}
export interface JoinRoomError {
name:
| "UserAlreadyJoinedError"
| "AccessDeniedError"
| "RoomNotFoundError"
| "NotLoggedInError"
| "UnknownError";
message: string;
}
export interface JoinRoomSuccess {
previousMatches: Match[];
media: Media[];
users: Array<{ user: User; progress: number }>;
}
// Leave
export interface LeaveRoomError {
errorType: "NOT_JOINED"; // Can't leave a room you're not in
}
// In-Room
export interface Media {
id: string;
type: LibraryType;
title: string;
description: string;
tagline?: string;
year?: number;
posterUrl?: string;
linkUrl: string;
genres: string[];
duration: number;
rating: number;
contentRating?: string;
}
export interface Match {
matchedAt: number;
media: Media;
users: string[];
}
export interface Rate {
rating: "like" | "dislike";
mediaId: string;
}
export interface SetupSuccess {
hostname: string;
port: number;
}
export interface SetupError {
message: string;
type: string;
}
// Filters
export const LibaryTypes = ["show", "movie", "music", "photo"] as const;
export type LibraryType = typeof LibaryTypes[number];
export interface Library {
title: string;
key: string;
type: LibraryType;
}
export interface Filters {
filters: Array<{
title: string;
key: string;
type: string;
libraryTypes: LibraryType[];
}>;
// e.g. { integer: [{ key: '=', title: 'is' }, { key: '!=', title: 'is not' }] }
// Note, the meanings of certain keys (e.g. '=') can be different depending on the type
filterTypes: Record<
string,
Array<{
key: string;
title: string;
}>
>;
}
export interface FilterValue {
title: string;
value: string;
}
export interface FilterValueRequest {
key: string;
}
export interface UserProgress {
user: User;
// A percentage of the way through the room the user is
progress: number;
}