improve mastodon note conversion and use access checks in more places (resolves #509)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { MiLocalUser } from '@/models/User.js';
|
||||
import { MastoConverters } from '../converters.js';
|
||||
import { parseTimelineArgs, TimelineArgs } from '../timelineArgs.js';
|
||||
import Account = Entity.Account;
|
||||
@@ -21,8 +22,9 @@ export class ApiSearchMastodon {
|
||||
constructor(
|
||||
private readonly request: FastifyRequest<ApiSearchMastodonRoute>,
|
||||
private readonly client: MegalodonInterface,
|
||||
private readonly me: MiLocalUser | null,
|
||||
private readonly BASE_URL: string,
|
||||
private readonly mastoConverter: MastoConverters,
|
||||
private readonly mastoConverters: MastoConverters,
|
||||
) {}
|
||||
|
||||
public async SearchV1() {
|
||||
@@ -40,8 +42,8 @@ export class ApiSearchMastodon {
|
||||
const stat = !type || type === 'statuses' ? await this.client.search(this.request.query.q, { type: 'statuses', ...query }) : null;
|
||||
const tags = !type || type === 'hashtags' ? await this.client.search(this.request.query.q, { type: 'hashtags', ...query }) : null;
|
||||
return {
|
||||
accounts: await Promise.all(acct?.data.accounts.map(async (account: Account) => await this.mastoConverter.convertAccount(account)) ?? []),
|
||||
statuses: await Promise.all(stat?.data.statuses.map(async (status: Status) => await this.mastoConverter.convertStatus(status)) ?? []),
|
||||
accounts: await Promise.all(acct?.data.accounts.map(async (account: Account) => await this.mastoConverters.convertAccount(account)) ?? []),
|
||||
statuses: await Promise.all(stat?.data.statuses.map(async (status: Status) => await this.mastoConverters.convertStatus(status, this.me)) ?? []),
|
||||
hashtags: tags?.data.hashtags ?? [],
|
||||
};
|
||||
}
|
||||
@@ -54,10 +56,12 @@ export class ApiSearchMastodon {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: '{}',
|
||||
body: JSON.stringify({
|
||||
i: this.request.headers.authorization?.replace('Bearer ', ''),
|
||||
}),
|
||||
})
|
||||
.then(res => res.json() as Promise<Status[]>)
|
||||
.then(data => data.map(status => this.mastoConverter.convertStatus(status)));
|
||||
.then(data => data.map(status => this.mastoConverters.convertStatus(status, this.me)));
|
||||
return Promise.all(data);
|
||||
}
|
||||
|
||||
@@ -83,7 +87,7 @@ export class ApiSearchMastodon {
|
||||
account: entry,
|
||||
}))));
|
||||
return Promise.all(data.map(async suggestion => {
|
||||
suggestion.account = await this.mastoConverter.convertAccount(suggestion.account);
|
||||
suggestion.account = await this.mastoConverters.convertAccount(suggestion.account);
|
||||
return suggestion;
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user