From a8ebbc517f1a82fa5f7ee1505320ae9094bd9ed6 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 18 Feb 2018 19:41:10 -0800 Subject: [PATCH] use instance URL basename more consistently --- routes/_api/blockedAndMuted.js | 5 +++-- routes/_api/lists.js | 3 ++- routes/_api/pinnedStatuses.js | 3 ++- routes/_api/reblogsAndFavs.js | 5 +++-- routes/_api/search.js | 3 ++- routes/_api/utils.js | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/routes/_api/blockedAndMuted.js b/routes/_api/blockedAndMuted.js index 4884cf3..2c99520 100644 --- a/routes/_api/blockedAndMuted.js +++ b/routes/_api/blockedAndMuted.js @@ -1,7 +1,8 @@ import { get, paramsString } from '../_utils/ajax' +import { basename } from './utils' 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 }) return get(url, { 'Authorization': `Bearer ${accessToken}` @@ -9,7 +10,7 @@ export async function getBlockedAccounts (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 }) return get(url, { 'Authorization': `Bearer ${accessToken}` diff --git a/routes/_api/lists.js b/routes/_api/lists.js index 57406db..8bc0d47 100644 --- a/routes/_api/lists.js +++ b/routes/_api/lists.js @@ -1,7 +1,8 @@ import { get } from '../_utils/ajax' +import { basename } from './utils' export function getLists (instanceName, accessToken) { - let url = `https://${instanceName}/api/v1/lists` + let url = `${basename(instanceName)}/api/v1/lists` return get(url, { 'Authorization': `Bearer ${accessToken}` }) diff --git a/routes/_api/pinnedStatuses.js b/routes/_api/pinnedStatuses.js index 531fd1f..58e15a9 100644 --- a/routes/_api/pinnedStatuses.js +++ b/routes/_api/pinnedStatuses.js @@ -1,7 +1,8 @@ import { get, paramsString } from '../_utils/ajax' +import { basename } from './utils' 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({ limit: 40, pinned: true diff --git a/routes/_api/reblogsAndFavs.js b/routes/_api/reblogsAndFavs.js index e44156a..0b67b8a 100644 --- a/routes/_api/reblogsAndFavs.js +++ b/routes/_api/reblogsAndFavs.js @@ -1,7 +1,8 @@ import { get, paramsString } from '../_utils/ajax' +import { basename } from './utils' 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 }) return get(url, { '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) { - let url = `https://${instanceName}/api/v1/statuses/${statusId}/favourited_by` + let url = `${basename(instanceName)}/api/v1/statuses/${statusId}/favourited_by` url += '?' + paramsString({ limit }) return get(url, { 'Authorization': `Bearer ${accessToken}` diff --git a/routes/_api/search.js b/routes/_api/search.js index 5384d48..f92f524 100644 --- a/routes/_api/search.js +++ b/routes/_api/search.js @@ -1,7 +1,8 @@ import { get, paramsString } from '../_utils/ajax' +import { basename } from './utils' export function search (instanceName, accessToken, query) { - let url = `https://${instanceName}/api/v1/search?` + paramsString({ + let url = `${basename(instanceName)}/api/v1/search?` + paramsString({ q: query, resolve: true }) diff --git a/routes/_api/utils.js b/routes/_api/utils.js index 7c42d1d..4f391a0 100644 --- a/routes/_api/utils.js +++ b/routes/_api/utils.js @@ -4,7 +4,7 @@ const isLocalhost = process.browser && process.env.NODE_ENV !== 'production' && function targetIsLocalhost (instanceName) { 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) {