mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Fix #672
Removed image focus as different clients implement this differently
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import axios from 'axios'
|
||||
import { ctx, handleError, PagedResponse, parseHeaderLinks, userAgent } from './helpers'
|
||||
import { ctx, handleError, PagedResponse, parseHeaderLinks, processBody, userAgent } from './helpers'
|
||||
|
||||
export type Params = {
|
||||
method: 'get' | 'post' | 'put' | 'delete'
|
||||
@ -39,15 +39,11 @@ const apiGeneral = async <T = unknown>({
|
||||
url,
|
||||
params,
|
||||
headers: {
|
||||
'Content-Type': body && body instanceof FormData ? 'multipart/form-data' : 'application/json',
|
||||
Accept: '*/*',
|
||||
Accept: 'application/json',
|
||||
...userAgent,
|
||||
...headers
|
||||
},
|
||||
...(body &&
|
||||
(body instanceof FormData
|
||||
? (body as (FormData & { _parts: [][] }) | undefined)?._parts?.length
|
||||
: Object.keys(body).length) && { data: body })
|
||||
data: processBody(body)
|
||||
})
|
||||
.then(response => ({ body: response.data, links: parseHeaderLinks(response.headers.link) }))
|
||||
.catch(handleError())
|
||||
|
@ -94,7 +94,6 @@ export const parseHeaderLinks = (headerLink?: string): PagedResponse['links'] =>
|
||||
}
|
||||
}
|
||||
|
||||
type LinkFormat = { id: string; isOffset: boolean }
|
||||
export type PagedResponse<T = unknown> = {
|
||||
body: T
|
||||
links?: {
|
||||
@ -103,4 +102,20 @@ export type PagedResponse<T = unknown> = {
|
||||
}
|
||||
}
|
||||
|
||||
export const processBody = (body?: FormData | Object): FormData | Object | undefined => {
|
||||
if (!body) return
|
||||
|
||||
if (body instanceof FormData) {
|
||||
if ((body as FormData & { _parts: [][] })._parts?.length) {
|
||||
return body
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(body).length) {
|
||||
return body
|
||||
}
|
||||
}
|
||||
|
||||
export { ctx, handleError, userAgent }
|
||||
|
@ -1,7 +1,14 @@
|
||||
import { getAccountDetails } from '@utils/storage/actions'
|
||||
import { StorageGlobal } from '@utils/storage/global'
|
||||
import axios, { AxiosRequestConfig } from 'axios'
|
||||
import { ctx, handleError, PagedResponse, parseHeaderLinks, userAgent } from './helpers'
|
||||
import {
|
||||
ctx,
|
||||
handleError,
|
||||
PagedResponse,
|
||||
parseHeaderLinks,
|
||||
processBody,
|
||||
userAgent
|
||||
} from './helpers'
|
||||
|
||||
export type Params = {
|
||||
account?: StorageGlobal['account.active']
|
||||
@ -12,7 +19,7 @@ export type Params = {
|
||||
[key: string]: string | number | boolean | string[] | number[] | boolean[]
|
||||
}
|
||||
headers?: { [key: string]: string }
|
||||
body?: FormData
|
||||
body?: FormData | Object
|
||||
extras?: Omit<AxiosRequestConfig, 'method' | 'baseURL' | 'url' | 'params' | 'headers' | 'data'>
|
||||
}
|
||||
|
||||
@ -51,13 +58,12 @@ const apiInstance = async <T = unknown>({
|
||||
url,
|
||||
params,
|
||||
headers: {
|
||||
'Content-Type': body && body instanceof FormData ? 'multipart/form-data' : 'application/json',
|
||||
Accept: '*/*',
|
||||
Accept: 'application/json',
|
||||
...userAgent,
|
||||
...headers,
|
||||
Authorization: `Bearer ${accountDetails['auth.token']}`
|
||||
},
|
||||
...((body as (FormData & { _parts: [][] }) | undefined)?._parts.length && { data: body }),
|
||||
data: processBody(body),
|
||||
...extras
|
||||
})
|
||||
.then(response => ({ body: response.data, links: parseHeaderLinks(response.headers.link) }))
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { mapEnvironment } from '@utils/helpers/checkEnvironment'
|
||||
import axios from 'axios'
|
||||
import { ctx, handleError, userAgent } from './helpers'
|
||||
import { ctx, handleError, processBody, userAgent } from './helpers'
|
||||
|
||||
export type Params = {
|
||||
method: 'get' | 'post' | 'put' | 'delete'
|
||||
@ -42,15 +42,11 @@ const apiTooot = async <T = unknown>({
|
||||
url: `${url}`,
|
||||
params,
|
||||
headers: {
|
||||
'Content-Type': body && body instanceof FormData ? 'multipart/form-data' : 'application/json',
|
||||
Accept: '*/*',
|
||||
Accept: 'application/json',
|
||||
...userAgent,
|
||||
...headers
|
||||
},
|
||||
...(body &&
|
||||
(body instanceof FormData
|
||||
? (body as (FormData & { _parts: [][] }) | undefined)?._parts?.length
|
||||
: Object.keys(body).length) && { data: body })
|
||||
data: processBody(body)
|
||||
})
|
||||
.then(response => {
|
||||
return Promise.resolve({
|
||||
|
@ -1,56 +1,38 @@
|
||||
import { getAccountStorage } from '@utils/storage/actions'
|
||||
|
||||
const features = [
|
||||
{
|
||||
feature: 'account_follow_notify',
|
||||
version: 3.3
|
||||
},
|
||||
{
|
||||
feature: 'notification_type_status',
|
||||
version: 3.3
|
||||
},
|
||||
{
|
||||
feature: 'account_return_suspended',
|
||||
version: 3.3
|
||||
},
|
||||
{
|
||||
feature: 'edit_post',
|
||||
version: 3.5
|
||||
},
|
||||
{
|
||||
feature: 'deprecate_auth_follow',
|
||||
version: 3.5
|
||||
},
|
||||
{
|
||||
feature: 'notification_type_update',
|
||||
version: 3.5
|
||||
},
|
||||
{
|
||||
feature: 'notification_type_admin_signup',
|
||||
version: 3.5
|
||||
},
|
||||
{
|
||||
feature: 'notification_types_positive_filter',
|
||||
version: 3.5
|
||||
},
|
||||
{
|
||||
feature: 'trends_new_path',
|
||||
version: 3.5
|
||||
},
|
||||
{
|
||||
feature: 'follow_tags',
|
||||
version: 4.0
|
||||
},
|
||||
{
|
||||
feature: 'notification_type_admin_report',
|
||||
version: 4.0
|
||||
},
|
||||
{
|
||||
feature: 'filter_server_side',
|
||||
version: 4.0
|
||||
}
|
||||
type Features =
|
||||
| 'account_follow_notify'
|
||||
| 'notification_type_status'
|
||||
| 'account_return_suspended'
|
||||
| 'edit_post'
|
||||
| 'deprecate_auth_follow'
|
||||
| 'notification_type_update'
|
||||
| 'notification_type_admin_signup'
|
||||
| 'notification_types_positive_filter'
|
||||
| 'trends_new_path'
|
||||
| 'follow_tags'
|
||||
| 'notification_type_admin_report'
|
||||
| 'filter_server_side'
|
||||
| 'instance_new_path'
|
||||
| 'edit_media_details'
|
||||
|
||||
const features: { feature: Features; version: number }[] = [
|
||||
{ feature: 'account_follow_notify', version: 3.3 },
|
||||
{ feature: 'notification_type_status', version: 3.3 },
|
||||
{ feature: 'account_return_suspended', version: 3.3 },
|
||||
{ feature: 'edit_post', version: 3.5 },
|
||||
{ feature: 'deprecate_auth_follow', version: 3.5 },
|
||||
{ feature: 'notification_type_update', version: 3.5 },
|
||||
{ feature: 'notification_type_admin_signup', version: 3.5 },
|
||||
{ feature: 'notification_types_positive_filter', version: 3.5 },
|
||||
{ feature: 'trends_new_path', version: 3.5 },
|
||||
{ feature: 'follow_tags', version: 4.0 },
|
||||
{ feature: 'notification_type_admin_report', version: 4.0 },
|
||||
{ feature: 'filter_server_side', version: 4.0 },
|
||||
{ feature: 'instance_new_path', version: 4.0 },
|
||||
{ feature: 'edit_media_details', version: 4.1 }
|
||||
]
|
||||
|
||||
export const featureCheck = (feature: string, v?: string): boolean =>
|
||||
export const featureCheck = (feature: Features, v?: string): boolean =>
|
||||
(features.find(f => f.feature === feature)?.version || 999) <=
|
||||
parseFloat(v || getAccountStorage.string('version'))
|
||||
|
Reference in New Issue
Block a user