From 10d3f3f0a03d56ed30dcb8399ec5f7a6b17d3ea4 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Tue, 24 Sep 2019 19:38:35 +0300 Subject: [PATCH 1/3] Use the remote pack listing endpoint --- src/api/emoji_packs.js | 10 ++++++++++ src/store/modules/emoji_packs.js | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/api/emoji_packs.js b/src/api/emoji_packs.js index ce261fdb..4e7c85dd 100644 --- a/src/api/emoji_packs.js +++ b/src/api/emoji_packs.js @@ -48,6 +48,16 @@ export async function listPacks(host) { }) } +export async function listRemotePacks(host, token, instance) { + return await request({ + baseURL: baseName(host), + url: `/api/pleroma/emoji/packs/list_from`, + method: 'post', + headers: authHeaders(token), + data: { instance_address: instance } + }) +} + export async function downloadFrom(host, instance_address, pack_name, as, token) { if (as.trim() === '') { as = null diff --git a/src/store/modules/emoji_packs.js b/src/store/modules/emoji_packs.js index 20dacf3a..1cee0060 100644 --- a/src/store/modules/emoji_packs.js +++ b/src/store/modules/emoji_packs.js @@ -1,4 +1,6 @@ -import { listPacks, +import { + listPacks, + listRemotePacks, downloadFrom, reloadEmoji, createPack, @@ -47,7 +49,8 @@ const packs = { commit('SET_LOCAL_PACKS', data) }, async SetRemoteEmojiPacks({ commit, getters, state }, { remoteInstance }) { - const { data } = await listPacks(remoteInstance) + const { data } = await listRemotePacks(getters.authHost, getters.token, remoteInstance) + commit('SET_REMOTE_PACKS', data) }, async DownloadFrom({ commit, getters, state }, { instanceAddress, packName, as }) { From 2662210063208482c85c8bff34865db8c88beef7 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Tue, 24 Sep 2019 20:10:50 +0300 Subject: [PATCH 2/3] Make baseName check if http is already in the name --- src/api/utils.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/api/utils.js b/src/api/utils.js index 4943f650..1346a204 100644 --- a/src/api/utils.js +++ b/src/api/utils.js @@ -1,5 +1,10 @@ const isLocalhost = (instanceName) => instanceName.startsWith('localhost:') || instanceName.startsWith('127.0.0.1:') -export const baseName = (instanceName) => - isLocalhost(instanceName) ? `http://${instanceName}` : `https://${instanceName}` +export const baseName = (instanceName) => { + if (instanceName.match(/https?:\/\//)) { + return instanceName + } else { + return isLocalhost(instanceName) ? `http://${instanceName}` : `https://${instanceName}` + } +} From e9060cd8bada7a10fa21c9964252381dc923b033 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Tue, 24 Sep 2019 20:12:17 +0300 Subject: [PATCH 3/3] Add baseName to some remote instance requests --- src/api/emoji_packs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/emoji_packs.js b/src/api/emoji_packs.js index 4e7c85dd..cc07b1b6 100644 --- a/src/api/emoji_packs.js +++ b/src/api/emoji_packs.js @@ -54,7 +54,7 @@ export async function listRemotePacks(host, token, instance) { url: `/api/pleroma/emoji/packs/list_from`, method: 'post', headers: authHeaders(token), - data: { instance_address: instance } + data: { instance_address: baseName(instance) } }) } @@ -68,7 +68,7 @@ export async function downloadFrom(host, instance_address, pack_name, as, token) url: '/api/pleroma/emoji/packs/download_from', method: 'post', headers: authHeaders(token), - data: { instance_address, pack_name, as }, + data: { instance_address: baseName(instance_address), pack_name, as }, timeout: 0 }) }