Add details to UA

This commit is contained in:
xmflsct 2022-11-05 01:11:09 +01:00
parent 0d9992107c
commit 7ef88c735b
4 changed files with 20 additions and 16 deletions

View File

@ -1,6 +1,6 @@
import axios from 'axios'
import Constants from 'expo-constants'
import handleError, { ctx } from './handleError'
import { userAgent } from './helpers'
export type Params = {
method: 'get' | 'post' | 'put' | 'delete'
@ -44,8 +44,8 @@ const apiGeneral = async <T = unknown>({
body && body instanceof FormData
? 'multipart/form-data'
: 'application/json',
'User-Agent': `tooot/${Constants.expoConfig?.version}`,
Accept: '*/*',
...userAgent,
...headers
},
...(body && { data: body })

6
src/api/helpers/index.ts Normal file
View File

@ -0,0 +1,6 @@
import Constants from "expo-constants"
import { Platform } from "react-native"
const userAgent = { 'User-Agent': `tooot/${Constants.expoConfig?.version} ${Platform.OS}/${Platform.Version}` }
export { userAgent }

View File

@ -1,8 +1,8 @@
import { RootState } from '@root/store'
import axios, { AxiosRequestConfig } from 'axios'
import Constants from 'expo-constants'
import li from 'li'
import handleError, { ctx } from './handleError'
import { userAgent } from './helpers'
export type Params = {
method: 'get' | 'post' | 'put' | 'delete' | 'patch'
@ -53,13 +53,13 @@ const apiInstance = async <T = unknown>({
console.log(
ctx.bgGreen.bold(' API instance ') +
' ' +
domain +
' ' +
method +
ctx.green(' -> ') +
`/${url}` +
(params ? ctx.green(' -> ') : ''),
' ' +
domain +
' ' +
method +
ctx.green(' -> ') +
`/${url}` +
(params ? ctx.green(' -> ') : ''),
params ? params : ''
)
@ -74,8 +74,8 @@ const apiInstance = async <T = unknown>({
body && body instanceof FormData
? 'multipart/form-data'
: 'application/json',
'User-Agent': `tooot/${Constants.expoConfig?.version}`,
Accept: '*/*',
...userAgent,
...headers,
...(token && {
Authorization: `Bearer ${token}`

View File

@ -1,8 +1,8 @@
import * as Sentry from '@sentry/react-native'
import { mapEnvironment } from '@utils/checkEnvironment'
import axios from 'axios'
import Constants from 'expo-constants'
import handleError, { ctx } from './handleError'
import { userAgent } from './helpers'
export type Params = {
method: 'get' | 'post' | 'put' | 'delete'
@ -50,13 +50,11 @@ const apiTooot = async <T = unknown>({
body && body instanceof FormData
? 'multipart/form-data'
: 'application/json',
'User-Agent': `tooot/${Constants.expoConfig?.version}`,
Accept: '*/*',
...userAgent,
...headers
},
...(body && { data: body }),
validateStatus: status =>
url.includes('translate') ? status < 500 : status === 200
...(body && { data: body })
})
.then(response => {
return Promise.resolve({