diff --git a/routes/_api/blockedAndMuted.js b/routes/_api/blockedAndMuted.js index 4884cf3e..2c995206 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 57406db9..8bc0d473 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 531fd1ff..58e15a94 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 e44156a6..0b67b8af 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 5384d488..f92f524e 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 7c42d1d9..4f391a06 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) {