Skip to content

Commit

Permalink
chore: remove unnecessary as casts
Browse files Browse the repository at this point in the history
  • Loading branch information
aweebs authored and ferferga committed Feb 17, 2023
1 parent 4b17b55 commit f876c1c
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 42 deletions.
3 changes: 1 addition & 2 deletions frontend/src/components/Buttons/SubtitleSelectionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export default defineComponent({
},
computed: {
tracks(): PlaybackTrack[] {
const subs = this.playbackManager
.currentItemParsedSubtitleTracks as PlaybackTrack[];
const subs = this.playbackManager.currentItemParsedSubtitleTracks ?? [];
return [
{
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/Item/ItemMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,12 @@ function getLibraryOptions(): MenuOption[] {
action: async (): Promise<void> => {
if (remote.sdk.api) {
try {
if (!menuProps.item.Id) {
throw new Error('Expected item to have id');
}
await getItemRefreshApi(remote.sdk.api).refreshItem({
itemId: menuProps.item.Id as string,
itemId: menuProps.item.Id,
replaceAllImages: false,
replaceAllMetadata: false
});
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/Layout/Carousel/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ function onSlideChange(): void {
swiperInstance.value?.updateSlides();
}
// Propagate events to children
emit(
'on-slide-change',
currentIndex.value,
swiperInstance.value as SwiperType
);
if (swiperInstance.value) {
// Propagate events to children
emit('on-slide-change', currentIndex.value, swiperInstance.value);
}
}
/**
* Handle touch events
Expand All @@ -111,7 +109,9 @@ function onTouch(): void {
isPaused.value = !isPaused.value;
// Propagate events to children
emit('on-touch', isPaused.value, swiperInstance.value as SwiperType);
if (swiperInstance.value) {
emit('on-touch', isPaused.value, swiperInstance.value);
}
}
/**
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/Playback/DraggableQueue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ const queue = computed({
},
set(newValue: BaseItemDto[]) {
playbackManager.setNewQueue(
newValue.map((item) => {
return item.Id as string;
})
newValue.map((item) => item.Id).filter((id): id is string => !!id)
);
}
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ import { version as clientVersion } from '@/../package.json';
const { t } = useI18n();
const route = useRoute();
const remote = useRemote();
let systemInfo = {} as SystemInfo;
route.meta.title = t('settings.settings');
let systemInfo: SystemInfo = {};
if (remote.auth.currentUser?.Policy?.IsAdministrator) {
systemInfo = (await remote.sdk.newUserApi(getSystemApi).getSystemInfo()).data;
}
Expand Down
32 changes: 21 additions & 11 deletions frontend/src/plugins/remote/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ class RemotePluginAuth {
const { data } = await getSystemApi(api).getPublicSystemInfo();

delete data.LocalAddress;
serv = data as ServerInfo;
serv.PublicAddress = serverUrl;
serv.isDefault = isDefault;
serv = {
...data,
PublicAddress: serverUrl,
isDefault: isDefault
};
} catch (error) {
useSnackbar(i18n.t('login.serverNotFound'), 'error');
throw new Error(error as string);
throw error;
}

const semverMajor = Number.parseInt(serv.Version?.split('.')[0] as string);
const semverMinor = Number.parseInt(serv.Version?.split('.')[1] as string);
const semverMajor = Number(serv.Version?.split('.')[0]);
const semverMinor = Number(serv.Version?.split('.')[1]);
const isServerVersionSupported =
semverMajor > 10 || (semverMajor === 10 && semverMinor >= 7);

Expand All @@ -121,11 +123,15 @@ class RemotePluginAuth {
state.value.servers.push(serv);
}

state.value.currentServerIndex = state.value.servers.indexOf(
state.value.servers.find(
(serv) => serv.PublicAddress === serverUrl
) as ServerInfo
const serverInfo = state.value.servers.find(
(serv) => serv.PublicAddress === serverUrl
);
if (!serverInfo) {
throw new Error('expected to find server by url');
}

state.value.currentServerIndex =
state.value.servers.indexOf(serverInfo);
}
} else {
useSnackbar(i18n.t('login.serverVersionTooLow'), 'error');
Expand Down Expand Up @@ -219,7 +225,11 @@ class RemotePluginAuth {
state.value.users.splice(state.value.users.indexOf(storeUser), 1);
}

delete state.value.accessTokens[user.Id as string];
if (!user.Id) {
throw new Error('expected user to have id');
}

delete state.value.accessTokens[user.Id];
}
}
/**
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/store/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ItemsStore {

state.value.collectionById[parent.Id] = childIds;

return this.getChildrenOfParent(parent.Id) as BaseItemDto[];
return this.getChildrenOfParent(parent.Id) ?? [];
};

/**
Expand Down Expand Up @@ -196,7 +196,11 @@ class ItemsStore {
if (childItems.Items) {
const parent = this.getItemById(parentId);

return this.addCollection(parent as BaseItemDto, childItems.Items);
if (!parent) {
throw new Error('expected item to be found');
}

return this.addCollection(parent, childItems.Items);
}
};

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/utils/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,11 @@ export function getImageInfo(
itemId = item.Id;
}

const url_string = remote.sdk.api?.getItemImageUrl(itemId as string, imgType);
if (!itemId) {
throw new Error('expected itemId to have been set');
}

const url_string = remote.sdk.api?.getItemImageUrl(itemId, imgType);

if (imgTag && imgType && itemId && url_string) {
url = new URL(url_string);
Expand Down
24 changes: 10 additions & 14 deletions frontend/src/utils/supported-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,27 @@ function supportsFullscreen(): boolean {
}

const element = document.documentElement;
const video = document.createElement('video');

return !!(
element.requestFullscreen ||
// @ts-expect-error -- Non-standard property
element.mozRequestFullScreen ||
// @ts-expect-error -- Non-standard property
element.webkitRequestFullscreen ||
// @ts-expect-error -- Non-standard property
element.msRequestFullscreen ||
// @ts-expect-error -- Non-standard property
document.createElement('video').webkitEnterFullscreen
// check properties that are not recorded on the element type
('mozRequestFullScreen' in element && element.mozRequestFullScreen) ||
('webkitRequestFullscreen' in element && element.webkitRequestFullscreen) ||
('msRequestFullscreen' in element && element.msRequestFullscreen) ||
('webkitEnterFullscreen' in video && video.webkitEnterFullscreen)
);
}

const video = document.createElement('video');

if (
// Check non-standard Safari PiP support
// @ts-expect-error - Non-standard functions doesn't have typings
(typeof video.webkitSupportsPresentationMode === 'function' &&
// @ts-expect-error - Non-standard functions doesn't have typings
('webkitSupportsPresentationMode' in video &&
typeof video.webkitSupportsPresentationMode === 'function' &&
video.webkitSupportsPresentationMode('picture-in-picture') &&
// @ts-expect-error - Non-standard functions doesn't have typings
typeof video.webkitSetPresentationMode === 'function') ||
// Check standard PiP support
'webkitSetPresentationMode' in video &&
typeof video.webkitSetPresentationMode) ||
document.pictureInPictureEnabled
) {
supportedFeatures.pictureInPicture = true;
Expand Down

0 comments on commit f876c1c

Please sign in to comment.