From d2ce0aafe81eea2d4259abe3a3b92018f98e6786 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Wed, 8 Dec 2021 23:11:51 +0100 Subject: [PATCH 1/3] Fix translation error When there is body, the method has to be `post` --- src/api/general.ts | 2 +- src/api/tooot.ts | 4 ++-- src/utils/queryHooks/translate.ts | 20 +++----------------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/api/general.ts b/src/api/general.ts index d2779e49..19ef755a 100644 --- a/src/api/general.ts +++ b/src/api/general.ts @@ -59,7 +59,7 @@ const apiGeneral = async ({ }) .catch(error => { if (sentry) { - Sentry.Native.setExtras(error.response) + Sentry.Native.setExtras(error.response || error.request) Sentry.Native.captureException(error) } diff --git a/src/api/tooot.ts b/src/api/tooot.ts index 79afb1a8..845b70cb 100644 --- a/src/api/tooot.ts +++ b/src/api/tooot.ts @@ -16,7 +16,7 @@ export type Params = { 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 ({ method, @@ -57,7 +57,7 @@ const apiTooot = async ({ }) .catch(error => { if (sentry) { - Sentry.Native.setExtras(error.response) + Sentry.Native.setExtras(error.response || error.request) Sentry.Native.captureException(error) } diff --git a/src/utils/queryHooks/translate.ts b/src/utils/queryHooks/translate.ts index 7bb8e084..64aec663 100644 --- a/src/utils/queryHooks/translate.ts +++ b/src/utils/queryHooks/translate.ts @@ -1,7 +1,6 @@ import apiTooot from '@api/tooot' import haptics from '@components/haptics' import { AxiosError } from 'axios' -import * as Crypto from 'expo-crypto' import { useQuery, UseQueryOptions } from 'react-query' type Translations = { @@ -13,7 +12,6 @@ type Translations = { export type QueryKeyTranslate = [ 'Translate', { - uri: string source: string target: string text: string[] @@ -21,23 +19,11 @@ export type QueryKeyTranslate = [ ] const queryFunction = async ({ queryKey }: { queryKey: QueryKeyTranslate }) => { - const { uri, 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 { source, target, text } = queryKey[1] const res = await apiTooot({ - method: 'get', - url: '/translate', - headers: { original }, + method: 'post', + url: 'translate', body: { source, target, text } }) haptics('Light') From e2c5e173d5149c52c89ea5b0e6f896c172a6a6a1 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Sun, 12 Dec 2021 22:09:18 +0100 Subject: [PATCH 2/3] Final test for new push system --- src/utils/push/useConnect.ts | 10 +++------- src/utils/slices/instances/push/register.ts | 2 +- src/utils/slices/instances/updatePushDecode.ts | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/utils/push/useConnect.ts b/src/utils/push/useConnect.ts index 77f3ad6b..e0ef63fb 100644 --- a/src/utils/push/useConnect.ts +++ b/src/utils/push/useConnect.ts @@ -25,12 +25,8 @@ const pushUseConnect = ({ mode, t, instances, dispatch }: Params) => { ).data apiTooot({ - method: 'post', - service: 'push', - url: 'connect', - body: { - expoToken - }, + method: 'get', + url: `push/connect/${expoToken}`, sentry: true }).catch(error => { if (error.status == 410) { @@ -76,7 +72,7 @@ const pushUseConnect = ({ mode, t, instances, dispatch }: Params) => { const pushEnabled = instances.filter(instance => instance.push.global.value) if (pushEnabled.length) { - // connect() + connect() } }, [instances]) } diff --git a/src/utils/slices/instances/push/register.ts b/src/utils/slices/instances/push/register.ts index 38f1cefd..c91a9279 100644 --- a/src/utils/slices/instances/push/register.ts +++ b/src/utils/slices/instances/push/register.ts @@ -77,7 +77,7 @@ const pushRegister = async ( accountId, accountFull, serverKey: res.body.server_key, - auth + auth: instancePush.decode.value === false ? null : auth }) if (Platform.OS === 'android') { diff --git a/src/utils/slices/instances/updatePushDecode.ts b/src/utils/slices/instances/updatePushDecode.ts index 172ca3d4..5ef848ed 100644 --- a/src/utils/slices/instances/updatePushDecode.ts +++ b/src/utils/slices/instances/updatePushDecode.ts @@ -29,7 +29,7 @@ export const updateInstancePushDecode = createAsyncThunk( method: 'put', url: `/push/update-decode/${expoToken}/${instance.url}/${instance.account.id}`, body: { - auth: disable ? null : instance.push.keys.auth + auth: !disable ? null : instance.push.keys.auth }, sentry: true }) From a84a3731c80c23ddf47f86b56add9822217e7e05 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Sun, 12 Dec 2021 22:11:15 +0100 Subject: [PATCH 3/3] Update tooot.ts --- src/api/tooot.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/tooot.ts b/src/api/tooot.ts index 845b70cb..2e26f241 100644 --- a/src/api/tooot.ts +++ b/src/api/tooot.ts @@ -16,7 +16,7 @@ export type Params = { sentry?: boolean } -export const TOOOT_API_DOMAIN = __DEV__ ? 'testapi.tooot.app' : 'api.tooot.app' +export const TOOOT_API_DOMAIN = __DEV__ ? 'testapi.tooot.app' : 'testapi.tooot.app' const apiTooot = async ({ method,