use instance URL basename more consistently

This commit is contained in:
Nolan Lawson 2018-02-18 19:41:10 -08:00
parent 944fd098b1
commit a8ebbc517f
6 changed files with 13 additions and 8 deletions

View file

@ -1,7 +1,8 @@
import { get, paramsString } from '../_utils/ajax' import { get, paramsString } from '../_utils/ajax'
import { basename } from './utils'
export async function getBlockedAccounts (instanceName, accessToken, limit = 80) { export async function getBlockedAccounts (instanceName, accessToken, limit = 80) {
let url = `https://${instanceName}/api/v1/blocks` let url = `${basename(instanceName)}/api/v1/blocks`
url += '?' + paramsString({ limit }) url += '?' + paramsString({ limit })
return get(url, { return get(url, {
'Authorization': `Bearer ${accessToken}` 'Authorization': `Bearer ${accessToken}`
@ -9,7 +10,7 @@ export async function getBlockedAccounts (instanceName, accessToken, limit = 80)
} }
export async function getMutedAccounts (instanceName, accessToken, limit = 80) { export async function getMutedAccounts (instanceName, accessToken, limit = 80) {
let url = `https://${instanceName}/api/v1/mutes` let url = `${basename(instanceName)}/api/v1/mutes`
url += '?' + paramsString({ limit }) url += '?' + paramsString({ limit })
return get(url, { return get(url, {
'Authorization': `Bearer ${accessToken}` 'Authorization': `Bearer ${accessToken}`

View file

@ -1,7 +1,8 @@
import { get } from '../_utils/ajax' import { get } from '../_utils/ajax'
import { basename } from './utils'
export function getLists (instanceName, accessToken) { export function getLists (instanceName, accessToken) {
let url = `https://${instanceName}/api/v1/lists` let url = `${basename(instanceName)}/api/v1/lists`
return get(url, { return get(url, {
'Authorization': `Bearer ${accessToken}` 'Authorization': `Bearer ${accessToken}`
}) })

View file

@ -1,7 +1,8 @@
import { get, paramsString } from '../_utils/ajax' import { get, paramsString } from '../_utils/ajax'
import { basename } from './utils'
export async function getPinnedStatuses (instanceName, accessToken, accountId) { export async function getPinnedStatuses (instanceName, accessToken, accountId) {
let url = `https://${instanceName}/api/v1/accounts/${accountId}/statuses` let url = `${basename(instanceName)}/api/v1/accounts/${accountId}/statuses`
url += '?' + paramsString({ url += '?' + paramsString({
limit: 40, limit: 40,
pinned: true pinned: true

View file

@ -1,7 +1,8 @@
import { get, paramsString } from '../_utils/ajax' import { get, paramsString } from '../_utils/ajax'
import { basename } from './utils'
export async function getReblogs (instanceName, accessToken, statusId, limit = 80) { export async function getReblogs (instanceName, accessToken, statusId, limit = 80) {
let url = `https://${instanceName}/api/v1/statuses/${statusId}/reblogged_by` let url = `${basename(instanceName)}/api/v1/statuses/${statusId}/reblogged_by`
url += '?' + paramsString({ limit }) url += '?' + paramsString({ limit })
return get(url, { return get(url, {
'Authorization': `Bearer ${accessToken}` 'Authorization': `Bearer ${accessToken}`
@ -9,7 +10,7 @@ export async function getReblogs (instanceName, accessToken, statusId, limit = 8
} }
export async function getFavorites (instanceName, accessToken, statusId, limit = 80) { export async function getFavorites (instanceName, accessToken, statusId, limit = 80) {
let url = `https://${instanceName}/api/v1/statuses/${statusId}/favourited_by` let url = `${basename(instanceName)}/api/v1/statuses/${statusId}/favourited_by`
url += '?' + paramsString({ limit }) url += '?' + paramsString({ limit })
return get(url, { return get(url, {
'Authorization': `Bearer ${accessToken}` 'Authorization': `Bearer ${accessToken}`

View file

@ -1,7 +1,8 @@
import { get, paramsString } from '../_utils/ajax' import { get, paramsString } from '../_utils/ajax'
import { basename } from './utils'
export function search (instanceName, accessToken, query) { export function search (instanceName, accessToken, query) {
let url = `https://${instanceName}/api/v1/search?` + paramsString({ let url = `${basename(instanceName)}/api/v1/search?` + paramsString({
q: query, q: query,
resolve: true resolve: true
}) })

View file

@ -4,7 +4,7 @@ const isLocalhost = process.browser && process.env.NODE_ENV !== 'production' &&
function targetIsLocalhost (instanceName) { function targetIsLocalhost (instanceName) {
return process.browser && process.env.NODE_ENV !== 'production' && return process.browser && process.env.NODE_ENV !== 'production' &&
(instanceName === 'localhost:3000' || instanceName === '127.0.0.1:3000') (instanceName.startsWith('localhost:') || instanceName.startsWith('127.0.0.1:'))
} }
export function basename (instanceName) { export function basename (instanceName) {