mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-06 20:16:57 +00:00
fix type errors in mastodon API
This commit is contained in:
parent
4ea1b6aa4d
commit
6e4e4fdc33
4 changed files with 17 additions and 17 deletions
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Entity } from 'megalodon';
|
||||
import { Entity, MastodonEntity } from 'megalodon';
|
||||
import mfm from '@transfem-org/sfm-js';
|
||||
import { MastodonNotificationType } from 'megalodon/lib/src/mastodon/notification.js';
|
||||
import { NotificationType } from 'megalodon/lib/src/notification.js';
|
||||
|
@ -275,7 +275,7 @@ export class MastodonConverters {
|
|||
this.getUser(p)
|
||||
.then(u => this.encode(u, mentionedRemoteUsers))
|
||||
.catch(() => null)))
|
||||
.then(p => p.filter(m => m)) as Promise<Entity.Mention[]>;
|
||||
.then((p: Entity.Mention[]) => p.filter(m => m));
|
||||
|
||||
const tags = note.tags.map(tag => {
|
||||
return {
|
||||
|
@ -327,7 +327,7 @@ export class MastodonConverters {
|
|||
sensitive: status.sensitive || !!cw,
|
||||
spoiler_text: cw,
|
||||
visibility: status.visibility,
|
||||
media_attachments: status.media_attachments.map(a => convertAttachment(a)),
|
||||
media_attachments: status.media_attachments.map((a: Entity.Account) => convertAttachment(a)),
|
||||
mentions: mentions,
|
||||
tags: tags,
|
||||
card: null, //FIXME
|
||||
|
@ -345,7 +345,7 @@ export class MastodonConverters {
|
|||
public async convertConversation(conversation: Entity.Conversation, me: MiLocalUser | null): Promise<MastodonEntity.Conversation> {
|
||||
return {
|
||||
id: conversation.id,
|
||||
accounts: await Promise.all(conversation.accounts.map(a => this.convertAccount(a))),
|
||||
accounts: await Promise.all(conversation.accounts.map((a: Entity.Account) => this.convertAccount(a))),
|
||||
last_status: conversation.last_status ? await this.convertStatus(conversation.last_status, me) : null,
|
||||
unread: conversation.unread,
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { MastodonEntity } from 'megalodon';
|
||||
import { parseTimelineArgs, TimelineArgs } from '@/server/api/mastodon/argsUtils.js';
|
||||
import { MastodonConverters } from '@/server/api/mastodon/MastodonConverters.js';
|
||||
import { attachMinMaxPagination } from '@/server/api/mastodon/pagination.js';
|
||||
|
|
|
@ -9,9 +9,8 @@ import { attachMinMaxPagination, attachOffsetPagination } from '@/server/api/mas
|
|||
import { MastodonConverters } from '../MastodonConverters.js';
|
||||
import { parseTimelineArgs, TimelineArgs, toBoolean, toInt } from '../argsUtils.js';
|
||||
import { ApiError } from '../../error.js';
|
||||
import Account = Entity.Account;
|
||||
import Status = Entity.Status;
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import type { Entity } from 'megalodon';
|
||||
|
||||
interface ApiSearchMastodonRoute {
|
||||
Querystring: TimelineArgs & {
|
||||
|
@ -53,8 +52,8 @@ export class ApiSearchMastodon {
|
|||
const { data } = await client.search(request.query.q, { type, ...query });
|
||||
const response = {
|
||||
...data,
|
||||
accounts: await Promise.all(data.accounts.map((account: Account) => this.mastoConverters.convertAccount(account))),
|
||||
statuses: await Promise.all(data.statuses.map((status: Status) => this.mastoConverters.convertStatus(status, me))),
|
||||
accounts: await Promise.all(data.accounts.map((account: Entity.Account) => this.mastoConverters.convertAccount(account))),
|
||||
statuses: await Promise.all(data.statuses.map((status: Entity.Status) => this.mastoConverters.convertStatus(status, me))),
|
||||
};
|
||||
|
||||
if (type === 'hashtags') {
|
||||
|
@ -90,8 +89,8 @@ export class ApiSearchMastodon {
|
|||
const stat = !type || type === 'statuses' ? await client.search(request.query.q, { type: 'statuses', ...query }) : null;
|
||||
const tags = !type || type === 'hashtags' ? await client.search(request.query.q, { type: 'hashtags', ...query }) : null;
|
||||
const response = {
|
||||
accounts: await Promise.all(acct?.data.accounts.map((account: Account) => this.mastoConverters.convertAccount(account)) ?? []),
|
||||
statuses: await Promise.all(stat?.data.statuses.map((status: Status) => this.mastoConverters.convertStatus(status, me)) ?? []),
|
||||
accounts: await Promise.all(acct?.data.accounts.map((account: Entity.Account) => this.mastoConverters.convertAccount(account)) ?? []),
|
||||
statuses: await Promise.all(stat?.data.statuses.map((status: Entity.Status) => this.mastoConverters.convertStatus(status, me)) ?? []),
|
||||
hashtags: tags?.data.hashtags ?? [],
|
||||
};
|
||||
|
||||
|
@ -113,7 +112,7 @@ export class ApiSearchMastodon {
|
|||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...request.headers as HeadersInit,
|
||||
...request.headers,
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
|
@ -122,7 +121,7 @@ export class ApiSearchMastodon {
|
|||
|
||||
await verifyResponse(res);
|
||||
|
||||
const data = await res.json() as Status[];
|
||||
const data = await res.json() as Entity.Status[];
|
||||
const me = await this.clientService.getAuth(request);
|
||||
const response = await Promise.all(data.map(status => this.mastoConverters.convertStatus(status, me)));
|
||||
|
||||
|
@ -136,7 +135,7 @@ export class ApiSearchMastodon {
|
|||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...request.headers as HeadersInit,
|
||||
...request.headers,
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
|
@ -150,7 +149,7 @@ export class ApiSearchMastodon {
|
|||
|
||||
await verifyResponse(res);
|
||||
|
||||
const data = await res.json() as Account[];
|
||||
const data = await res.json() as Entity.Account[];
|
||||
const response = await Promise.all(data.map(async entry => {
|
||||
return {
|
||||
source: 'global',
|
||||
|
|
|
@ -55,8 +55,8 @@ export class ApiStatusMastodon {
|
|||
|
||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||
const { data } = await client.getStatusContext(_request.params.id, parseTimelineArgs(_request.query));
|
||||
const ancestors = await Promise.all(data.ancestors.map(async status => await this.mastoConverters.convertStatus(status, me)));
|
||||
const descendants = await Promise.all(data.descendants.map(async status => await this.mastoConverters.convertStatus(status, me)));
|
||||
const ancestors = await Promise.all(data.ancestors.map(async (status: Entity.Status) => await this.mastoConverters.convertStatus(status, me)));
|
||||
const descendants = await Promise.all(data.descendants.map(async (status: Entity.Status) => await this.mastoConverters.convertStatus(status, me)));
|
||||
const response = { ancestors, descendants };
|
||||
|
||||
reply.send(response);
|
||||
|
@ -166,7 +166,7 @@ export class ApiStatusMastodon {
|
|||
if (body.in_reply_to_id && removed === '/unreact') {
|
||||
const id = body.in_reply_to_id;
|
||||
const post = await client.getStatus(id);
|
||||
const react = post.data.emoji_reactions.filter(e => e.me)[0].name;
|
||||
const react = post.data.emoji_reactions.filter((e: Entity.Emoji) => e.me)[0].name;
|
||||
const data = await client.deleteEmojiReaction(id, react);
|
||||
reply.send(data.data);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue