use consistent user agent for requests

This commit is contained in:
austinried 2021-09-08 15:49:01 +09:00
parent 51f79ac8ad
commit eb578fa5e6
3 changed files with 9 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import { Song } from '@app/models/music' import { Song } from '@app/models/music'
import userAgent from '@app/util/userAgent'
import { GetState, SetState } from 'zustand' import { GetState, SetState } from 'zustand'
import { Store } from './store' import { Store } from './store'
import { TrackExt } from './trackplayer' import { TrackExt } from './trackplayer'
@ -29,6 +30,7 @@ export const createTrackPlayerMapSlice = (set: SetState<Store>, get: GetState<St
artist: song.artist || 'Unknown Artist', artist: song.artist || 'Unknown Artist',
album: song.album || 'Unknown Album', album: song.album || 'Unknown Album',
url: song.streamUri, url: song.streamUri,
userAgent,
artwork, artwork,
coverArt: song.coverArt, coverArt: song.coverArt,
duration: song.duration, duration: song.duration,

View File

@ -34,6 +34,7 @@ import {
SubsonicResponse, SubsonicResponse,
} from '@app/subsonic/responses' } from '@app/subsonic/responses'
import toast from '@app/util/toast' import toast from '@app/util/toast'
import userAgent from '@app/util/userAgent'
import { DOMParser } from 'xmldom' import { DOMParser } from 'xmldom'
export class SubsonicApiError extends Error { export class SubsonicApiError extends Error {
@ -85,7 +86,9 @@ export class SubsonicApiClient {
let text: string let text: string
try { try {
const response = await fetch(this.buildUrl(method, params)) const response = await fetch(this.buildUrl(method, params), {
headers: { 'User-Agent': userAgent },
})
text = await response.text() text = await response.text()
} catch (err) { } catch (err) {
toast(`Network error: ${this.address}`) toast(`Network error: ${this.address}`)

3
app/util/userAgent.ts Normal file
View File

@ -0,0 +1,3 @@
import { Platform } from 'react-native'
export default `subtracks/${Platform.OS}`