fix: use access token for all Mastodon routes (#14634)
* fix: use access token for all Mastodon routes * fix: only send access token to MASTODON_API_HOST
This commit is contained in:
parent
6b7b95d1b3
commit
30657490ec
|
|
@ -11,7 +11,7 @@ export default async (ctx) => {
|
|||
|
||||
const url = `http://${site}/api/v1/timelines/public?local=true&only_media=${only_media}`;
|
||||
|
||||
const response = await got.get(url);
|
||||
const response = await got.get(url, { headers: utils.apiHeaders() });
|
||||
const list = response.data;
|
||||
|
||||
ctx.set('data', {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export default async (ctx) => {
|
|||
|
||||
const url = `http://${site}/api/v1/timelines/public?remote=true&only_media=${only_media}`;
|
||||
|
||||
const response = await got.get(url);
|
||||
const response = await got.get(url, { headers: utils.apiHeaders() });
|
||||
const list = response.data;
|
||||
|
||||
ctx.set('data', {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,12 @@ import { config } from '@/config';
|
|||
|
||||
const allowSiteList = ['mastodon.social', 'pawoo.net'];
|
||||
|
||||
const apiHeaders = (site) => {
|
||||
const { accessToken, apiHost } = config.mastodon;
|
||||
// avoid sending API token to other sites
|
||||
return accessToken && site === apiHost ? { Authorization: `Bearer ${accessToken}` } : {};
|
||||
};
|
||||
|
||||
const mediaParse = (media_attachments) =>
|
||||
media_attachments
|
||||
.map((item) => {
|
||||
|
|
@ -59,6 +65,7 @@ async function getAccountStatuses(site, account_id, only_media) {
|
|||
const statuses_response = await got({
|
||||
method: 'get',
|
||||
url: statuses_url,
|
||||
headers: apiHeaders(site),
|
||||
});
|
||||
const data = statuses_response.data;
|
||||
|
||||
|
|
@ -70,6 +77,7 @@ async function getAccountStatuses(site, account_id, only_media) {
|
|||
const account_response = await got({
|
||||
method: 'get',
|
||||
url: account_url,
|
||||
headers: apiHeaders(site),
|
||||
});
|
||||
account_data = account_response.data;
|
||||
}
|
||||
|
|
@ -95,9 +103,7 @@ async function getAccountIdByAcct(acct) {
|
|||
const search_response = await got({
|
||||
method: 'get',
|
||||
url: search_url,
|
||||
headers: {
|
||||
...(mastodonConfig.accessToken ? { Authorization: `Bearer ${mastodonConfig.accessToken}` } : {}),
|
||||
},
|
||||
headers: apiHeaders(site),
|
||||
searchParams: {
|
||||
q: acct,
|
||||
type: 'accounts',
|
||||
|
|
@ -123,6 +129,7 @@ async function getAccountIdByAcct(acct) {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
apiHeaders,
|
||||
parseStatuses,
|
||||
getAccountStatuses,
|
||||
getAccountIdByAcct,
|
||||
|
|
|
|||
Loading…
Reference in New Issue