diff --git a/src/actions/detailsActions.js b/src/actions/detailsActions.js index aca65b8..2e481b3 100644 --- a/src/actions/detailsActions.js +++ b/src/actions/detailsActions.js @@ -1,5 +1,6 @@ import { LOAD_DETAILS, CLEAR_DETAILS, SET_DETAILS_LOADING, DISPLAY_WARNING } from './types' import { SONG_DETAILS } from '../constants/views' +import { BEATSAVER_BASE_URL, BSABER_BASE_URL } from '../constants/urls' import AdmZip from 'adm-zip' import { hashAndWriteToMetadata } from './queueActions' @@ -60,7 +61,7 @@ export const loadDetailsFromKey = key => (dispatch, getState) => { }) setView(SONG_DETAILS)(dispatch, getState) if((/^[a-f0-9]+$/).test(key)) { - fetch(`https://beatsaver.com/api/maps/detail/${key}`) + fetch(`${BEATSAVER_BASE_URL}/api/maps/detail/${key}`) .then(res => { if(res.status === 404){ dispatch({ @@ -74,7 +75,7 @@ export const loadDetailsFromKey = key => (dispatch, getState) => { }) .then(res => res.json()) .then(details => { - fetch(`http://beatsaver.com${details.downloadURL}`) + fetch(`${BEATSAVER_BASE_URL}${details.downloadURL}`) .then(res => res.arrayBuffer()) .then(data => { let zip = new AdmZip(new Buffer(data)) @@ -105,7 +106,7 @@ export const loadDetailsFromKey = key => (dispatch, getState) => { } }) }) - fetch(`https://bsaber.com/wp-json/bsaber-api/songs/${key}/ratings`) + fetch(`${BSABER_BASE_URL}/wp-json/bsaber-api/songs/${key}/ratings`) .then(res => res.json()) .then(bsaberData => { dispatch({ @@ -139,4 +140,4 @@ export const loadDetailsFromKey = key => (dispatch, getState) => { } }) } -} \ No newline at end of file +} diff --git a/src/actions/modActions.js b/src/actions/modActions.js index 86411a0..160dee7 100644 --- a/src/actions/modActions.js +++ b/src/actions/modActions.js @@ -1,5 +1,6 @@ import { SET_MOD_LIST, SET_RESOURCE, SET_LOADING, LOAD_MOD_DETAILS, INSTALL_MOD, SET_SCANNING_FOR_MODS, SET_INSTALLED_MODS, DISPLAY_WARNING, UNINSTALL_MOD, CLEAR_MODS, ADD_TO_QUEUE, UPDATE_PROGRESS, ADD_DEPENDENT, SET_MOD_ACTIVE, ADD_PENDING_MOD, SET_PATCHING, SET_MOD_UPDATE_AVAILABLE, CLEAR_MOD_UPDATES, SET_IGNORE_MOD_UPDATE } from './types' import { MODS_VIEW, MOD_DETAILS } from '../constants/views' +import { BEATMODS_BASE_URL } from '../constants/urls' import { BEATMODS, LIBRARY } from '../constants/resources' @@ -27,7 +28,7 @@ export const fetchApprovedMods = () => (dispatch, getState) => { type: SET_LOADING, payload: true }) - fetch(`https://beatmods.com/api/v1/mod?status=approved&gameVersion=${getState().settings.gameVersion}`) + fetch(`${BEATMODS_BASE_URL}/api/v1/mod?status=approved&gameVersion=${getState().settings.gameVersion}`) .then(res => res.json()) .then(beatModsResponse => { dispatch({ @@ -54,7 +55,7 @@ export const fetchRecommendedMods = () => (dispatch, getState) => { let recommendedMods = ['CameraPlus', 'YUR Fit Calorie Tracker', 'SyncSaber', 'Custom Sabers', 'Custom Platforms', 'Custom Avatars', 'BeatSaberTweaks', 'PracticePlugin', 'Counters+'] let mods = [] for(let i = 0; i < recommendedMods.length; i++) { - fetch(`https://beatmods.com/api/v1/mod?name=${encodeURIComponent(recommendedMods[i])}&gameVersion=${getState().settings.gameVersion}`) + fetch(`${BEATMODS_BASE_URL}/api/v1/mod?name=${encodeURIComponent(recommendedMods[i])}&gameVersion=${getState().settings.gameVersion}`) .then(res => res.json()) .then(beatModsResponse => { if(beatModsResponse.length === 0) { recommendedMods.splice(i, 1); return } @@ -99,7 +100,7 @@ export const fetchModCategory = category => (dispatch, getState) => { type: SET_LOADING, payload: true }) - fetch(`https://beatmods.com/api/v1/mod?category=${ category }&status=approved&gameVersion=${getState().settings.gameVersion}`) + fetch(`${BEATMODS_BASE_URL}/api/v1/mod?category=${ category }&status=approved&gameVersion=${getState().settings.gameVersion}`) .then(res => res.json()) .then(beatModsResponse => { dispatch({ @@ -123,7 +124,7 @@ export const fetchLocalMods = () => (dispatch, getState) => { type: SET_LOADING, payload: true }) - fetch(`https://beatmods.com/api/v1/mod?status=approved&status=inactive`) + fetch(`${BEATMODS_BASE_URL}/api/v1/mod?status=approved&status=inactive`) .then(res => res.json()) .then(beatModsResponse => { let installedMods = getState().mods.installedMods @@ -161,7 +162,7 @@ export const fetchActivatedMods = () => (dispatch, getState) => { type: SET_LOADING, payload: true }) - fetch(`https://beatmods.com/api/v1/mod?status=approved&status=inactive`) + fetch(`${BEATMODS_BASE_URL}/api/v1/mod?status=approved&status=inactive`) .then(res => res.json()) .then(beatModsResponse => { let activatedMods = getState().mods.installedMods.filter(mod => mod.active === true) @@ -195,7 +196,7 @@ export const loadModDetails = modId => (dispatch, getState) => { type: SET_LOADING, payload: true }) - fetch(`https://beatmods.com/api/v1/mod`) + fetch(`${BEATMODS_BASE_URL}/api/v1/mod`) .then(res => res.json()) .then(beatModsResponse => { dispatch({ @@ -233,7 +234,7 @@ export const installMod = (modName, version, dependencyOf = '') => (dispatch, ge } return } - fetch(`https://beatmods.com/api/v1/mod?status=approved&status=inactive&name=${ encodeURIComponent(modName) }&gameVersion=${ getState().settings.gameVersion }`) + fetch(`${BEATMODS_BASE_URL}/api/v1/mod?status=approved&status=inactivename=${ encodeURIComponent(modName) }&gameVersion=${ getState().settings.gameVersion }`) .then(res => res.json()) .then(beatModsResponse => { let latestVersion = '0.0.0' @@ -269,7 +270,7 @@ export const installMod = (modName, version, dependencyOf = '') => (dispatch, ge // Install Mod if(mod.downloads.some(version => version.type === 'universal')) { - req = request.get({ url: `https://beatmods.com${mod.downloads.filter(version => version.type === 'universal')[0].url}`, encoding: null }, (err, r, data) => { + req = request.get({ url: `${BEATMODS_BASE_URL}${mod.downloads.filter(version => version.type === 'universal')[0].url}`, encoding: null }, (err, r, data) => { if(err) { dispatch({ type: DISPLAY_WARNING, @@ -319,7 +320,7 @@ export const installMod = (modName, version, dependencyOf = '') => (dispatch, ge } else { let installationType = getState().settings.installationType if(mod.downloads.some(version => version.type === installationType)) { - req = request.get({ url: `https://beatmods.com${mod.downloads.filter(version => version.type === installationType)[0].url}`, encoding: null }, (err, r, data) => { + req = request.get({ url: `${BEATMODS_BASE_URL}${mod.downloads.filter(version => version.type === installationType)[0].url}`, encoding: null }, (err, r, data) => { if(err) { dispatch({ type: DISPLAY_WARNING, @@ -517,7 +518,7 @@ export const checkInstalledMods = () => (dispatch, getState) => { let md5sum = crypto.createHash('md5') md5sum.update(data) let hash = md5sum.digest('hex') - fetch(`https://beatmods.com/api/v1/mod?hash=${hash}`) + fetch(`${BEATMODS_BASE_URL}/api/v1/mod?hash=${hash}`) .then(res => res.json()) .then(beatModsResponse => { if(beatModsResponse.length > 0) { @@ -572,7 +573,7 @@ export const checkInstalledMods = () => (dispatch, getState) => { let md5sum = crypto.createHash('md5') md5sum.update(data) let hash = md5sum.digest('hex') - fetch(`https://beatmods.com/api/v1/mod?hash=${hash}`) + fetch(`${BEATMODS_BASE_URL}/api/v1/mod?hash=${hash}`) .then(res => res.json()) .then(beatModsResponse => { if(beatModsResponse.length > 0) { @@ -671,7 +672,7 @@ export const checkModsForUpdates = () => (dispatch, getState) => { }) let installedMods = getState().mods.installedMods for(let m = 0; m < installedMods.length; m++) { - fetch(`https://beatmods.com/api/v1/mod?status=approved&name=${ installedMods[m].name }&gameVersion=${ getState().settings.gameVersion }`) + fetch(`${BEATMODS_BASE_URL}/api/v1/mod?status=approved&name=${ installedMods[m].name }&gameVersion=${ getState().settings.gameVersion }`) .then(res => res.json()) .then(beatModsResponse => { if(beatModsResponse.length === 0) return diff --git a/src/actions/playlistsActions.js b/src/actions/playlistsActions.js index d24a4b4..368bf24 100644 --- a/src/actions/playlistsActions.js +++ b/src/actions/playlistsActions.js @@ -1,5 +1,6 @@ import { FETCH_LOCAL_PLAYLISTS, LOAD_NEW_PLAYLIST_IMAGE, SET_NEW_PLAYLIST_OPEN, SET_PLAYLIST_PICKER_OPEN, CLEAR_PLAYLIST_DIALOG, LOAD_PLAYLIST_DETAILS, LOAD_PLAYLIST_SONGS, CLEAR_PLAYLIST_DETAILS, SET_PLAYLIST_EDITING, SET_LOADING, DISPLAY_WARNING } from './types' import { PLAYLIST_LIST, PLAYLIST_DETAILS } from '../constants/views' +import { BEATSAVER_BASE_URL } from '../constants/urls' import { defaultPlaylistIcon } from '../b64Assets' import { hashAndWriteToMetadata } from './queueActions' import { setView } from './viewActions' @@ -196,7 +197,7 @@ export const loadPlaylistDetails = playlistFile => (dispatch, getState) => { }) }) } else { - fetch(`https://beatsaver.com/api/maps/by-hash/${playlist.songs[i].hash}`) + fetch(`${BEATSAVER_BASE_URL}/api/maps/by-hash/${playlist.songs[i].hash}`) .then(res => res.json()) .then(song => { song.coverURL = `https://beatsaver.com/${song.coverURL}` @@ -213,10 +214,10 @@ export const loadPlaylistDetails = playlistFile => (dispatch, getState) => { }) } } else { - fetch(`https://beatsaver.com/api/maps/detail/${playlist.songs[i].key}`) + fetch(`${BEATSAVER_BASE_URL}/api/maps/detail/${playlist.songs[i].key}`) .then(res => res.json()) .then(details => { - details.coverURL = `https://beatsaver.com/${details.coverURL}` + details.coverURL = `${BEATSAVER_BASE_URL}/${details.coverURL}` if(state.songs.downloadedSongs.some(song => song.hash === details.hash)) { let file = state.songs.downloadedSongs[state.songs.downloadedSongs.findIndex(song => song.hash === details.hash)].file fs.readFile(file, 'UTF8', (err, data) => { diff --git a/src/actions/queueActions.js b/src/actions/queueActions.js index 09a84fc..9e03d45 100644 --- a/src/actions/queueActions.js +++ b/src/actions/queueActions.js @@ -1,5 +1,6 @@ import { ADD_TO_QUEUE, CLEAR_QUEUE, UPDATE_PROGRESS, SET_DOWNLOADED_SONGS, SET_DOWNLOADING_COUNT, SET_WAIT_LIST, DISPLAY_WARNING, SET_SCANNING_FOR_SONGS, SET_DISCOVERED_FILES, SET_PROCESSED_FILES } from './types' import { SONG_LIST } from '../constants/views' +import { BEATSAVER_BASE_URL } from '../constants/urls' import { isModInstalled, installEssentialMods } from './modActions' import { setView } from './viewActions' @@ -19,7 +20,7 @@ export const downloadSong = (identity) => (dispatch, getState) => { if(!isModInstalled('SongLoader')(dispatch, getState)) installEssentialMods()(dispatch, getState) let hash = identity if(identity) { - fetch(`https://beatsaver.com/api/maps/by-hash/${hash}`) + fetch(`${BEATSAVER_BASE_URL}/api/maps/by-hash/${hash}`) .then(res => res.json()) .then(song => { hash = song.hash @@ -39,7 +40,7 @@ export const downloadSong = (identity) => (dispatch, getState) => { setTimeout(() => { document.getElementById('queue-button').classList.remove('notify') }, 1000) - fetch(`https://beatsaver.com/api/maps/by-hash/${hash}`) + fetch(`${BEATSAVER_BASE_URL}/api/maps/by-hash/${hash}`) .then(res => res.json()) .then(song => { let utc = Date.now() @@ -49,13 +50,13 @@ export const downloadSong = (identity) => (dispatch, getState) => { payload: { utc, hash: song.hash, - image: `https://www.beatsaver.com${ song.coverURL }`, + image: `${BEATSAVER_BASE_URL}${ song.coverURL }`, title: song.metadata.songName, author: song.metadata.songAuthorName } }) let req = request.get({ - url: `http://www.beatsaver.com${song.downloadURL}`, + url: `${BEATSAVER_BASE_URL}${song.downloadURL}`, encoding: null }, (err, r, data) => { try { @@ -237,7 +238,7 @@ export const downloadSong = (identity) => (dispatch, getState) => { setTimeout(() => { document.getElementById('queue-button').classList.remove('notify') }, 1000) - fetch(`https://beatsaver.com/api/maps/by-hash/${hash}`) + fetch(`${BEATSAVER_BASE_URL}/api/maps/by-hash/${hash}`) .then(res => res.json()) .then(song => { let utc = Date.now() @@ -246,13 +247,13 @@ export const downloadSong = (identity) => (dispatch, getState) => { payload: { utc, hash: song.hash, - image: `https://www.beatsaver.com${ song.coverURL }`, + image: `${BEATSAVER_BASE_URL}${ song.coverURL }`, title: song.metadata.songName, author: song.metadata.songAuthorName } }) let req = request.get({ - url: `https://beatsaver.com/${ song.downloadURL }`, + url: `${BEATSAVER_BASE_URL}/${ song.downloadURL }`, encoding: null }, (err, r, data) => { try { diff --git a/src/actions/searchActions.js b/src/actions/searchActions.js index 8bd408c..e375587 100644 --- a/src/actions/searchActions.js +++ b/src/actions/searchActions.js @@ -1,4 +1,5 @@ import { SET_SEARCH_SOURCES, SUBMIT_SEARCH, SET_LOADING } from './types' +import { BEATSAVER_BASE_URL } from '../constants/urls' const { remote } = window.require('electron') const fs = remote.require('fs') @@ -48,7 +49,7 @@ export const submitSearch = keywords => (dispatch, getState) => { localResultsReady = true // BeatSaver Search - fetch('https://beatsaver.com/api/search/text/all?q=' + encodeURIComponent(keywords.replace('/', '\\'))) + fetch(`${BEATSAVER_BASE_URL}/api/search/text/all?q=` + encodeURIComponent(keywords.replace('/', '\\'))) .then(res => res.json()) .then(data => { beatSaverSongs = data.docs @@ -68,7 +69,7 @@ export const submitSearch = keywords => (dispatch, getState) => { // BeatSaver ID Search if(isId) { - fetch('https://beatsaver.com/api/maps/detail/' + keywords) + fetch(`${BEATSAVER_BASE_URL}/api/maps/detail/` + keywords) .then(res => { if(res.status !== 200) { beatSaverIdResultsReady = true; return } return res.json() }) .then(data => { if(!data) { beatSaverIdResultsReady = true; return } diff --git a/src/actions/songListActions.js b/src/actions/songListActions.js index 4b028ab..cb39a52 100644 --- a/src/actions/songListActions.js +++ b/src/actions/songListActions.js @@ -1,6 +1,7 @@ import { FETCH_NEW, FETCH_TOP_DOWNLOADS, FETCH_TOP_FINISHED, FETCH_LOCAL_SONGS, ADD_BSABER_RATING, SET_SCROLLTOP, SET_LOADING, SET_LOADING_MORE, LOAD_MORE, SET_RESOURCE, DISPLAY_WARNING } from './types' import { SONG_LIST } from '../constants/views' import { BEATSAVER, LIBRARY } from '../constants/resources' +import { BEATSAVER_BASE_URL, BSABER_BASE_URL } from '../constants/urls' import { hashAndWriteToMetadata } from './queueActions' import { setView } from './viewActions' @@ -9,9 +10,9 @@ const fs = remote.require('fs') const path = remote.require('path') const resourceUrl = { - 'BEATSAVER_NEW_SONGS': 'https://beatsaver.com/api/maps/latest', - 'BEATSAVER_TOP_DOWNLOADED_SONGS': 'https://beatsaver.com/api/maps/downloads', - 'BEATSAVER_TOP_FINISHED_SONGS': 'https://beatsaver.com/api/maps/plays' + 'BEATSAVER_NEW_SONGS': `${BEATSAVER_BASE_URL}/api/maps/latest`, + 'BEATSAVER_TOP_DOWNLOADED_SONGS': `${BEATSAVER_BASE_URL}/api/maps/downloads`, + 'BEATSAVER_TOP_FINISHED_SONGS': `${BEATSAVER_BASE_URL}/api/maps/plays` } export const fetchNew = () => (dispatch, getState) => { @@ -28,7 +29,7 @@ export const fetchNew = () => (dispatch, getState) => { type: SET_RESOURCE, payload: BEATSAVER.NEW_SONGS }) - fetch('https://beatsaver.com/api/maps/latest') + fetch(`${BEATSAVER_BASE_URL}api/maps/latest`) .then(res => res.json()) .then(data => { console.log(data) @@ -42,7 +43,7 @@ export const fetchNew = () => (dispatch, getState) => { }) console.log(data); for(let i = 0; i < data.docs.length; i++) { - fetch(`https://bsaber.com/wp-json/bsaber-api/songs/${data.docs[i].key}/ratings`) + fetch(`${BSABER_BASE_URL}/wp-json/bsaber-api/songs/${data.docs[i].key}/ratings`) .then(res => res.json()) .then(bsaberData => { dispatch({ @@ -74,7 +75,7 @@ export const fetchTopDownloads = () => (dispatch, getState) => { type: SET_RESOURCE, payload: BEATSAVER.TOP_DOWNLOADED_SONGS }) - fetch('https://beatsaver.com/api/maps/downloads') + fetch(`${BEATSAVER_BASE_URL}/api/maps/downloads`) .then(res => res.json()) .then(data => { dispatch({ @@ -86,7 +87,7 @@ export const fetchTopDownloads = () => (dispatch, getState) => { payload: false }) for(let i = 0; i < data.songs.length; i++) { - fetch(`https://bsaber.com/wp-json/bsaber-api/songs/${data.docs[i].key}/ratings`) + fetch(`${BSABER_BASE_URL}/wp-json/bsaber-api/songs/${data.docs[i].key}/ratings`) .then(res => res.json()) .then(bsaberData => { dispatch({ @@ -118,7 +119,7 @@ export const fetchTopFinished = () => (dispatch, getState) => { type: SET_RESOURCE, payload: BEATSAVER.TOP_FINISHED_SONGS }) - fetch('https://beatsaver.com/api/maps/plays') + fetch(`${BEATSAVER_BASE_URL}/api/maps/plays`) .then(res => res.json()) .then(data => { dispatch({ @@ -130,7 +131,7 @@ export const fetchTopFinished = () => (dispatch, getState) => { payload: false }) for(let i = 0; i < data.docs.length; i++) { - fetch(`https://bsaber.com/wp-json/bsaber-api/songs/${data.docs[i].key}/ratings`) + fetch(`${BSABER_BASE_URL}/wp-json/bsaber-api/songs/${data.docs[i].key}/ratings`) .then(res => res.json()) .then(bsaberData => { dispatch({ @@ -230,7 +231,7 @@ export const loadMore = () => (dispatch, getState) => { }) console.log(data) for(let i = state.songs.songs.length; i < state.songs.songs.length + data.docs.length; i++) { - fetch(`https://bsaber.com/wp-json/bsaber-api/songs/${data.docs[i - state.songs.songs.length].key}/ratings`) + fetch(`${BSABER_BASE_URL}/wp-json/bsaber-api/songs/${data.docs[i - state.songs.songs.length].key}/ratings`) .then(res => res.json()) .then(bsaberData => { dispatch({ diff --git a/src/constants/urls.js b/src/constants/urls.js new file mode 100644 index 0000000..b687c90 --- /dev/null +++ b/src/constants/urls.js @@ -0,0 +1,3 @@ +export const BEATSAVER_BASE_URL = 'https://beatsaver.com' +export const BSABER_BASE_URL = 'https://bsaber.com' +export const BEATMODS_BASE_URL = 'https://beatmods.com' \ No newline at end of file