mirror of https://github.com/tooot-app/app
Fix translation error
When there is body, the method has to be `post`
This commit is contained in:
parent
6c6dc0ce6a
commit
d2ce0aafe8
|
@ -59,7 +59,7 @@ const apiGeneral = async <T = unknown>({
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (sentry) {
|
if (sentry) {
|
||||||
Sentry.Native.setExtras(error.response)
|
Sentry.Native.setExtras(error.response || error.request)
|
||||||
Sentry.Native.captureException(error)
|
Sentry.Native.captureException(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ export type Params = {
|
||||||
sentry?: boolean
|
sentry?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TOOOT_API_DOMAIN = __DEV__ ? 'testapi.tooot.app' : 'testapi.tooot.app'
|
export const TOOOT_API_DOMAIN = __DEV__ ? 'testapi.tooot.app' : 'api.tooot.app'
|
||||||
|
|
||||||
const apiTooot = async <T = unknown>({
|
const apiTooot = async <T = unknown>({
|
||||||
method,
|
method,
|
||||||
|
@ -57,7 +57,7 @@ const apiTooot = async <T = unknown>({
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (sentry) {
|
if (sentry) {
|
||||||
Sentry.Native.setExtras(error.response)
|
Sentry.Native.setExtras(error.response || error.request)
|
||||||
Sentry.Native.captureException(error)
|
Sentry.Native.captureException(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import apiTooot from '@api/tooot'
|
import apiTooot from '@api/tooot'
|
||||||
import haptics from '@components/haptics'
|
import haptics from '@components/haptics'
|
||||||
import { AxiosError } from 'axios'
|
import { AxiosError } from 'axios'
|
||||||
import * as Crypto from 'expo-crypto'
|
|
||||||
import { useQuery, UseQueryOptions } from 'react-query'
|
import { useQuery, UseQueryOptions } from 'react-query'
|
||||||
|
|
||||||
type Translations = {
|
type Translations = {
|
||||||
|
@ -13,7 +12,6 @@ type Translations = {
|
||||||
export type QueryKeyTranslate = [
|
export type QueryKeyTranslate = [
|
||||||
'Translate',
|
'Translate',
|
||||||
{
|
{
|
||||||
uri: string
|
|
||||||
source: string
|
source: string
|
||||||
target: string
|
target: string
|
||||||
text: string[]
|
text: string[]
|
||||||
|
@ -21,23 +19,11 @@ export type QueryKeyTranslate = [
|
||||||
]
|
]
|
||||||
|
|
||||||
const queryFunction = async ({ queryKey }: { queryKey: QueryKeyTranslate }) => {
|
const queryFunction = async ({ queryKey }: { queryKey: QueryKeyTranslate }) => {
|
||||||
const { uri, source, target, text } = queryKey[1]
|
const { source, target, text } = queryKey[1]
|
||||||
|
|
||||||
const uriEncoded = await Crypto.digestStringAsync(
|
|
||||||
Crypto.CryptoDigestAlgorithm.SHA256,
|
|
||||||
uri.replace(/https?:\/\//, ''),
|
|
||||||
{ encoding: Crypto.CryptoEncoding.HEX }
|
|
||||||
)
|
|
||||||
const original = await Crypto.digestStringAsync(
|
|
||||||
Crypto.CryptoDigestAlgorithm.SHA256,
|
|
||||||
JSON.stringify({ source, text }),
|
|
||||||
{ encoding: Crypto.CryptoEncoding.HEX }
|
|
||||||
)
|
|
||||||
|
|
||||||
const res = await apiTooot<Translations>({
|
const res = await apiTooot<Translations>({
|
||||||
method: 'get',
|
method: 'post',
|
||||||
url: '/translate',
|
url: 'translate',
|
||||||
headers: { original },
|
|
||||||
body: { source, target, text }
|
body: { source, target, text }
|
||||||
})
|
})
|
||||||
haptics('Light')
|
haptics('Light')
|
||||||
|
|
Loading…
Reference in New Issue