Skip to content

Commit e723d98

Browse files
committed
Use typed function call instead of a type cast for querySelector in login/index.ts
1 parent 9d3540f commit e723d98

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

src/apiclient.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ declare module 'jellyfin-apiclient' {
7575
accessToken(): string;
7676
addMediaPath(virtualFolderName: string, mediaPath: string, networkSharePath: string, refreshLibrary?: boolean): Promise<void>;
7777
addVirtualFolder(name: string, type?: string, refreshLibrary?: boolean, libraryOptions?: any): Promise<void>;
78-
ajax(request: any): Promise<any>;
78+
ajax(request: any, includeAuthorization?: boolean): Promise<any>;
7979
appName(): string;
8080
appVersion(): string;
8181
authenticateUserByName(name: string, password: string): Promise<AuthenticationResult>;

src/apps/legacy/controllers/session/login/index.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function authenticateUserByName(page: HTMLElement, apiClient: ApiClient, url: st
3434

3535
onLoginSuccessful(user.Id, result.AccessToken, apiClient, url);
3636
}, function (response) {
37-
(page.querySelector('#txtManualPassword') as HTMLInputElement).value = '';
37+
page.querySelector<HTMLInputElement>('#txtManualPassword')!.value = '';
3838
loading.hide();
3939

4040
const UnauthorizedOrForbidden = [401, 403];
@@ -52,14 +52,12 @@ function authenticateUserByName(page: HTMLElement, apiClient: ApiClient, url: st
5252

5353
function authenticateQuickConnect(apiClient: ApiClient, targetUrl: string) {
5454
const url = apiClient.getUrl('/QuickConnect/Initiate');
55-
// @ts-expect-error: The signature of ajax has just one argument. The `true` can probably be removed with no consequences
5655
apiClient.ajax({ type: 'POST', url }, true).then(res => res.json()).then(function (json) {
5756
if (!json.Secret || !json.Code) {
5857
console.error('Malformed quick connect response', json);
5958
return false;
6059
}
6160

62-
// Should we be awaiting this promise?
6361
void baseAlert({
6462
dialogOptions: {
6563
id: 'quickConnectAlert'
@@ -118,20 +116,19 @@ function authenticateQuickConnect(apiClient: ApiClient, targetUrl: string) {
118116

119117
function onLoginSuccessful(id: string | null | undefined, accessToken: string | null | undefined, apiClient: ApiClient, url: string) {
120118
Dashboard.onServerChanged(id, accessToken, apiClient);
121-
// Should we be handling the promise from navigate?
122119
void Dashboard.navigate(url || 'home');
123120
}
124121

125122
function showManualForm(context: HTMLElement, showCancel: boolean, focusPassword?: boolean) {
126-
(context.querySelector('.chkRememberLogin') as HTMLInputElement).checked = appSettings.enableAutoLogin();
123+
context.querySelector<HTMLInputElement>('.chkRememberLogin')!.checked = appSettings.enableAutoLogin();
127124
context.querySelector('.manualLoginForm')!.classList.remove('hide');
128125
context.querySelector('.visualLoginForm')!.classList.add('hide');
129126
context.querySelector('.btnManual')!.classList.add('hide');
130127

131128
if (focusPassword) {
132-
(context.querySelector('#txtManualPassword') as HTMLInputElement).focus();
129+
context.querySelector<HTMLInputElement>('#txtManualPassword')!.focus();
133130
} else {
134-
(context.querySelector('#txtManualName') as HTMLElement).focus();
131+
context.querySelector<HTMLElement>('#txtManualName')!.focus();
135132
}
136133

137134
if (showCancel) {
@@ -198,7 +195,7 @@ export default function (view: HTMLElement, params: Record<string, string>) {
198195
return ServerConnections.getOrCreateApiClient(serverId);
199196
}
200197

201-
// @ts-expect-error: We're returning a type definition instead of an instance. This path is probably never hit since it would break if it were.
198+
// @ts-expect-error: This works because it returns window.ApiClient, but we shouldn't use it in the new code.
202199
return ApiClient;
203200
}
204201

@@ -219,7 +216,6 @@ export default function (view: HTMLElement, params: Record<string, string>) {
219216
view.querySelector('.manualLoginForm')!.classList.add('hide');
220217
view.querySelector('.btnManual')!.classList.remove('hide');
221218

222-
// Should we be handling this promise?
223219
void import('components/autoFocuser').then(({ default: autoFocuser }) => {
224220
autoFocuser.autoFocus(view);
225221
});
@@ -236,20 +232,20 @@ export default function (view: HTMLElement, params: Record<string, string>) {
236232
const haspw = cardContent.getAttribute('data-haspw');
237233

238234
if (id === 'manual') {
239-
(context.querySelector('#txtManualName') as HTMLInputElement).value = '';
235+
context.querySelector<HTMLInputElement>('#txtManualName')!.value = '';
240236
showManualForm(context, true);
241237
} else if (haspw == 'false') {
242238
authenticateUserByName(context, getApiClient(), getTargetUrl(), name, '');
243239
} else {
244-
(context.querySelector('#txtManualName') as HTMLInputElement).value = name;
245-
(context.querySelector('#txtManualPassword') as HTMLInputElement).value = '';
240+
context.querySelector<HTMLInputElement>('#txtManualName')!.value = name;
241+
context.querySelector<HTMLInputElement>('#txtManualPassword')!.value = '';
246242
showManualForm(context, true, true);
247243
}
248244
}
249245
});
250246
view.querySelector('.manualLoginForm')!.addEventListener('submit', function (e) {
251-
appSettings.enableAutoLogin((view.querySelector('.chkRememberLogin') as HTMLInputElement).checked);
252-
authenticateUserByName(view, getApiClient(), getTargetUrl(), (view.querySelector('#txtManualName') as HTMLInputElement).value, (view.querySelector('#txtManualPassword') as HTMLInputElement).value);
247+
appSettings.enableAutoLogin(view.querySelector<HTMLInputElement>('.chkRememberLogin')!.checked);
248+
authenticateUserByName(view, getApiClient(), getTargetUrl(), view.querySelector<HTMLInputElement>('#txtManualName')!.value, view.querySelector<HTMLInputElement>('#txtManualPassword')!.value);
253249
e.preventDefault();
254250
return false;
255251
});
@@ -262,7 +258,7 @@ export default function (view: HTMLElement, params: Record<string, string>) {
262258
return false;
263259
});
264260
view.querySelector('.btnManual')!.addEventListener('click', function () {
265-
(view.querySelector('#txtManualName') as HTMLInputElement).value = '';
261+
view.querySelector<HTMLInputElement>('#txtManualName')!.value = '';
266262
showManualForm(view, true);
267263
});
268264
view.querySelector('.btnSelectServer')!.addEventListener('click', function () {
@@ -289,13 +285,12 @@ export default function (view: HTMLElement, params: Record<string, string>) {
289285
console.debug('Failed to get QuickConnect status');
290286
});
291287

292-
// Should we be awaiting this promise?
293288
void apiClient.getPublicUsers().then(function (users) {
294289
if (users.length) {
295290
showVisualForm();
296291
loadUserList(view, apiClient, users);
297292
} else {
298-
(view.querySelector('#txtManualName') as HTMLInputElement).value = '';
293+
view.querySelector<HTMLInputElement>('#txtManualName')!.value = '';
299294
showManualForm(view, false, false);
300295
}
301296
}).catch().then(function () {

0 commit comments

Comments
 (0)