Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbuiter committed Mar 7, 2021
1 parent a04f7fa commit 4d686bf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const GenerateMagnetModal: FC = () => {
}
}, []);

if (UIStore.activeModal?.id !== 'chromecast') {
return null;
}

if (!initialized)
return (
<Modal
Expand All @@ -44,16 +48,15 @@ const GenerateMagnetModal: FC = () => {
actions={[
{
clickHandler: null,
content: intl.formatMessage({
id: 'button.close',
}),
content: i18n._('button.close'),
triggerDismiss: true,
type: 'tertiary',
},
]}
/>
);

const hash = UIStore.activeModal?.hash;
const mediaFiles = contents.filter((file) => isFileChromecastable(file.filename));
const selectedFileName = (contents[selectedFileIndex]?.filename || '').replace(/\.\w+$/, '');
const subtitleSources: Subtitles[] = [
Expand All @@ -64,9 +67,8 @@ const GenerateMagnetModal: FC = () => {
];

const beginCasting = async () => {
if (!UIStore.activeModal?.hash || !connected) return;
if (!connected) return;

const hash = UIStore.activeModal?.hash;
const {filename} = contents[selectedFileIndex];
const contentType = getChromecastContentType(filename);
if (!contentType) return;
Expand All @@ -86,14 +88,14 @@ const GenerateMagnetModal: FC = () => {
mediaInfo.textTrackStyle = new chrome.cast.media.TextTrackStyle();
mediaInfo.textTrackStyle.backgroundColor = '#00000000';
mediaInfo.textTrackStyle.edgeColor = '#000000FF';
mediaInfo.textTrackStyle.edgeType = 'DROP_SHADOW';
mediaInfo.textTrackStyle.edgeType = chrome.cast.media.TextTrackEdgeType.DROP_SHADOW;
mediaInfo.textTrackStyle.fontFamily = 'SANS_SERIF';
mediaInfo.textTrackStyle.fontScale = 1.0;
mediaInfo.textTrackStyle.foregroundColor = '#FFFFFF';

const track = new chrome.cast.media.Track(0, 'TEXT');
const track = new chrome.cast.media.Track(0, chrome.cast.media.TrackType.TEXT);
track.name = 'Text';
track.subtype = 'CAPTIONS';
track.subtype = chrome.cast.media.TextTrackType.CAPTIONS;
track.trackContentId = await TorrentActions.getTorrentContentsSubtitlePermalink(hash, selectedSubtitles);
track.trackContentType = 'text/vtt';

Expand All @@ -111,23 +113,23 @@ const GenerateMagnetModal: FC = () => {
const media = castSession.getMediaSession();
if (!media) return;

media.stop(new chrome.cast.media.StopRequest());
media.stop(
new chrome.cast.media.StopRequest(),
() => {},
() => {},
);
};

return (
<Modal
heading={intl.formatMessage({
id: 'chromecast.modal.title',
})}
heading={i18n._('chromecast.modal.title')}
content={
<div className="modal__content inverse">
<Form>
<FormRow>
<Select
id="fileIndex"
label={intl.formatMessage({
id: 'chromecast.modal.file',
})}
label={i18n._('chromecast.modal.file')}
onSelect={(fileIndex) => {
setSelectedFileIndex(Number(fileIndex));
setSelectedSubtitles('none');
Expand All @@ -142,20 +144,14 @@ const GenerateMagnetModal: FC = () => {
<FormRow>
<Select
id="subtitleSource"
label={intl.formatMessage({
id: 'chromecast.modal.subtitle',
})}
label={i18n._('chromecast.modal.subtitle')}
onSelect={(id) => {
if (id === 'none') setSelectedSubtitles('none');
else setSelectedSubtitles(Number(id));
}}>
{subtitleSources.map((source) => (
<SelectItem key={source} id={`${source}`}>
{source === 'none'
? intl.formatMessage({
id: 'chromecast.modal.subtitle.none',
})
: contents[source].filename}
{source === 'none' ? i18n._('chromecast.modal.subtitle.none') : contents[source].filename}
</SelectItem>
))}
</Select>
Expand Down
2 changes: 2 additions & 0 deletions client/src/javascript/util/chromecastUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {chromecastableExtensions, subtitleExtensions} from '../../../../shared/c

export function isFileChromecastable(filename: string): boolean {
const fileExtension = filename.split('.').pop();
if (!fileExtension) return false;
return fileExtension in chromecastableExtensions;
}

Expand All @@ -12,5 +13,6 @@ export function getChromecastContentType(filename: string): string | undefined {

export function isFileSubtitles(filename: string): boolean {
const fileExtension = filename.split('.').pop();
if (!fileExtension) return false;
return subtitleExtensions.includes(fileExtension);
}
3 changes: 2 additions & 1 deletion server/routes/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {FloodSettings} from '@shared/types/FloodSettings';
import type {HistorySnapshot} from '@shared/constants/historySnapshotTypes';
import type {NotificationFetchOptions} from '@shared/types/Notification';
import type {SetFloodSettingsOptions} from '@shared/types/api/index';
import type {RequestHandler} from 'express';

import {accessDeniedError, isAllowedPath, sanitizePath} from '../../util/fileUtil';
import appendUserServices from '../../middleware/appendUserServices';
Expand All @@ -27,7 +28,7 @@ router.use('/auth', authRoutes);

// Special routes that may bypass authentication when conditions matched

const authenticateContentRequest = async (req, _res, next) => {
const authenticateContentRequest: RequestHandler = async (req, _res, next) => {
const {token} = req.query;

if (typeof token === 'string' && token !== '') {
Expand Down
6 changes: 3 additions & 3 deletions server/routes/api/torrents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,16 +927,16 @@ router.get(
return;
}

let index = stringIndex ? Number(stringIndex) : contents[0].index;
const index = stringIndex ? Number(stringIndex) : contents[0].index;

let subtitleSourceContent = contents.find((content) => index == content.index);
const subtitleSourceContent = contents.find((content) => index == content.index);

if (!subtitleSourceContent) {
res.status(404).json({error: 'Torrent contents not found'});
return;
}

let subtitleSourcePath = sanitizePath(path.join(selectedTorrent.directory, subtitleSourceContent.path));
const subtitleSourcePath = sanitizePath(path.join(selectedTorrent.directory, subtitleSourceContent.path));

if (!isAllowedPath(subtitleSourcePath)) {
const {code, message} = accessDeniedError();
Expand Down
2 changes: 1 addition & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"paths": {
"@shared/*": ["shared/*"]
},
"outDir": "../dist"
"outDir": "../dist",
},
"include": ["./**/*.ts", "../shared/**/*.ts", "../config.js", "../config.ts"]
}

0 comments on commit 4d686bf

Please sign in to comment.