Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function* subtitlesLoadFromTextSaga ({payload: {key, text}}) {
const scope = yield select(state => state.get('scope'));
yield put({type: scope.subtitlesLoadStarted, payload: {key}});
let items;
try {
items = srtParse(text);
} catch (ex) {
yield put({type: scope.subtitlesLoadFailed, payload: {key, error: ex}});
return;
}
yield put({type: scope.subtitlesLoadSucceeded, payload: {key, text, items}});
}
function* subtitlesLoadFromUrlSaga ({payload: {key, url}}) {
const scope = yield select(state => state.get('scope'));
yield put({type: scope.subtitlesLoadStarted, payload: {key}});
try {
const text = yield call(getSubtitles, url);
const items = srtParse(text);
yield put({type: scope.subtitlesLoadSucceeded, payload: {key, text, items}});
} catch (ex) {
yield put({type: scope.subtitlesLoadFailed, payload: {key, error: ex}});
}
}
function* subtitlesLoadFromFileSaga ({payload: {key, file}}) {
const scope = yield select(state => state.get('scope'));
try {
const text = yield call(readFileAsText, file);
const items = srtParse(text);
yield put({type: scope.subtitlesLoadSucceeded, payload: {key, text, items}});
} catch (ex) {
yield put({type: scope.subtitlesLoadFailed, payload: {key, error: ex}});
}
}