mirror of
https://github.com/tooot-app/app
synced 2025-05-19 21:14:17 +02:00
Use new api gateway
This commit is contained in:
parent
f3abcf640c
commit
927e7df4e9
@ -5,7 +5,7 @@ export SENTRY_PROJECT=""
|
|||||||
export SENTRY_AUTH_TOKEN=""
|
export SENTRY_AUTH_TOKEN=""
|
||||||
export SENTRY_DSN=""
|
export SENTRY_DSN=""
|
||||||
|
|
||||||
export TRANSLATE_KEY=""
|
export TOOOT_API_KEY=""
|
||||||
|
|
||||||
# Fastlane start
|
# Fastlane start
|
||||||
export LC_ALL=""
|
export LC_ALL=""
|
||||||
|
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -40,7 +40,7 @@ jobs:
|
|||||||
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
|
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
|
||||||
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
||||||
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
|
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
|
||||||
TRANSLATE_KEY: ${{ secrets.TRANSLATE_KEY }}
|
TOOOT_API_KEY: ${{ secrets.TOOOT_API_KEY }}
|
||||||
FASTLANE_USER: ${{ secrets.FASTLANE_USER }}
|
FASTLANE_USER: ${{ secrets.FASTLANE_USER }}
|
||||||
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
|
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
|
||||||
MATCH_GIT_URL: ${{ secrets.MATCH_GIT_URL }}
|
MATCH_GIT_URL: ${{ secrets.MATCH_GIT_URL }}
|
||||||
|
@ -14,7 +14,7 @@ export default (): ExpoConfig => ({
|
|||||||
assetBundlePatterns: ['assets/*'],
|
assetBundlePatterns: ['assets/*'],
|
||||||
extra: {
|
extra: {
|
||||||
sentryDSN: process.env.SENTRY_DSN,
|
sentryDSN: process.env.SENTRY_DSN,
|
||||||
translateKey: process.env.TRANSLATE_KEY
|
toootApiKey: process.env.TOOOT_API_KEY
|
||||||
},
|
},
|
||||||
hooks: {
|
hooks: {
|
||||||
postPublish: [
|
postPublish: [
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"versions": {
|
"versions": {
|
||||||
"native": "210511",
|
"native": "210511",
|
||||||
"major": 2,
|
"major": 2,
|
||||||
"minor": 0,
|
"minor": 1,
|
||||||
"patch": 5,
|
"patch": 0,
|
||||||
"expo": "41.0.0"
|
"expo": "41.0.0"
|
||||||
},
|
},
|
||||||
"description": "tooot app for Mastodon",
|
"description": "tooot app for Mastodon",
|
||||||
|
104
src/api/tooot.ts
Normal file
104
src/api/tooot.ts
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
import axios from 'axios'
|
||||||
|
import chalk from 'chalk'
|
||||||
|
import { Constants } from 'react-native-unimodules'
|
||||||
|
import * as Sentry from 'sentry-expo'
|
||||||
|
|
||||||
|
const ctx = new chalk.Instance({ level: 3 })
|
||||||
|
|
||||||
|
export type Params = {
|
||||||
|
service: 'push' | 'translate'
|
||||||
|
method: 'get' | 'post'
|
||||||
|
url: string
|
||||||
|
params?: {
|
||||||
|
[key: string]: string | number | boolean | string[] | number[] | boolean[]
|
||||||
|
}
|
||||||
|
headers?: { [key: string]: string }
|
||||||
|
body?: FormData | Object
|
||||||
|
sentry?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const DOMAIN = __DEV__ ? 'testapi.tooot.app' : 'api.tooot.app'
|
||||||
|
|
||||||
|
const apiTooot = async <T = unknown>({
|
||||||
|
service,
|
||||||
|
method,
|
||||||
|
url,
|
||||||
|
params,
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
sentry = false
|
||||||
|
}: Params): Promise<{ body: T }> => {
|
||||||
|
const key = Constants.manifest.extra?.toootApiKey
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
ctx.bgGreen.bold(' API tooot ') +
|
||||||
|
' ' +
|
||||||
|
method +
|
||||||
|
ctx.green(' -> ') +
|
||||||
|
`/${url}` +
|
||||||
|
(params ? ctx.green(' -> ') : ''),
|
||||||
|
params ? params : ''
|
||||||
|
)
|
||||||
|
|
||||||
|
return axios({
|
||||||
|
timeout: method === 'post' ? 1000 * 60 : 1000 * 15,
|
||||||
|
method,
|
||||||
|
baseURL: `https://${DOMAIN}/`,
|
||||||
|
url: `${service}/${url}`,
|
||||||
|
params,
|
||||||
|
headers: {
|
||||||
|
...(key && { 'x-tooot-key': key }),
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'User-Agent': `tooot/${Constants.manifest.version}`,
|
||||||
|
Accept: '*/*',
|
||||||
|
...headers
|
||||||
|
},
|
||||||
|
...(body && { data: body })
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
return Promise.resolve({
|
||||||
|
body: response.data
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
if (sentry) {
|
||||||
|
Sentry.Native.setExtras(error.response)
|
||||||
|
Sentry.Native.captureException(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.response) {
|
||||||
|
// The request was made and the server responded with a status code
|
||||||
|
// that falls out of the range of 2xx
|
||||||
|
console.error(
|
||||||
|
ctx.bold(' API tooot '),
|
||||||
|
ctx.bold('response'),
|
||||||
|
error.response.status,
|
||||||
|
error.response.data.error
|
||||||
|
)
|
||||||
|
return Promise.reject({
|
||||||
|
status: error.response.status,
|
||||||
|
message: error.response.data.error
|
||||||
|
})
|
||||||
|
} else if (error.request) {
|
||||||
|
// The request was made but no response was received
|
||||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
|
// http.ClientRequest in node.js
|
||||||
|
console.error(
|
||||||
|
ctx.bold(' API tooot '),
|
||||||
|
ctx.bold('request'),
|
||||||
|
error.request
|
||||||
|
)
|
||||||
|
return Promise.reject()
|
||||||
|
} else {
|
||||||
|
console.error(
|
||||||
|
ctx.bold(' API tooot '),
|
||||||
|
ctx.bold('internal'),
|
||||||
|
error.message,
|
||||||
|
url
|
||||||
|
)
|
||||||
|
return Promise.reject()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default apiTooot
|
@ -1,12 +1,9 @@
|
|||||||
import apiGeneral from '@api/general'
|
import apiGeneral from '@api/general'
|
||||||
|
import apiTooot from '@api/tooot'
|
||||||
import { displayMessage } from '@components/Message'
|
import { displayMessage } from '@components/Message'
|
||||||
import { NavigationContainerRef } from '@react-navigation/native'
|
import { NavigationContainerRef } from '@react-navigation/native'
|
||||||
import { Dispatch } from '@reduxjs/toolkit'
|
import { Dispatch } from '@reduxjs/toolkit'
|
||||||
import {
|
import { disableAllPushes, Instance } from '@utils/slices/instancesSlice'
|
||||||
disableAllPushes,
|
|
||||||
Instance,
|
|
||||||
PUSH_SERVER
|
|
||||||
} from '@utils/slices/instancesSlice'
|
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { TFunction } from 'react-i18next'
|
import { TFunction } from 'react-i18next'
|
||||||
@ -34,10 +31,10 @@ const pushUseConnect = ({
|
|||||||
})
|
})
|
||||||
).data
|
).data
|
||||||
|
|
||||||
apiGeneral({
|
apiTooot({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
domain: PUSH_SERVER,
|
service: 'push',
|
||||||
url: 'v1/connect',
|
url: 'connect',
|
||||||
body: {
|
body: {
|
||||||
expoToken
|
expoToken
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import apiGeneral from '@api/general'
|
import apiTooot from '@api/tooot'
|
||||||
import haptics from '@components/haptics'
|
import haptics from '@components/haptics'
|
||||||
import { AxiosError } from 'axios'
|
import { AxiosError } from 'axios'
|
||||||
import { Buffer } from 'buffer'
|
import { Buffer } from 'buffer'
|
||||||
@ -21,16 +21,7 @@ export type QueryKeyTranslate = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
export const TRANSLATE_SERVER = __DEV__
|
|
||||||
? 'testtranslate.tooot.app'
|
|
||||||
: 'translate.tooot.app'
|
|
||||||
|
|
||||||
const queryFunction = async ({ queryKey }: { queryKey: QueryKeyTranslate }) => {
|
const queryFunction = async ({ queryKey }: { queryKey: QueryKeyTranslate }) => {
|
||||||
const key = Constants.manifest.extra?.translateKey
|
|
||||||
if (!key) {
|
|
||||||
return Promise.reject()
|
|
||||||
}
|
|
||||||
|
|
||||||
const { uri, source, target, text } = queryKey[1]
|
const { uri, source, target, text } = queryKey[1]
|
||||||
|
|
||||||
const uriEncoded = Buffer.from(uri.replace(/https?:\/\//, ''))
|
const uriEncoded = Buffer.from(uri.replace(/https?:\/\//, ''))
|
||||||
@ -42,11 +33,11 @@ const queryFunction = async ({ queryKey }: { queryKey: QueryKeyTranslate }) => {
|
|||||||
'base64'
|
'base64'
|
||||||
)
|
)
|
||||||
|
|
||||||
const res = await apiGeneral<Translations>({
|
const res = await apiTooot<Translations>({
|
||||||
domain: TRANSLATE_SERVER,
|
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: `v1/translate/${uriEncoded}/${target}`,
|
service: 'translate',
|
||||||
headers: { key, original }
|
url: `source/${uriEncoded}/target/${target}`,
|
||||||
|
headers: { original }
|
||||||
})
|
})
|
||||||
haptics('Light')
|
haptics('Light')
|
||||||
return res.body
|
return res.body
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
import apiGeneral from '@api/general'
|
|
||||||
import apiInstance from '@api/instance'
|
import apiInstance from '@api/instance'
|
||||||
|
import apiTooot from '@api/tooot'
|
||||||
import i18n from '@root/i18n/i18n'
|
import i18n from '@root/i18n/i18n'
|
||||||
import { RootState } from '@root/store'
|
import { RootState } from '@root/store'
|
||||||
import {
|
import { getInstance, Instance } from '@utils/slices/instancesSlice'
|
||||||
getInstance,
|
|
||||||
Instance,
|
|
||||||
PUSH_SERVER
|
|
||||||
} from '@utils/slices/instancesSlice'
|
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
import { Platform } from 'react-native'
|
import { Platform } from 'react-native'
|
||||||
import androidDefaults from './androidDefaults'
|
import androidDefaults from './androidDefaults'
|
||||||
@ -22,13 +18,13 @@ const register1 = async ({
|
|||||||
accountId: Mastodon.Account['id']
|
accountId: Mastodon.Account['id']
|
||||||
accountFull: string
|
accountFull: string
|
||||||
}) => {
|
}) => {
|
||||||
return apiGeneral<{
|
return apiTooot<{
|
||||||
endpoint: string
|
endpoint: string
|
||||||
keys: { public: string; private: string; auth: string }
|
keys: { public: string; private: string; auth: string }
|
||||||
}>({
|
}>({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
domain: PUSH_SERVER,
|
service: 'push',
|
||||||
url: 'v1/register1',
|
url: 'register1',
|
||||||
body: { expoToken, instanceUrl, accountId, accountFull },
|
body: { expoToken, instanceUrl, accountId, accountFull },
|
||||||
sentry: true
|
sentry: true
|
||||||
})
|
})
|
||||||
@ -47,10 +43,10 @@ const register2 = async ({
|
|||||||
accountId: Mastodon.Account['id']
|
accountId: Mastodon.Account['id']
|
||||||
removeKeys: boolean
|
removeKeys: boolean
|
||||||
}) => {
|
}) => {
|
||||||
return apiGeneral({
|
return apiTooot({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
domain: PUSH_SERVER,
|
service: 'push',
|
||||||
url: 'v1/register2',
|
url: 'register2',
|
||||||
body: { expoToken, instanceUrl, accountId, serverKey, removeKeys },
|
body: { expoToken, instanceUrl, accountId, serverKey, removeKeys },
|
||||||
sentry: true
|
sentry: true
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import apiGeneral from '@api/general'
|
|
||||||
import apiInstance from '@api/instance'
|
import apiInstance from '@api/instance'
|
||||||
|
import apiTooot from '@api/tooot'
|
||||||
import { RootState } from '@root/store'
|
import { RootState } from '@root/store'
|
||||||
import { getInstance, PUSH_SERVER } from '@utils/slices/instancesSlice'
|
import { getInstance } from '@utils/slices/instancesSlice'
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
import { Platform } from 'react-native'
|
import { Platform } from 'react-native'
|
||||||
|
|
||||||
@ -19,10 +19,10 @@ const pushUnregister = async (state: RootState, expoToken: string) => {
|
|||||||
url: 'push/subscription'
|
url: 'push/subscription'
|
||||||
})
|
})
|
||||||
|
|
||||||
await apiGeneral<{ endpoint: string; publicKey: string; auth: string }>({
|
await apiTooot<{ endpoint: string; publicKey: string; auth: string }>({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
domain: PUSH_SERVER,
|
service: 'push',
|
||||||
url: 'v1/unregister',
|
url: 'unregister',
|
||||||
body: {
|
body: {
|
||||||
expoToken,
|
expoToken,
|
||||||
instanceUrl: instance.url,
|
instanceUrl: instance.url,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import apiGeneral from '@api/general'
|
import apiTooot from '@api/tooot'
|
||||||
import { createAsyncThunk } from '@reduxjs/toolkit'
|
import { createAsyncThunk } from '@reduxjs/toolkit'
|
||||||
import i18n from '@root/i18n/i18n'
|
import i18n from '@root/i18n/i18n'
|
||||||
import { RootState } from '@root/store'
|
import { RootState } from '@root/store'
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
import { Platform } from 'react-native'
|
import { Platform } from 'react-native'
|
||||||
import { getInstance, Instance, PUSH_SERVER } from '../instancesSlice'
|
import { getInstance, Instance } from '../instancesSlice'
|
||||||
import androidDefaults from './push/androidDefaults'
|
import androidDefaults from './push/androidDefaults'
|
||||||
|
|
||||||
export const updateInstancePushDecode = createAsyncThunk(
|
export const updateInstancePushDecode = createAsyncThunk(
|
||||||
@ -25,10 +25,10 @@ export const updateInstancePushDecode = createAsyncThunk(
|
|||||||
})
|
})
|
||||||
).data
|
).data
|
||||||
|
|
||||||
await apiGeneral({
|
await apiTooot({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
domain: PUSH_SERVER,
|
service: 'push',
|
||||||
url: 'v1/update-decode',
|
url: 'update-decode',
|
||||||
body: {
|
body: {
|
||||||
expoToken,
|
expoToken,
|
||||||
instanceUrl: instance.url,
|
instanceUrl: instance.url,
|
||||||
|
@ -11,8 +11,6 @@ import { updateInstancePush } from './instances/updatePush'
|
|||||||
import { updateInstancePushAlert } from './instances/updatePushAlert'
|
import { updateInstancePushAlert } from './instances/updatePushAlert'
|
||||||
import { updateInstancePushDecode } from './instances/updatePushDecode'
|
import { updateInstancePushDecode } from './instances/updatePushDecode'
|
||||||
|
|
||||||
export const PUSH_SERVER = __DEV__ ? 'testpush.tooot.app' : 'push.tooot.app'
|
|
||||||
|
|
||||||
export type Instance = {
|
export type Instance = {
|
||||||
active: boolean
|
active: boolean
|
||||||
appData: {
|
appData: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user