1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Main updates

This commit is contained in:
Zhiyuan Zheng
2021-08-22 00:17:24 +02:00
parent 74359a9592
commit 44ec3e5b87
5 changed files with 1600 additions and 2771 deletions

View File

@@ -28,7 +28,7 @@ const apiTooot = async <T = unknown>({
body,
sentry = false
}: Params): Promise<{ body: T }> => {
const key = Constants.manifest.extra?.toootApiKey
const key = Constants.manifest?.extra?.toootApiKey
console.log(
ctx.bgGreen.bold(' API tooot ') +
@@ -49,7 +49,7 @@ const apiTooot = async <T = unknown>({
headers: {
...(key && { 'x-tooot-key': key }),
'Content-Type': 'application/json',
'User-Agent': `tooot/${Constants.manifest.version}`,
'User-Agent': `tooot/${Constants.manifest?.version}`,
Accept: '*/*',
...headers
},

View File

@@ -1,8 +1,7 @@
import apiTooot from '@api/tooot'
import haptics from '@components/haptics'
import { AxiosError } from 'axios'
import { Buffer } from 'buffer'
import Constants from 'expo-constants'
import * as Crypto from 'expo-crypto'
import { useQuery, UseQueryOptions } from 'react-query'
type Translations = {
@@ -24,13 +23,15 @@ export type QueryKeyTranslate = [
const queryFunction = async ({ queryKey }: { queryKey: QueryKeyTranslate }) => {
const { uri, source, target, text } = queryKey[1]
const uriEncoded = Buffer.from(uri.replace(/https?:\/\//, ''))
.toString('base64')
.replace('+', '-')
.replace('/', '_')
.replace(/=+$/, '')
const original = Buffer.from(JSON.stringify({ source, text })).toString(
'base64'
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>({