mirror of
https://github.com/tooot-app/app
synced 2025-02-05 12:58:21 +01:00
Add details to UA
This commit is contained in:
parent
0d9992107c
commit
7ef88c735b
@ -1,6 +1,6 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import Constants from 'expo-constants'
|
|
||||||
import handleError, { ctx } from './handleError'
|
import handleError, { ctx } from './handleError'
|
||||||
|
import { userAgent } from './helpers'
|
||||||
|
|
||||||
export type Params = {
|
export type Params = {
|
||||||
method: 'get' | 'post' | 'put' | 'delete'
|
method: 'get' | 'post' | 'put' | 'delete'
|
||||||
@ -44,8 +44,8 @@ const apiGeneral = async <T = unknown>({
|
|||||||
body && body instanceof FormData
|
body && body instanceof FormData
|
||||||
? 'multipart/form-data'
|
? 'multipart/form-data'
|
||||||
: 'application/json',
|
: 'application/json',
|
||||||
'User-Agent': `tooot/${Constants.expoConfig?.version}`,
|
|
||||||
Accept: '*/*',
|
Accept: '*/*',
|
||||||
|
...userAgent,
|
||||||
...headers
|
...headers
|
||||||
},
|
},
|
||||||
...(body && { data: body })
|
...(body && { data: body })
|
||||||
|
6
src/api/helpers/index.ts
Normal file
6
src/api/helpers/index.ts
Normal 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 }
|
@ -1,8 +1,8 @@
|
|||||||
import { RootState } from '@root/store'
|
import { RootState } from '@root/store'
|
||||||
import axios, { AxiosRequestConfig } from 'axios'
|
import axios, { AxiosRequestConfig } from 'axios'
|
||||||
import Constants from 'expo-constants'
|
|
||||||
import li from 'li'
|
import li from 'li'
|
||||||
import handleError, { ctx } from './handleError'
|
import handleError, { ctx } from './handleError'
|
||||||
|
import { userAgent } from './helpers'
|
||||||
|
|
||||||
export type Params = {
|
export type Params = {
|
||||||
method: 'get' | 'post' | 'put' | 'delete' | 'patch'
|
method: 'get' | 'post' | 'put' | 'delete' | 'patch'
|
||||||
@ -53,13 +53,13 @@ const apiInstance = async <T = unknown>({
|
|||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
ctx.bgGreen.bold(' API instance ') +
|
ctx.bgGreen.bold(' API instance ') +
|
||||||
' ' +
|
' ' +
|
||||||
domain +
|
domain +
|
||||||
' ' +
|
' ' +
|
||||||
method +
|
method +
|
||||||
ctx.green(' -> ') +
|
ctx.green(' -> ') +
|
||||||
`/${url}` +
|
`/${url}` +
|
||||||
(params ? ctx.green(' -> ') : ''),
|
(params ? ctx.green(' -> ') : ''),
|
||||||
params ? params : ''
|
params ? params : ''
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -74,8 +74,8 @@ const apiInstance = async <T = unknown>({
|
|||||||
body && body instanceof FormData
|
body && body instanceof FormData
|
||||||
? 'multipart/form-data'
|
? 'multipart/form-data'
|
||||||
: 'application/json',
|
: 'application/json',
|
||||||
'User-Agent': `tooot/${Constants.expoConfig?.version}`,
|
|
||||||
Accept: '*/*',
|
Accept: '*/*',
|
||||||
|
...userAgent,
|
||||||
...headers,
|
...headers,
|
||||||
...(token && {
|
...(token && {
|
||||||
Authorization: `Bearer ${token}`
|
Authorization: `Bearer ${token}`
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import * as Sentry from '@sentry/react-native'
|
import * as Sentry from '@sentry/react-native'
|
||||||
import { mapEnvironment } from '@utils/checkEnvironment'
|
import { mapEnvironment } from '@utils/checkEnvironment'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import Constants from 'expo-constants'
|
|
||||||
import handleError, { ctx } from './handleError'
|
import handleError, { ctx } from './handleError'
|
||||||
|
import { userAgent } from './helpers'
|
||||||
|
|
||||||
export type Params = {
|
export type Params = {
|
||||||
method: 'get' | 'post' | 'put' | 'delete'
|
method: 'get' | 'post' | 'put' | 'delete'
|
||||||
@ -50,13 +50,11 @@ const apiTooot = async <T = unknown>({
|
|||||||
body && body instanceof FormData
|
body && body instanceof FormData
|
||||||
? 'multipart/form-data'
|
? 'multipart/form-data'
|
||||||
: 'application/json',
|
: 'application/json',
|
||||||
'User-Agent': `tooot/${Constants.expoConfig?.version}`,
|
|
||||||
Accept: '*/*',
|
Accept: '*/*',
|
||||||
|
...userAgent,
|
||||||
...headers
|
...headers
|
||||||
},
|
},
|
||||||
...(body && { data: body }),
|
...(body && { data: body })
|
||||||
validateStatus: status =>
|
|
||||||
url.includes('translate') ? status < 500 : status === 200
|
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user