diff options
Diffstat (limited to 'web/source/settings/lib/api')
-rw-r--r-- | web/source/settings/lib/api/admin.js | 27 | ||||
-rw-r--r-- | web/source/settings/lib/api/index.js | 44 |
2 files changed, 26 insertions, 45 deletions
diff --git a/web/source/settings/lib/api/admin.js b/web/source/settings/lib/api/admin.js index 56513b900..5f4fa1d1f 100644 --- a/web/source/settings/lib/api/admin.js +++ b/web/source/settings/lib/api/admin.js @@ -160,33 +160,6 @@ module.exports = function ({ apiCall, getChanges }) { }); }; }, - - fetchCustomEmoji: function fetchCustomEmoji() { - return function (dispatch, _getState) { - return Promise.try(() => { - return dispatch(apiCall("GET", "/api/v1/admin/custom_emojis?filter=domain:local&limit=0")); - }).then((emoji) => { - return dispatch(admin.setEmoji(emoji)); - }); - }; - }, - - newEmoji: function newEmoji() { - return function (dispatch, getState) { - return Promise.try(() => { - const state = getState().admin.newEmoji; - - const update = getChanges(state, { - formKeys: ["shortcode"], - fileKeys: ["image"] - }); - - return dispatch(apiCall("POST", "/api/v1/admin/custom_emojis", update, "form")); - }).then((emoji) => { - return dispatch(admin.addEmoji(emoji)); - }); - }; - } }; return adminAPI; };
\ No newline at end of file diff --git a/web/source/settings/lib/api/index.js b/web/source/settings/lib/api/index.js index e699011bd..8af7d5b43 100644 --- a/web/source/settings/lib/api/index.js +++ b/web/source/settings/lib/api/index.js @@ -24,14 +24,12 @@ const d = require("dotty"); const { APIError, AuthenticationError } = require("../errors"); const { setInstanceInfo, setNamedInstanceInfo } = require("../../redux/reducers/instances").actions; -const oauth = require("../../redux/reducers/oauth").actions; function apiCall(method, route, payload, type = "json") { return function (dispatch, getState) { const state = getState(); let base = state.oauth.instance; let auth = state.oauth.token; - console.log(method, base, route, "auth:", auth != undefined); return Promise.try(() => { let url = new URL(base); @@ -51,21 +49,7 @@ function apiCall(method, route, payload, type = "json") { headers["Content-Type"] = "application/json"; body = JSON.stringify(payload); } else if (type == "form") { - const formData = new FormData(); - Object.entries(payload).forEach(([key, val]) => { - if (isPlainObject(val)) { - Object.entries(val).forEach(([key2, val2]) => { - if (val2 != undefined) { - formData.set(`${key}[${key2}]`, val2); - } - }); - } else { - if (val != undefined) { - formData.set(key, val); - } - } - }); - body = formData; + body = convertToForm(payload); } } @@ -100,6 +84,28 @@ function apiCall(method, route, payload, type = "json") { }; } +/* + Takes an object with (nested) keys, and transforms it into + a FormData object to be sent over the API +*/ +function convertToForm(payload) { + const formData = new FormData(); + Object.entries(payload).forEach(([key, val]) => { + if (isPlainObject(val)) { + Object.entries(val).forEach(([key2, val2]) => { + if (val2 != undefined) { + formData.set(`${key}[${key2}]`, val2); + } + }); + } else { + if (val != undefined) { + formData.set(key, val); + } + } + }); + return formData; +} + function getChanges(state, keys) { const { formKeys = [], fileKeys = [], renamedKeys = {} } = keys; const update = {}; @@ -129,7 +135,8 @@ function getChanges(state, keys) { } function getCurrentUrl() { - return `${window.location.origin}${window.location.pathname}`; + let [pre, _past] = window.location.pathname.split("/settings"); + return `${window.location.origin}${pre}/settings`; } function fetchInstanceWithoutStore(domain) { @@ -181,5 +188,6 @@ module.exports = { user: require("./user")(submoduleArgs), admin: require("./admin")(submoduleArgs), apiCall, + convertToForm, getChanges };
\ No newline at end of file |