From c285546052f20f675569c9b2c82146ecbcb398ab Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 11 Oct 2022 10:32:31 +0200 Subject: Move flavours/glitch/util/api to flavours/glitch/api --- .../flavours/glitch/actions/account_notes.js | 2 +- app/javascript/flavours/glitch/actions/accounts.js | 2 +- .../flavours/glitch/actions/announcements.js | 2 +- app/javascript/flavours/glitch/actions/blocks.js | 2 +- .../flavours/glitch/actions/bookmarks.js | 2 +- app/javascript/flavours/glitch/actions/compose.js | 2 +- .../flavours/glitch/actions/conversations.js | 2 +- .../flavours/glitch/actions/custom_emojis.js | 2 +- .../flavours/glitch/actions/directory.js | 2 +- .../flavours/glitch/actions/domain_blocks.js | 2 +- .../flavours/glitch/actions/favourites.js | 2 +- app/javascript/flavours/glitch/actions/filters.js | 2 +- app/javascript/flavours/glitch/actions/history.js | 2 +- .../flavours/glitch/actions/identity_proofs.js | 2 +- .../flavours/glitch/actions/interactions.js | 2 +- app/javascript/flavours/glitch/actions/lists.js | 2 +- app/javascript/flavours/glitch/actions/markers.js | 2 +- app/javascript/flavours/glitch/actions/mutes.js | 2 +- .../flavours/glitch/actions/notifications.js | 2 +- .../flavours/glitch/actions/pin_statuses.js | 2 +- app/javascript/flavours/glitch/actions/polls.js | 2 +- .../actions/push_notifications/registerer.js | 2 +- app/javascript/flavours/glitch/actions/reports.js | 2 +- app/javascript/flavours/glitch/actions/search.js | 2 +- app/javascript/flavours/glitch/actions/server.js | 2 +- app/javascript/flavours/glitch/actions/settings.js | 2 +- app/javascript/flavours/glitch/actions/statuses.js | 2 +- .../flavours/glitch/actions/suggestions.js | 2 +- app/javascript/flavours/glitch/actions/tags.js | 2 +- .../flavours/glitch/actions/timelines.js | 2 +- app/javascript/flavours/glitch/actions/trends.js | 2 +- app/javascript/flavours/glitch/api.js | 52 ++++++++++++++++++++++ .../flavours/glitch/components/admin/Counter.js | 2 +- .../flavours/glitch/components/admin/Dimension.js | 2 +- .../components/admin/ReportReasonSelector.js | 2 +- .../flavours/glitch/components/admin/Retention.js | 2 +- .../flavours/glitch/components/admin/Trends.js | 2 +- .../containers/column_settings_container.js | 2 +- .../glitch/features/ui/components/embed_modal.js | 2 +- app/javascript/flavours/glitch/util/api.js | 52 ---------------------- 40 files changed, 90 insertions(+), 90 deletions(-) create mode 100644 app/javascript/flavours/glitch/api.js delete mode 100644 app/javascript/flavours/glitch/util/api.js (limited to 'app/javascript/flavours') diff --git a/app/javascript/flavours/glitch/actions/account_notes.js b/app/javascript/flavours/glitch/actions/account_notes.js index c1cce3193..059ed9e80 100644 --- a/app/javascript/flavours/glitch/actions/account_notes.js +++ b/app/javascript/flavours/glitch/actions/account_notes.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; export const ACCOUNT_NOTE_SUBMIT_REQUEST = 'ACCOUNT_NOTE_SUBMIT_REQUEST'; export const ACCOUNT_NOTE_SUBMIT_SUCCESS = 'ACCOUNT_NOTE_SUBMIT_SUCCESS'; diff --git a/app/javascript/flavours/glitch/actions/accounts.js b/app/javascript/flavours/glitch/actions/accounts.js index 750740879..dc670e50a 100644 --- a/app/javascript/flavours/glitch/actions/accounts.js +++ b/app/javascript/flavours/glitch/actions/accounts.js @@ -1,4 +1,4 @@ -import api, { getLinks } from 'flavours/glitch/util/api'; +import api, { getLinks } from '../api'; import { importAccount, importFetchedAccount, importFetchedAccounts } from './importer'; export const ACCOUNT_FETCH_REQUEST = 'ACCOUNT_FETCH_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/announcements.js b/app/javascript/flavours/glitch/actions/announcements.js index 871409d43..1bdea909f 100644 --- a/app/javascript/flavours/glitch/actions/announcements.js +++ b/app/javascript/flavours/glitch/actions/announcements.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { normalizeAnnouncement } from './importer/normalizer'; export const ANNOUNCEMENTS_FETCH_REQUEST = 'ANNOUNCEMENTS_FETCH_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/blocks.js b/app/javascript/flavours/glitch/actions/blocks.js index adae9d83c..fd9881302 100644 --- a/app/javascript/flavours/glitch/actions/blocks.js +++ b/app/javascript/flavours/glitch/actions/blocks.js @@ -1,4 +1,4 @@ -import api, { getLinks } from 'flavours/glitch/util/api'; +import api, { getLinks } from '../api'; import { fetchRelationships } from './accounts'; import { importFetchedAccounts } from './importer'; import { openModal } from './modal'; diff --git a/app/javascript/flavours/glitch/actions/bookmarks.js b/app/javascript/flavours/glitch/actions/bookmarks.js index 83dbf5407..544ed2ff2 100644 --- a/app/javascript/flavours/glitch/actions/bookmarks.js +++ b/app/javascript/flavours/glitch/actions/bookmarks.js @@ -1,4 +1,4 @@ -import api, { getLinks } from 'flavours/glitch/util/api'; +import api, { getLinks } from '../api'; import { importFetchedStatuses } from './importer'; export const BOOKMARKED_STATUSES_FETCH_REQUEST = 'BOOKMARKED_STATUSES_FETCH_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index ab74fb303..b34ac6253 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { CancelToken, isCancel } from 'axios'; import { throttle } from 'lodash'; import { search as emojiSearch } from 'flavours/glitch/util/emoji/emoji_mart_search_light'; diff --git a/app/javascript/flavours/glitch/actions/conversations.js b/app/javascript/flavours/glitch/actions/conversations.js index e5c85c65d..4ef654b1f 100644 --- a/app/javascript/flavours/glitch/actions/conversations.js +++ b/app/javascript/flavours/glitch/actions/conversations.js @@ -1,4 +1,4 @@ -import api, { getLinks } from 'flavours/glitch/util/api'; +import api, { getLinks } from '../api'; import { importFetchedAccounts, importFetchedStatuses, diff --git a/app/javascript/flavours/glitch/actions/custom_emojis.js b/app/javascript/flavours/glitch/actions/custom_emojis.js index 29ae72edb..7b7d0091b 100644 --- a/app/javascript/flavours/glitch/actions/custom_emojis.js +++ b/app/javascript/flavours/glitch/actions/custom_emojis.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; export const CUSTOM_EMOJIS_FETCH_REQUEST = 'CUSTOM_EMOJIS_FETCH_REQUEST'; export const CUSTOM_EMOJIS_FETCH_SUCCESS = 'CUSTOM_EMOJIS_FETCH_SUCCESS'; diff --git a/app/javascript/flavours/glitch/actions/directory.js b/app/javascript/flavours/glitch/actions/directory.js index 9fbfb7f5b..4b2b6dd56 100644 --- a/app/javascript/flavours/glitch/actions/directory.js +++ b/app/javascript/flavours/glitch/actions/directory.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { importFetchedAccounts } from './importer'; import { fetchRelationships } from './accounts'; diff --git a/app/javascript/flavours/glitch/actions/domain_blocks.js b/app/javascript/flavours/glitch/actions/domain_blocks.js index 6d3f471fa..34a33a654 100644 --- a/app/javascript/flavours/glitch/actions/domain_blocks.js +++ b/app/javascript/flavours/glitch/actions/domain_blocks.js @@ -1,4 +1,4 @@ -import api, { getLinks } from 'flavours/glitch/util/api'; +import api, { getLinks } from '../api'; export const DOMAIN_BLOCK_REQUEST = 'DOMAIN_BLOCK_REQUEST'; export const DOMAIN_BLOCK_SUCCESS = 'DOMAIN_BLOCK_SUCCESS'; diff --git a/app/javascript/flavours/glitch/actions/favourites.js b/app/javascript/flavours/glitch/actions/favourites.js index 0d8bfb14d..9448b1efe 100644 --- a/app/javascript/flavours/glitch/actions/favourites.js +++ b/app/javascript/flavours/glitch/actions/favourites.js @@ -1,4 +1,4 @@ -import api, { getLinks } from 'flavours/glitch/util/api'; +import api, { getLinks } from '../api'; import { importFetchedStatuses } from './importer'; export const FAVOURITED_STATUSES_FETCH_REQUEST = 'FAVOURITED_STATUSES_FETCH_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/filters.js b/app/javascript/flavours/glitch/actions/filters.js index 9aa31028a..76326802e 100644 --- a/app/javascript/flavours/glitch/actions/filters.js +++ b/app/javascript/flavours/glitch/actions/filters.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { openModal } from './modal'; export const FILTERS_FETCH_REQUEST = 'FILTERS_FETCH_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/history.js b/app/javascript/flavours/glitch/actions/history.js index c47057261..c142aaf61 100644 --- a/app/javascript/flavours/glitch/actions/history.js +++ b/app/javascript/flavours/glitch/actions/history.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { importFetchedAccounts } from './importer'; export const HISTORY_FETCH_REQUEST = 'HISTORY_FETCH_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/identity_proofs.js b/app/javascript/flavours/glitch/actions/identity_proofs.js index 18e679aec..103983956 100644 --- a/app/javascript/flavours/glitch/actions/identity_proofs.js +++ b/app/javascript/flavours/glitch/actions/identity_proofs.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; export const IDENTITY_PROOFS_ACCOUNT_FETCH_REQUEST = 'IDENTITY_PROOFS_ACCOUNT_FETCH_REQUEST'; export const IDENTITY_PROOFS_ACCOUNT_FETCH_SUCCESS = 'IDENTITY_PROOFS_ACCOUNT_FETCH_SUCCESS'; diff --git a/app/javascript/flavours/glitch/actions/interactions.js b/app/javascript/flavours/glitch/actions/interactions.js index 336c8fa90..225ee7eb2 100644 --- a/app/javascript/flavours/glitch/actions/interactions.js +++ b/app/javascript/flavours/glitch/actions/interactions.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { importFetchedAccounts, importFetchedStatus } from './importer'; export const REBLOG_REQUEST = 'REBLOG_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/lists.js b/app/javascript/flavours/glitch/actions/lists.js index c2309b8c2..5ab922436 100644 --- a/app/javascript/flavours/glitch/actions/lists.js +++ b/app/javascript/flavours/glitch/actions/lists.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { importFetchedAccounts } from './importer'; import { showAlertForError } from './alerts'; diff --git a/app/javascript/flavours/glitch/actions/markers.js b/app/javascript/flavours/glitch/actions/markers.js index 6a0549f7f..943052c0d 100644 --- a/app/javascript/flavours/glitch/actions/markers.js +++ b/app/javascript/flavours/glitch/actions/markers.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { debounce } from 'lodash'; import compareId from 'flavours/glitch/util/compare_id'; import { List as ImmutableList } from 'immutable'; diff --git a/app/javascript/flavours/glitch/actions/mutes.js b/app/javascript/flavours/glitch/actions/mutes.js index 2bacfadb7..1ccf9592f 100644 --- a/app/javascript/flavours/glitch/actions/mutes.js +++ b/app/javascript/flavours/glitch/actions/mutes.js @@ -1,4 +1,4 @@ -import api, { getLinks } from 'flavours/glitch/util/api'; +import api, { getLinks } from '../api'; import { fetchRelationships } from './accounts'; import { importFetchedAccounts } from './importer'; import { openModal } from 'flavours/glitch/actions/modal'; diff --git a/app/javascript/flavours/glitch/actions/notifications.js b/app/javascript/flavours/glitch/actions/notifications.js index 4cabd3f4f..a2deb0210 100644 --- a/app/javascript/flavours/glitch/actions/notifications.js +++ b/app/javascript/flavours/glitch/actions/notifications.js @@ -1,4 +1,4 @@ -import api, { getLinks } from 'flavours/glitch/util/api'; +import api, { getLinks } from '../api'; import IntlMessageFormat from 'intl-messageformat'; import { fetchFollowRequests, fetchRelationships } from './accounts'; import { diff --git a/app/javascript/flavours/glitch/actions/pin_statuses.js b/app/javascript/flavours/glitch/actions/pin_statuses.js index faed73686..0926978ac 100644 --- a/app/javascript/flavours/glitch/actions/pin_statuses.js +++ b/app/javascript/flavours/glitch/actions/pin_statuses.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { importFetchedStatuses } from './importer'; export const PINNED_STATUSES_FETCH_REQUEST = 'PINNED_STATUSES_FETCH_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/polls.js b/app/javascript/flavours/glitch/actions/polls.js index ca94a095f..8e8b82df5 100644 --- a/app/javascript/flavours/glitch/actions/polls.js +++ b/app/javascript/flavours/glitch/actions/polls.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { importFetchedPoll } from './importer'; export const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/push_notifications/registerer.js b/app/javascript/flavours/glitch/actions/push_notifications/registerer.js index 8fdb239f7..a7ad57690 100644 --- a/app/javascript/flavours/glitch/actions/push_notifications/registerer.js +++ b/app/javascript/flavours/glitch/actions/push_notifications/registerer.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../../api'; import { pushNotificationsSetting } from 'flavours/glitch/util/settings'; import { setBrowserSupport, setSubscription, clearSubscription } from './setter'; diff --git a/app/javascript/flavours/glitch/actions/reports.js b/app/javascript/flavours/glitch/actions/reports.js index 333bc71f4..fbe5b3791 100644 --- a/app/javascript/flavours/glitch/actions/reports.js +++ b/app/javascript/flavours/glitch/actions/reports.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { openModal } from './modal'; export const REPORT_SUBMIT_REQUEST = 'REPORT_SUBMIT_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/search.js b/app/javascript/flavours/glitch/actions/search.js index b4aee4525..776782693 100644 --- a/app/javascript/flavours/glitch/actions/search.js +++ b/app/javascript/flavours/glitch/actions/search.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { fetchRelationships } from './accounts'; import { importFetchedAccounts, importFetchedStatuses } from './importer'; diff --git a/app/javascript/flavours/glitch/actions/server.js b/app/javascript/flavours/glitch/actions/server.js index 215dfeffa..af8fef780 100644 --- a/app/javascript/flavours/glitch/actions/server.js +++ b/app/javascript/flavours/glitch/actions/server.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { importFetchedAccount } from './importer'; export const SERVER_FETCH_REQUEST = 'Server_FETCH_REQUEST'; diff --git a/app/javascript/flavours/glitch/actions/settings.js b/app/javascript/flavours/glitch/actions/settings.js index fb0bcc09c..5634a11ef 100644 --- a/app/javascript/flavours/glitch/actions/settings.js +++ b/app/javascript/flavours/glitch/actions/settings.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { debounce } from 'lodash'; import { showAlertForError } from './alerts'; diff --git a/app/javascript/flavours/glitch/actions/statuses.js b/app/javascript/flavours/glitch/actions/statuses.js index 58c1d44a6..5930b7a16 100644 --- a/app/javascript/flavours/glitch/actions/statuses.js +++ b/app/javascript/flavours/glitch/actions/statuses.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { deleteFromTimelines } from './timelines'; import { importFetchedStatus, importFetchedStatuses } from './importer'; diff --git a/app/javascript/flavours/glitch/actions/suggestions.js b/app/javascript/flavours/glitch/actions/suggestions.js index 7070250e3..1f1116e75 100644 --- a/app/javascript/flavours/glitch/actions/suggestions.js +++ b/app/javascript/flavours/glitch/actions/suggestions.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; import { importFetchedAccounts } from './importer'; import { fetchRelationships } from './accounts'; diff --git a/app/javascript/flavours/glitch/actions/tags.js b/app/javascript/flavours/glitch/actions/tags.js index 4016cf96f..37e79d4cb 100644 --- a/app/javascript/flavours/glitch/actions/tags.js +++ b/app/javascript/flavours/glitch/actions/tags.js @@ -1,4 +1,4 @@ -import api from 'flavours/glitch/util/api'; +import api from '../api'; export const HASHTAG_FETCH_REQUEST = 'HASHTAG_FETCH_REQUEST'; export const HASHTAG_FETCH_SUCCESS = 'HASHTAG_FETCH_SUCCESS'; diff --git a/app/javascript/flavours/glitch/actions/timelines.js b/app/javascript/flavours/glitch/actions/timelines.js index 4e4adbe04..402e3ce40 100644 --- a/app/javascript/flavours/glitch/actions/timelines.js +++ b/app/javascript/flavours/glitch/actions/timelines.js @@ -1,6 +1,6 @@ import { importFetchedStatus, importFetchedStatuses } from './importer'; import { submitMarkers } from './markers'; -import api, { getLinks } from 'flavours/glitch/util/api'; +import api, { getLinks } from 'flavours/glitch/api'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; import compareId from 'flavours/glitch/util/compare_id'; import { me, usePendingItems as preferPendingItems } from 'flavours/glitch/initial_state'; diff --git a/app/javascript/flavours/glitch/actions/trends.js b/app/javascript/flavours/glitch/actions/trends.js index e9aa28dd3..edda0b5b5 100644 --- a/app/javascript/flavours/glitch/actions/trends.js +++ b/app/javascript/flavours/glitch/actions/trends.js @@ -1,4 +1,4 @@ -import api, { getLinks } from 'flavours/glitch/util/api'; +import api, { getLinks } from '../api'; import { importFetchedStatuses } from './importer'; export const TRENDS_TAGS_FETCH_REQUEST = 'TRENDS_TAGS_FETCH_REQUEST'; diff --git a/app/javascript/flavours/glitch/api.js b/app/javascript/flavours/glitch/api.js new file mode 100644 index 000000000..90d8465ef --- /dev/null +++ b/app/javascript/flavours/glitch/api.js @@ -0,0 +1,52 @@ +import axios from 'axios'; +import ready from './ready'; +import LinkHeader from 'http-link-header'; + +export const getLinks = response => { + const value = response.headers.link; + + if (!value) { + return { refs: [] }; + } + + return LinkHeader.parse(value); +}; + +const csrfHeader = {}; + +const setCSRFHeader = () => { + const csrfToken = document.querySelector('meta[name=csrf-token]'); + + if (csrfToken) { + csrfHeader['X-CSRF-Token'] = csrfToken.content; + } +}; + +ready(setCSRFHeader); + +const authorizationHeaderFromState = getState => { + const accessToken = getState && getState().getIn(['meta', 'access_token'], ''); + + if (!accessToken) { + return {}; + } + + return { + 'Authorization': `Bearer ${accessToken}`, + }; +}; + +export default getState => axios.create({ + headers: { + ...csrfHeader, + ...authorizationHeaderFromState(getState), + }, + + transformResponse: [function (data) { + try { + return JSON.parse(data); + } catch(Exception) { + return data; + } + }], +}); diff --git a/app/javascript/flavours/glitch/components/admin/Counter.js b/app/javascript/flavours/glitch/components/admin/Counter.js index a4d6cef41..5b6a19f8d 100644 --- a/app/javascript/flavours/glitch/components/admin/Counter.js +++ b/app/javascript/flavours/glitch/components/admin/Counter.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import api from 'flavours/glitch/util/api'; +import api from 'flavours/glitch/api'; import { FormattedNumber } from 'react-intl'; import { Sparklines, SparklinesCurve } from 'react-sparklines'; import classNames from 'classnames'; diff --git a/app/javascript/flavours/glitch/components/admin/Dimension.js b/app/javascript/flavours/glitch/components/admin/Dimension.js index a924d093c..c2cef4e16 100644 --- a/app/javascript/flavours/glitch/components/admin/Dimension.js +++ b/app/javascript/flavours/glitch/components/admin/Dimension.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import api from 'flavours/glitch/util/api'; +import api from 'flavours/glitch/api'; import { FormattedNumber } from 'react-intl'; import { roundTo10 } from 'flavours/glitch/util/numbers'; import Skeleton from 'flavours/glitch/components/skeleton'; diff --git a/app/javascript/flavours/glitch/components/admin/ReportReasonSelector.js b/app/javascript/flavours/glitch/components/admin/ReportReasonSelector.js index 0f2a4fe36..771dbb452 100644 --- a/app/javascript/flavours/glitch/components/admin/ReportReasonSelector.js +++ b/app/javascript/flavours/glitch/components/admin/ReportReasonSelector.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import api from 'flavours/glitch/util/api'; +import api from 'flavours/glitch/api'; import { injectIntl, defineMessages } from 'react-intl'; import classNames from 'classnames'; diff --git a/app/javascript/flavours/glitch/components/admin/Retention.js b/app/javascript/flavours/glitch/components/admin/Retention.js index 6d7e4b279..8ffc9a9be 100644 --- a/app/javascript/flavours/glitch/components/admin/Retention.js +++ b/app/javascript/flavours/glitch/components/admin/Retention.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import api from 'flavours/glitch/util/api'; +import api from 'flavours/glitch/api'; import { FormattedMessage, FormattedNumber, FormattedDate } from 'react-intl'; import classNames from 'classnames'; import { roundTo10 } from 'flavours/glitch/util/numbers'; diff --git a/app/javascript/flavours/glitch/components/admin/Trends.js b/app/javascript/flavours/glitch/components/admin/Trends.js index 60e367f00..4c17b69a0 100644 --- a/app/javascript/flavours/glitch/components/admin/Trends.js +++ b/app/javascript/flavours/glitch/components/admin/Trends.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import api from 'flavours/glitch/util/api'; +import api from 'flavours/glitch/api'; import { FormattedMessage } from 'react-intl'; import classNames from 'classnames'; import Hashtag from 'flavours/glitch/components/hashtag'; diff --git a/app/javascript/flavours/glitch/features/hashtag_timeline/containers/column_settings_container.js b/app/javascript/flavours/glitch/features/hashtag_timeline/containers/column_settings_container.js index 1cf527573..004856b04 100644 --- a/app/javascript/flavours/glitch/features/hashtag_timeline/containers/column_settings_container.js +++ b/app/javascript/flavours/glitch/features/hashtag_timeline/containers/column_settings_container.js @@ -1,7 +1,7 @@ import { connect } from 'react-redux'; import ColumnSettings from '../components/column_settings'; import { changeColumnParams } from 'flavours/glitch/actions/columns'; -import api from 'flavours/glitch/util/api'; +import api from 'flavours/glitch/api'; const mapStateToProps = (state, { columnId }) => { const columns = state.getIn(['settings', 'columns']); diff --git a/app/javascript/flavours/glitch/features/ui/components/embed_modal.js b/app/javascript/flavours/glitch/features/ui/components/embed_modal.js index b6f5e628d..624b68f7e 100644 --- a/app/javascript/flavours/glitch/features/ui/components/embed_modal.js +++ b/app/javascript/flavours/glitch/features/ui/components/embed_modal.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { defineMessages, FormattedMessage, injectIntl } from 'react-intl'; -import api from 'flavours/glitch/util/api'; +import api from 'flavours/glitch/api'; import IconButton from 'flavours/glitch/components/icon_button'; const messages = defineMessages({ diff --git a/app/javascript/flavours/glitch/util/api.js b/app/javascript/flavours/glitch/util/api.js deleted file mode 100644 index 90d8465ef..000000000 --- a/app/javascript/flavours/glitch/util/api.js +++ /dev/null @@ -1,52 +0,0 @@ -import axios from 'axios'; -import ready from './ready'; -import LinkHeader from 'http-link-header'; - -export const getLinks = response => { - const value = response.headers.link; - - if (!value) { - return { refs: [] }; - } - - return LinkHeader.parse(value); -}; - -const csrfHeader = {}; - -const setCSRFHeader = () => { - const csrfToken = document.querySelector('meta[name=csrf-token]'); - - if (csrfToken) { - csrfHeader['X-CSRF-Token'] = csrfToken.content; - } -}; - -ready(setCSRFHeader); - -const authorizationHeaderFromState = getState => { - const accessToken = getState && getState().getIn(['meta', 'access_token'], ''); - - if (!accessToken) { - return {}; - } - - return { - 'Authorization': `Bearer ${accessToken}`, - }; -}; - -export default getState => axios.create({ - headers: { - ...csrfHeader, - ...authorizationHeaderFromState(getState), - }, - - transformResponse: [function (data) { - try { - return JSON.parse(data); - } catch(Exception) { - return data; - } - }], -}); -- cgit