mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-14 05:57:32 -07:00
[mastodon-client] Refactor object id converters
This commit is contained in:
parent
f0cedf4f39
commit
f5e28fc27a
11 changed files with 120 additions and 125 deletions
|
@ -1,74 +1,69 @@
|
||||||
import { Entity } from "megalodon";
|
|
||||||
import { convertId, IdType } from "../index.js";
|
import { convertId, IdType } from "../index.js";
|
||||||
|
|
||||||
function simpleConvert(data: any) {
|
function simpleConvertId(data: any) {
|
||||||
// copy the object to bypass weird pass by reference bugs
|
// copy the object to bypass weird pass by reference bugs
|
||||||
const result = Object.assign({}, data);
|
const result = Object.assign({}, data);
|
||||||
result.id = convertId(data.id, IdType.MastodonId);
|
result.id = convertId(data.id, IdType.MastodonId);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertAccount(account: Entity.Account | MastodonEntity.MutedAccount) {
|
export function convertAccountId(account: MastodonEntity.Account | MastodonEntity.MutedAccount) {
|
||||||
return simpleConvert(account);
|
return simpleConvertId(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertAnnouncement(announcement: Entity.Announcement) {
|
export function convertAnnouncementId(announcement: MastodonEntity.Announcement) {
|
||||||
return simpleConvert(announcement);
|
return simpleConvertId(announcement);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertAttachment(attachment: Entity.Attachment) {
|
export function convertAttachmentId(attachment: MastodonEntity.Attachment) {
|
||||||
return simpleConvert(attachment);
|
return simpleConvertId(attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertFilter(filter: Entity.Filter) {
|
export function convertFilterId(filter: MastodonEntity.Filter) {
|
||||||
return simpleConvert(filter);
|
return simpleConvertId(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertList(list: MastodonEntity.List) {
|
export function convertListId(list: MastodonEntity.List) {
|
||||||
return simpleConvert(list);
|
return simpleConvertId(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertFeaturedTag(tag: Entity.FeaturedTag) {
|
export function convertNotificationIds(notification: MastodonEntity.Notification) {
|
||||||
return simpleConvert(tag);
|
notification.account = convertAccountId(notification.account);
|
||||||
}
|
|
||||||
|
|
||||||
export function convertNotification(notification: MastodonEntity.Notification) {
|
|
||||||
notification.account = convertAccount(notification.account);
|
|
||||||
notification.id = convertId(notification.id, IdType.MastodonId);
|
notification.id = convertId(notification.id, IdType.MastodonId);
|
||||||
if (notification.status)
|
if (notification.status)
|
||||||
notification.status = convertStatus(notification.status);
|
notification.status = convertStatusIds(notification.status);
|
||||||
if (notification.reaction)
|
if (notification.reaction)
|
||||||
notification.reaction = convertReaction(notification.reaction);
|
notification.reaction = convertReactionIds(notification.reaction);
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertPoll(poll: Entity.Poll) {
|
export function convertPollId(poll: MastodonEntity.Poll) {
|
||||||
return simpleConvert(poll);
|
return simpleConvertId(poll);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertReaction(reaction: MastodonEntity.Reaction) {
|
export function convertReactionIds(reaction: MastodonEntity.Reaction) {
|
||||||
if (reaction.accounts) {
|
if (reaction.accounts) {
|
||||||
reaction.accounts = reaction.accounts.map(convertAccount);
|
reaction.accounts = reaction.accounts.map(convertAccountId);
|
||||||
}
|
}
|
||||||
return reaction;
|
return reaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertRelationship(relationship: Entity.Relationship) {
|
export function convertRelationshipId(relationship: MastodonEntity.Relationship) {
|
||||||
return simpleConvert(relationship);
|
return simpleConvertId(relationship);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertSearch(search: MastodonEntity.Search) {
|
export function convertSearchIds(search: MastodonEntity.Search) {
|
||||||
search.accounts = search.accounts.map(p => convertAccount(p));
|
search.accounts = search.accounts.map(p => convertAccountId(p));
|
||||||
search.statuses = search.statuses.map(p => convertStatus(p));
|
search.statuses = search.statuses.map(p => convertStatusIds(p));
|
||||||
return search;
|
return search;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertStatusSource(statusSource: MastodonEntity.StatusSource) {
|
export function convertStatusSourceId(statusSource: MastodonEntity.StatusSource) {
|
||||||
return simpleConvert(statusSource);
|
return simpleConvertId(statusSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertStatus(status: MastodonEntity.Status) {
|
export function convertStatusIds(status: MastodonEntity.Status) {
|
||||||
status.account = convertAccount(status.account);
|
status.account = convertAccountId(status.account);
|
||||||
status.id = convertId(status.id, IdType.MastodonId);
|
status.id = convertId(status.id, IdType.MastodonId);
|
||||||
if (status.in_reply_to_account_id)
|
if (status.in_reply_to_account_id)
|
||||||
status.in_reply_to_account_id = convertId(
|
status.in_reply_to_account_id = convertId(
|
||||||
|
@ -78,34 +73,34 @@ export function convertStatus(status: MastodonEntity.Status) {
|
||||||
if (status.in_reply_to_id)
|
if (status.in_reply_to_id)
|
||||||
status.in_reply_to_id = convertId(status.in_reply_to_id, IdType.MastodonId);
|
status.in_reply_to_id = convertId(status.in_reply_to_id, IdType.MastodonId);
|
||||||
status.media_attachments = status.media_attachments.map((attachment) =>
|
status.media_attachments = status.media_attachments.map((attachment) =>
|
||||||
convertAttachment(attachment),
|
convertAttachmentId(attachment),
|
||||||
);
|
);
|
||||||
status.mentions = status.mentions.map((mention) => ({
|
status.mentions = status.mentions.map((mention) => ({
|
||||||
...mention,
|
...mention,
|
||||||
id: convertId(mention.id, IdType.MastodonId),
|
id: convertId(mention.id, IdType.MastodonId),
|
||||||
}));
|
}));
|
||||||
if (status.poll) status.poll = convertPoll(status.poll);
|
if (status.poll) status.poll = convertPollId(status.poll);
|
||||||
if (status.reblog) status.reblog = convertStatus(status.reblog);
|
if (status.reblog) status.reblog = convertStatusIds(status.reblog);
|
||||||
if (status.quote) status.quote = convertStatus(status.quote);
|
if (status.quote) status.quote = convertStatusIds(status.quote);
|
||||||
status.reactions = status.reactions.map(convertReaction);
|
status.reactions = status.reactions.map(convertReactionIds);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertStatusEdit(edit: MastodonEntity.StatusEdit) {
|
export function convertStatusEditIds(edit: MastodonEntity.StatusEdit) {
|
||||||
edit.account = convertAccount(edit.account);
|
edit.account = convertAccountId(edit.account);
|
||||||
edit.media_attachments = edit.media_attachments.map((attachment) =>
|
edit.media_attachments = edit.media_attachments.map((attachment) =>
|
||||||
convertAttachment(attachment),
|
convertAttachmentId(attachment),
|
||||||
);
|
);
|
||||||
if (edit.poll) edit.poll = convertPoll(edit.poll);
|
if (edit.poll) edit.poll = convertPollId(edit.poll);
|
||||||
return edit;
|
return edit;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertConversation(conversation: MastodonEntity.Conversation) {
|
export function convertConversationIds(conversation: MastodonEntity.Conversation) {
|
||||||
conversation.id = convertId(conversation.id, IdType.MastodonId);
|
conversation.id = convertId(conversation.id, IdType.MastodonId);
|
||||||
conversation.accounts = conversation.accounts.map(convertAccount);
|
conversation.accounts = conversation.accounts.map(convertAccountId);
|
||||||
if (conversation.last_status) {
|
if (conversation.last_status) {
|
||||||
conversation.last_status = convertStatus(conversation.last_status);
|
conversation.last_status = convertStatusIds(conversation.last_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
return conversation;
|
return conversation;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import { argsToBools, convertPaginationArgsIds, limitToInt, normalizeUrlQuery } from "./timeline.js";
|
import { argsToBools, convertPaginationArgsIds, limitToInt, normalizeUrlQuery } from "./timeline.js";
|
||||||
import { convertId, IdType } from "../../index.js";
|
import { convertId, IdType } from "../../index.js";
|
||||||
import { convertAccount, convertList, convertRelationship, convertStatus, } from "../converters.js";
|
import { convertAccountId, convertListId, convertRelationshipId, convertStatusIds, } from "../converters.js";
|
||||||
import { getUser } from "@/server/api/common/getters.js";
|
import { getUser } from "@/server/api/common/getters.js";
|
||||||
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
||||||
import authenticate from "@/server/api/authenticate.js";
|
import authenticate from "@/server/api/authenticate.js";
|
||||||
|
@ -22,7 +22,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
const acct = await UserHelpers.verifyCredentials(user);
|
const acct = await UserHelpers.verifyCredentials(user);
|
||||||
ctx.body = convertAccount(acct);
|
ctx.body = convertAccountId(acct);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -41,7 +41,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
const acct = await UserHelpers.updateCredentials(user, (ctx.request as any).body as any);
|
const acct = await UserHelpers.updateCredentials(user, (ctx.request as any).body as any);
|
||||||
ctx.body = convertAccount(acct)
|
ctx.body = convertAccountId(acct)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -58,7 +58,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const account = await UserConverter.encode(user);
|
const account = await UserConverter.encode(user);
|
||||||
ctx.body = convertAccount(account);
|
ctx.body = convertAccountId(account);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -79,7 +79,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const ids = (normalizeUrlQuery(ctx.query, ['id[]'])['id[]'] ?? [])
|
const ids = (normalizeUrlQuery(ctx.query, ['id[]'])['id[]'] ?? [])
|
||||||
.map((id: string) => convertId(id, IdType.IceshrimpId));
|
.map((id: string) => convertId(id, IdType.IceshrimpId));
|
||||||
const result = await UserHelpers.getUserRelationhipToMany(ids, user.id);
|
const result = await UserHelpers.getUserRelationhipToMany(ids, user.id);
|
||||||
ctx.body = result.map(rel => convertRelationship(rel));
|
ctx.body = result.map(rel => convertRelationshipId(rel));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -91,7 +91,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
try {
|
try {
|
||||||
const userId = convertId(ctx.params.id, IdType.IceshrimpId);
|
const userId = convertId(ctx.params.id, IdType.IceshrimpId);
|
||||||
const account = await UserConverter.encode(await getUser(userId));
|
const account = await UserConverter.encode(await getUser(userId));
|
||||||
ctx.body = convertAccount(account);
|
ctx.body = convertAccountId(account);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -113,7 +113,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const tl = await UserHelpers.getUserStatuses(query, user, args.max_id, args.since_id, args.min_id, args.limit, args['only_media'], args['exclude_replies'], args['exclude_reblogs'], args.pinned, args.tagged)
|
const tl = await UserHelpers.getUserStatuses(query, user, args.max_id, args.since_id, args.min_id, args.limit, args['only_media'], args['exclude_replies'], args['exclude_reblogs'], args.pinned, args.tagged)
|
||||||
.then(n => NoteConverter.encodeMany(n, user, cache));
|
.then(n => NoteConverter.encodeMany(n, user, cache));
|
||||||
|
|
||||||
ctx.body = tl.map(s => convertStatus(s));
|
ctx.body = tl.map(s => convertStatusIds(s));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -148,7 +148,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const res = await UserHelpers.getUserFollowers(query, user, args.max_id, args.since_id, args.min_id, args.limit);
|
const res = await UserHelpers.getUserFollowers(query, user, args.max_id, args.since_id, args.min_id, args.limit);
|
||||||
const followers = await UserConverter.encodeMany(res.data, cache);
|
const followers = await UserConverter.encodeMany(res.data, cache);
|
||||||
|
|
||||||
ctx.body = followers.map((account) => convertAccount(account));
|
ctx.body = followers.map((account) => convertAccountId(account));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -173,7 +173,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const res = await UserHelpers.getUserFollowing(query, user, args.max_id, args.since_id, args.min_id, args.limit);
|
const res = await UserHelpers.getUserFollowing(query, user, args.max_id, args.since_id, args.min_id, args.limit);
|
||||||
const following = await UserConverter.encodeMany(res.data, cache);
|
const following = await UserConverter.encodeMany(res.data, cache);
|
||||||
|
|
||||||
ctx.body = following.map((account) => convertAccount(account));
|
ctx.body = following.map((account) => convertAccountId(account));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -197,7 +197,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
|
|
||||||
const member = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
const member = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
||||||
const results = await ListHelpers.getListsByMember(user, member);
|
const results = await ListHelpers.getListsByMember(user, member);
|
||||||
ctx.body = results.map(p => convertList(p));
|
ctx.body = results.map(p => convertListId(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
ctx.status = 400;
|
ctx.status = 400;
|
||||||
ctx.body = { error: e.message };
|
ctx.body = { error: e.message };
|
||||||
|
@ -219,7 +219,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
||||||
//FIXME: Parse form data
|
//FIXME: Parse form data
|
||||||
const result = await UserHelpers.followUser(target, user, true, false);
|
const result = await UserHelpers.followUser(target, user, true, false);
|
||||||
ctx.body = convertRelationship(result);
|
ctx.body = convertRelationshipId(result);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -242,7 +242,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
|
|
||||||
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
||||||
const result = await UserHelpers.unfollowUser(target, user);
|
const result = await UserHelpers.unfollowUser(target, user);
|
||||||
ctx.body = convertRelationship(result);
|
ctx.body = convertRelationshipId(result);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -265,7 +265,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
|
|
||||||
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
||||||
const result = await UserHelpers.blockUser(target, user);
|
const result = await UserHelpers.blockUser(target, user);
|
||||||
ctx.body = convertRelationship(result);
|
ctx.body = convertRelationshipId(result);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -288,7 +288,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
|
|
||||||
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
||||||
const result = await UserHelpers.unblockUser(target, user);
|
const result = await UserHelpers.unblockUser(target, user);
|
||||||
ctx.body = convertRelationship(result)
|
ctx.body = convertRelationshipId(result)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -313,7 +313,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const args = normalizeUrlQuery(argsToBools(limitToInt(ctx.query, ['duration']), ['notifications']));
|
const args = normalizeUrlQuery(argsToBools(limitToInt(ctx.query, ['duration']), ['notifications']));
|
||||||
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
||||||
const result = await UserHelpers.muteUser(target, user, args.notifications, args.duration);
|
const result = await UserHelpers.muteUser(target, user, args.notifications, args.duration);
|
||||||
ctx.body = convertRelationship(result)
|
ctx.body = convertRelationshipId(result)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -336,7 +336,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
|
|
||||||
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
||||||
const result = await UserHelpers.unmuteUser(target, user);
|
const result = await UserHelpers.unmuteUser(target, user);
|
||||||
ctx.body = convertRelationship(result)
|
ctx.body = convertRelationshipId(result)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -376,7 +376,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const res = await UserHelpers.getUserBookmarks(user, args.max_id, args.since_id, args.min_id, args.limit);
|
const res = await UserHelpers.getUserBookmarks(user, args.max_id, args.since_id, args.min_id, args.limit);
|
||||||
const bookmarks = await NoteConverter.encodeMany(res.data, user, cache);
|
const bookmarks = await NoteConverter.encodeMany(res.data, user, cache);
|
||||||
|
|
||||||
ctx.body = bookmarks.map(s => convertStatus(s));
|
ctx.body = bookmarks.map(s => convertStatusIds(s));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 20);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 20);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -400,7 +400,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const res = await UserHelpers.getUserFavorites(user, args.max_id, args.since_id, args.min_id, args.limit);
|
const res = await UserHelpers.getUserFavorites(user, args.max_id, args.since_id, args.min_id, args.limit);
|
||||||
const favorites = await NoteConverter.encodeMany(res.data, user, cache);
|
const favorites = await NoteConverter.encodeMany(res.data, user, cache);
|
||||||
|
|
||||||
ctx.body = favorites.map(s => convertStatus(s));
|
ctx.body = favorites.map(s => convertStatusIds(s));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 20);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 20);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -422,7 +422,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const cache = UserHelpers.getFreshAccountCache();
|
const cache = UserHelpers.getFreshAccountCache();
|
||||||
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
|
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
|
||||||
const res = await UserHelpers.getUserMutes(user, args.max_id, args.since_id, args.min_id, args.limit, cache);
|
const res = await UserHelpers.getUserMutes(user, args.max_id, args.since_id, args.min_id, args.limit, cache);
|
||||||
ctx.body = res.data.map(m => convertAccount(m));
|
ctx.body = res.data.map(m => convertAccountId(m));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -445,7 +445,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
|
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
|
||||||
const res = await UserHelpers.getUserBlocks(user, args.max_id, args.since_id, args.min_id, args.limit);
|
const res = await UserHelpers.getUserBlocks(user, args.max_id, args.since_id, args.min_id, args.limit);
|
||||||
const blocks = await UserConverter.encodeMany(res.data, cache);
|
const blocks = await UserConverter.encodeMany(res.data, cache);
|
||||||
ctx.body = blocks.map(b => convertAccount(b));
|
ctx.body = blocks.map(b => convertAccountId(b));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -468,7 +468,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
|
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
|
||||||
const res = await UserHelpers.getUserFollowRequests(user, args.max_id, args.since_id, args.min_id, args.limit);
|
const res = await UserHelpers.getUserFollowRequests(user, args.max_id, args.since_id, args.min_id, args.limit);
|
||||||
const requests = await UserConverter.encodeMany(res.data, cache);
|
const requests = await UserConverter.encodeMany(res.data, cache);
|
||||||
ctx.body = requests.map(b => convertAccount(b));
|
ctx.body = requests.map(b => convertAccountId(b));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -491,7 +491,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
|
|
||||||
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
||||||
const result = await UserHelpers.acceptFollowRequest(target, user);
|
const result = await UserHelpers.acceptFollowRequest(target, user);
|
||||||
ctx.body = convertRelationship(result);
|
ctx.body = convertRelationshipId(result);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -514,7 +514,7 @@ export function setupEndpointsAccount(router: Router): void {
|
||||||
|
|
||||||
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
const target = await UserHelpers.getUserCached(convertId(ctx.params.id, IdType.IceshrimpId));
|
||||||
const result = await UserHelpers.rejectFollowRequest(target, user);
|
const result = await UserHelpers.rejectFollowRequest(target, user);
|
||||||
ctx.body = convertRelationship(result);
|
ctx.body = convertRelationshipId(result);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import { getClient } from "../index.js";
|
import { getClient } from "../index.js";
|
||||||
import { convertId, IdType } from "../../index.js";
|
import { convertId, IdType } from "../../index.js";
|
||||||
import { convertFilter } from "../converters.js";
|
import { convertFilterId } from "../converters.js";
|
||||||
|
|
||||||
export function setupEndpointsFilter(router: Router): void {
|
export function setupEndpointsFilter(router: Router): void {
|
||||||
router.get("/v1/filters", async (ctx) => {
|
router.get("/v1/filters", async (ctx) => {
|
||||||
|
@ -11,7 +11,7 @@ export function setupEndpointsFilter(router: Router): void {
|
||||||
const body: any = ctx.request.body;
|
const body: any = ctx.request.body;
|
||||||
try {
|
try {
|
||||||
const data = await client.getFilters();
|
const data = await client.getFilters();
|
||||||
ctx.body = data.data.map((filter) => convertFilter(filter));
|
ctx.body = data.data.map((filter) => convertFilterId(filter));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -28,7 +28,7 @@ export function setupEndpointsFilter(router: Router): void {
|
||||||
const data = await client.getFilter(
|
const data = await client.getFilter(
|
||||||
convertId(ctx.params.id, IdType.IceshrimpId),
|
convertId(ctx.params.id, IdType.IceshrimpId),
|
||||||
);
|
);
|
||||||
ctx.body = convertFilter(data.data);
|
ctx.body = convertFilterId(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -43,7 +43,7 @@ export function setupEndpointsFilter(router: Router): void {
|
||||||
const body: any = ctx.request.body;
|
const body: any = ctx.request.body;
|
||||||
try {
|
try {
|
||||||
const data = await client.createFilter(body.phrase, body.context, body);
|
const data = await client.createFilter(body.phrase, body.context, body);
|
||||||
ctx.body = convertFilter(data.data);
|
ctx.body = convertFilterId(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -62,7 +62,7 @@ export function setupEndpointsFilter(router: Router): void {
|
||||||
body.phrase,
|
body.phrase,
|
||||||
body.context,
|
body.context,
|
||||||
);
|
);
|
||||||
ctx.body = convertFilter(data.data);
|
ctx.body = convertFilterId(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import { convertAccount, convertList, } from "../converters.js";
|
import { convertAccountId, convertListId, } from "../converters.js";
|
||||||
import { convertId, IdType } from "../../index.js";
|
import { convertId, IdType } from "../../index.js";
|
||||||
import authenticate from "@/server/api/authenticate.js";
|
import authenticate from "@/server/api/authenticate.js";
|
||||||
import { convertPaginationArgsIds, limitToInt, normalizeUrlQuery } from "@/server/api/mastodon/endpoints/timeline.js";
|
import { convertPaginationArgsIds, limitToInt, normalizeUrlQuery } from "@/server/api/mastodon/endpoints/timeline.js";
|
||||||
|
@ -23,7 +23,7 @@ export function setupEndpointsList(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.body = await ListHelpers.getLists(user)
|
ctx.body = await ListHelpers.getLists(user)
|
||||||
.then(p => p.map(list => convertList(list)));
|
.then(p => p.map(list => convertListId(list)));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -46,7 +46,7 @@ export function setupEndpointsList(router: Router): void {
|
||||||
const id = convertId(ctx.params.id, IdType.IceshrimpId);
|
const id = convertId(ctx.params.id, IdType.IceshrimpId);
|
||||||
|
|
||||||
ctx.body = await ListHelpers.getList(user, id)
|
ctx.body = await ListHelpers.getList(user, id)
|
||||||
.then(p => convertList(p));
|
.then(p => convertListId(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ export function setupEndpointsList(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.body = await ListHelpers.createList(user, title)
|
ctx.body = await ListHelpers.createList(user, title)
|
||||||
.then(p => convertList(p));
|
.then(p => convertListId(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
ctx.status = 400;
|
ctx.status = 400;
|
||||||
ctx.body = { error: e.message };
|
ctx.body = { error: e.message };
|
||||||
|
@ -106,7 +106,7 @@ export function setupEndpointsList(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.body = await ListHelpers.updateList(user, list, title)
|
ctx.body = await ListHelpers.updateList(user, list, title)
|
||||||
.then(p => convertList(p));
|
.then(p => convertListId(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -159,7 +159,7 @@ export function setupEndpointsList(router: Router): void {
|
||||||
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query)));
|
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query)));
|
||||||
const res = await ListHelpers.getListUsers(user, id, args.max_id, args.since_id, args.min_id, args.limit);
|
const res = await ListHelpers.getListUsers(user, id, args.max_id, args.since_id, args.min_id, args.limit);
|
||||||
const accounts = await UserConverter.encodeMany(res.data);
|
const accounts = await UserConverter.encodeMany(res.data);
|
||||||
ctx.body = accounts.map(account => convertAccount(account));
|
ctx.body = accounts.map(account => convertAccountId(account));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import { convertId, IdType } from "@/misc/convert-id.js";
|
import { convertId, IdType } from "@/misc/convert-id.js";
|
||||||
import { convertAttachment } from "@/server/api/mastodon/converters.js";
|
import { convertAttachmentId } from "@/server/api/mastodon/converters.js";
|
||||||
import multer from "@koa/multer";
|
import multer from "@koa/multer";
|
||||||
import authenticate from "@/server/api/authenticate.js";
|
import authenticate from "@/server/api/authenticate.js";
|
||||||
import { MediaHelpers } from "@/server/api/mastodon/helpers/media.js";
|
import { MediaHelpers } from "@/server/api/mastodon/helpers/media.js";
|
||||||
|
@ -27,7 +27,7 @@ export function setupEndpointsMedia(router: Router, fileRouter: Router, upload:
|
||||||
}
|
}
|
||||||
|
|
||||||
const attachment = FileConverter.encode(file);
|
const attachment = FileConverter.encode(file);
|
||||||
ctx.body = convertAttachment(attachment);
|
ctx.body = convertAttachmentId(attachment);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 500;
|
ctx.status = 500;
|
||||||
|
@ -55,7 +55,7 @@ export function setupEndpointsMedia(router: Router, fileRouter: Router, upload:
|
||||||
|
|
||||||
const result = await MediaHelpers.updateMedia(user, file, ctx.request.body)
|
const result = await MediaHelpers.updateMedia(user, file, ctx.request.body)
|
||||||
.then(p => FileConverter.encode(p));
|
.then(p => FileConverter.encode(p));
|
||||||
ctx.body = convertAttachment(result);
|
ctx.body = convertAttachmentId(result);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -81,7 +81,7 @@ export function setupEndpointsMedia(router: Router, fileRouter: Router, upload:
|
||||||
}
|
}
|
||||||
const result = await MediaHelpers.uploadMedia(user, file, ctx.request.body)
|
const result = await MediaHelpers.uploadMedia(user, file, ctx.request.body)
|
||||||
.then(p => FileConverter.encode(p));
|
.then(p => FileConverter.encode(p));
|
||||||
ctx.body = convertAttachment(result);
|
ctx.body = convertAttachmentId(result);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 500;
|
ctx.status = 500;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import { getClient } from "@/server/api/mastodon/index.js";
|
import { getClient } from "@/server/api/mastodon/index.js";
|
||||||
import { convertId, IdType } from "@/misc/convert-id.js";
|
import { convertId, IdType } from "@/misc/convert-id.js";
|
||||||
import { convertAccount, convertAnnouncement, convertFilter } from "@/server/api/mastodon/converters.js";
|
import { convertAccountId, convertAnnouncementId, convertFilterId } from "@/server/api/mastodon/converters.js";
|
||||||
import { Users } from "@/models/index.js";
|
import { Users } from "@/models/index.js";
|
||||||
import { getInstance } from "@/server/api/mastodon/endpoints/meta.js";
|
import { getInstance } from "@/server/api/mastodon/endpoints/meta.js";
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
|
@ -39,7 +39,7 @@ export function setupEndpointsMisc(router: Router): void {
|
||||||
try {
|
try {
|
||||||
const data = await client.getInstanceAnnouncements();
|
const data = await client.getInstanceAnnouncements();
|
||||||
ctx.body = data.data.map((announcement) =>
|
ctx.body = data.data.map((announcement) =>
|
||||||
convertAnnouncement(announcement),
|
convertAnnouncementId(announcement),
|
||||||
);
|
);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -74,7 +74,7 @@ export function setupEndpointsMisc(router: Router): void {
|
||||||
// displayed without being logged in
|
// displayed without being logged in
|
||||||
try {
|
try {
|
||||||
const data = await client.getFilters();
|
const data = await client.getFilters();
|
||||||
ctx.body = data.data.map((filter) => convertFilter(filter));
|
ctx.body = data.data.map((filter) => convertFilterId(filter));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import { convertId, IdType } from "../../index.js";
|
import { convertId, IdType } from "../../index.js";
|
||||||
import { convertPaginationArgsIds, limitToInt, normalizeUrlQuery } from "./timeline.js";
|
import { convertPaginationArgsIds, limitToInt, normalizeUrlQuery } from "./timeline.js";
|
||||||
import { convertConversation, convertNotification } from "../converters.js";
|
import { convertConversationIds, convertNotificationIds } from "../converters.js";
|
||||||
import authenticate from "@/server/api/authenticate.js";
|
import authenticate from "@/server/api/authenticate.js";
|
||||||
import { UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
import { UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
||||||
import { NotificationHelpers } from "@/server/api/mastodon/helpers/notification.js";
|
import { NotificationHelpers } from "@/server/api/mastodon/helpers/notification.js";
|
||||||
|
@ -24,7 +24,7 @@ export function setupEndpointsNotifications(router: Router): void {
|
||||||
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query)), ['types[]', 'exclude_types[]']);
|
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query)), ['types[]', 'exclude_types[]']);
|
||||||
const data = NotificationHelpers.getNotifications(user, args.max_id, args.since_id, args.min_id, args.limit, args['types[]'], args['exclude_types[]'], args.account_id)
|
const data = NotificationHelpers.getNotifications(user, args.max_id, args.since_id, args.min_id, args.limit, args['types[]'], args['exclude_types[]'], args.account_id)
|
||||||
.then(p => NotificationConverter.encodeMany(p, user, cache))
|
.then(p => NotificationConverter.encodeMany(p, user, cache))
|
||||||
.then(p => p.map(n => convertNotification(n)));
|
.then(p => p.map(n => convertNotificationIds(n)));
|
||||||
|
|
||||||
ctx.body = await data;
|
ctx.body = await data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -50,7 +50,7 @@ export function setupEndpointsNotifications(router: Router): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.body = convertNotification(await NotificationConverter.encode(notification, user));
|
ctx.body = convertNotificationIds(await NotificationConverter.encode(notification, user));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Converter } from "megalodon";
|
||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { argsToBools, convertPaginationArgsIds, limitToInt, normalizeUrlQuery } from "./timeline.js";
|
import { argsToBools, convertPaginationArgsIds, limitToInt, normalizeUrlQuery } from "./timeline.js";
|
||||||
import { convertAccount, convertSearch, convertStatus } from "../converters.js";
|
import { convertAccountId, convertSearchIds, convertStatusIds } from "../converters.js";
|
||||||
import authenticate from "@/server/api/authenticate.js";
|
import authenticate from "@/server/api/authenticate.js";
|
||||||
import { UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
import { UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
||||||
import { SearchHelpers } from "@/server/api/mastodon/helpers/search.js";
|
import { SearchHelpers } from "@/server/api/mastodon/helpers/search.js";
|
||||||
|
@ -23,7 +23,7 @@ export function setupEndpointsSearch(router: Router): void {
|
||||||
const result = await SearchHelpers.search(user, args.q, args.type, args.resolve, args.following, args.account_id, args['exclude_unreviewed'], args.max_id, args.min_id, args.limit, args.offset, cache);
|
const result = await SearchHelpers.search(user, args.q, args.type, args.resolve, args.following, args.account_id, args['exclude_unreviewed'], args.max_id, args.min_id, args.limit, args.offset, cache);
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
...convertSearch(result),
|
...convertSearchIds(result),
|
||||||
hashtags: result.hashtags.map(p => p.name),
|
hashtags: result.hashtags.map(p => p.name),
|
||||||
};
|
};
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -46,7 +46,7 @@ export function setupEndpointsSearch(router: Router): void {
|
||||||
const cache = UserHelpers.getFreshAccountCache();
|
const cache = UserHelpers.getFreshAccountCache();
|
||||||
const result = await SearchHelpers.search(user, args.q, args.type, args.resolve, args.following, args.account_id, args['exclude_unreviewed'], args.max_id, args.min_id, args.limit, args.offset, cache);
|
const result = await SearchHelpers.search(user, args.q, args.type, args.resolve, args.following, args.account_id, args['exclude_unreviewed'], args.max_id, args.min_id, args.limit, args.offset, cache);
|
||||||
|
|
||||||
ctx.body = convertSearch(result);
|
ctx.body = convertSearchIds(result);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 400;
|
ctx.status = 400;
|
||||||
|
@ -62,7 +62,7 @@ export function setupEndpointsSearch(router: Router): void {
|
||||||
ctx.request.hostname,
|
ctx.request.hostname,
|
||||||
accessTokens,
|
accessTokens,
|
||||||
);
|
);
|
||||||
ctx.body = data.map((status) => convertStatus(status));
|
ctx.body = data.map((status) => convertStatusIds(status));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -81,7 +81,7 @@ export function setupEndpointsSearch(router: Router): void {
|
||||||
query.limit || 20,
|
query.limit || 20,
|
||||||
);
|
);
|
||||||
data = data.map((suggestion) => {
|
data = data.map((suggestion) => {
|
||||||
suggestion.account = convertAccount(suggestion.account);
|
suggestion.account = convertAccountId(suggestion.account);
|
||||||
return suggestion;
|
return suggestion;
|
||||||
});
|
});
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import { convertId, IdType } from "../../index.js";
|
import { convertId, IdType } from "../../index.js";
|
||||||
import { convertAccount, convertPoll, convertStatus, convertStatusEdit, convertStatusSource, } from "../converters.js";
|
import { convertAccountId, convertPollId, convertStatusIds, convertStatusEditIds, convertStatusSourceId, } from "../converters.js";
|
||||||
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
||||||
import { getNote } from "@/server/api/common/getters.js";
|
import { getNote } from "@/server/api/common/getters.js";
|
||||||
import authenticate from "@/server/api/authenticate.js";
|
import authenticate from "@/server/api/authenticate.js";
|
||||||
|
@ -42,7 +42,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
let request = NoteHelpers.normalizeComposeOptions(ctx.request.body);
|
let request = NoteHelpers.normalizeComposeOptions(ctx.request.body);
|
||||||
ctx.body = await NoteHelpers.createNote(request, user)
|
ctx.body = await NoteHelpers.createNote(request, user)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
|
|
||||||
if (key !== null) postIdempotencyCache.set(key, {status: ctx.body});
|
if (key !== null) postIdempotencyCache.set(key, {status: ctx.body});
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -76,7 +76,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
let request = NoteHelpers.normalizeEditOptions(ctx.request.body);
|
let request = NoteHelpers.normalizeEditOptions(ctx.request.body);
|
||||||
ctx.body = await NoteHelpers.editNote(request, note, user)
|
ctx.body = await NoteHelpers.editNote(request, note, user)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = ctx.status == 404 ? 404 : 401;
|
ctx.status = ctx.status == 404 ? 404 : 401;
|
||||||
|
@ -97,7 +97,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = await NoteConverter.encode(note, user);
|
const status = await NoteConverter.encode(note, user);
|
||||||
ctx.body = convertStatus(status);
|
ctx.body = convertStatusIds(status);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = ctx.status == 404 ? 404 : 401;
|
ctx.status = ctx.status == 404 ? 404 : 401;
|
||||||
|
@ -134,7 +134,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.deleteNote(note, user)
|
ctx.body = await NoteHelpers.deleteNote(note, user)
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(`Error processing ${ctx.method} /api${ctx.path}: ${e.message}`);
|
console.error(`Error processing ${ctx.method} /api${ctx.path}: ${e.message}`);
|
||||||
ctx.status = 500;
|
ctx.status = 500;
|
||||||
|
@ -163,10 +163,10 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
const ancestors = await NoteHelpers.getNoteAncestors(note, user, user ? 4096 : 60)
|
const ancestors = await NoteHelpers.getNoteAncestors(note, user, user ? 4096 : 60)
|
||||||
.then(n => NoteConverter.encodeMany(n, user, cache))
|
.then(n => NoteConverter.encodeMany(n, user, cache))
|
||||||
.then(n => n.map(s => convertStatus(s)));
|
.then(n => n.map(s => convertStatusIds(s)));
|
||||||
const descendants = await NoteHelpers.getNoteDescendants(note, user, user ? 4096 : 40, user ? 4096 : 20)
|
const descendants = await NoteHelpers.getNoteDescendants(note, user, user ? 4096 : 40, user ? 4096 : 20)
|
||||||
.then(n => NoteConverter.encodeMany(n, user, cache))
|
.then(n => NoteConverter.encodeMany(n, user, cache))
|
||||||
.then(n => n.map(s => convertStatus(s)));
|
.then(n => n.map(s => convertStatusIds(s)));
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
ancestors,
|
ancestors,
|
||||||
|
@ -195,7 +195,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await NoteHelpers.getNoteEditHistory(note);
|
const res = await NoteHelpers.getNoteEditHistory(note);
|
||||||
ctx.body = res.map(p => convertStatusEdit(p));
|
ctx.body = res.map(p => convertStatusEditIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -219,7 +219,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
const src = NoteHelpers.getNoteSource(note);
|
const src = NoteHelpers.getNoteSource(note);
|
||||||
ctx.body = convertStatusSource(src);
|
ctx.body = convertStatusSourceId(src);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -246,7 +246,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
|
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
|
||||||
const res = await NoteHelpers.getNoteRebloggedBy(note, user, args.max_id, args.since_id, args.min_id, args.limit);
|
const res = await NoteHelpers.getNoteRebloggedBy(note, user, args.max_id, args.since_id, args.min_id, args.limit);
|
||||||
const users = await UserConverter.encodeMany(res.data, cache);
|
const users = await UserConverter.encodeMany(res.data, cache);
|
||||||
ctx.body = users.map(m => convertAccount(m));
|
ctx.body = users.map(m => convertAccountId(m));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -274,7 +274,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
|
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
|
||||||
const res = await NoteHelpers.getNoteFavoritedBy(note, args.max_id, args.since_id, args.min_id, args.limit);
|
const res = await NoteHelpers.getNoteFavoritedBy(note, args.max_id, args.since_id, args.min_id, args.limit);
|
||||||
const users = await UserConverter.encodeMany(res.data, cache);
|
const users = await UserConverter.encodeMany(res.data, cache);
|
||||||
ctx.body = users.map(m => convertAccount(m));
|
ctx.body = users.map(m => convertAccountId(m));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -312,7 +312,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.reactToNote(note, user, reaction)
|
ctx.body = await NoteHelpers.reactToNote(note, user, reaction)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -343,7 +343,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.removeReactFromNote(note, user)
|
ctx.body = await NoteHelpers.removeReactFromNote(note, user)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -374,7 +374,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.reblogNote(note, user)
|
ctx.body = await NoteHelpers.reblogNote(note, user)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -405,7 +405,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.unreblogNote(note, user)
|
ctx.body = await NoteHelpers.unreblogNote(note, user)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -436,7 +436,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.bookmarkNote(note, user)
|
ctx.body = await NoteHelpers.bookmarkNote(note, user)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -467,7 +467,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.unbookmarkNote(note, user)
|
ctx.body = await NoteHelpers.unbookmarkNote(note, user)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -498,7 +498,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.pinNote(note, user)
|
ctx.body = await NoteHelpers.pinNote(note, user)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -529,7 +529,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.unpinNote(note, user)
|
ctx.body = await NoteHelpers.unpinNote(note, user)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -560,7 +560,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.reactToNote(note, user, ctx.params.name)
|
ctx.body = await NoteHelpers.reactToNote(note, user, ctx.params.name)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -591,7 +591,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
|
|
||||||
ctx.body = await NoteHelpers.removeReactFromNote(note, user)
|
ctx.body = await NoteHelpers.removeReactFromNote(note, user)
|
||||||
.then(p => NoteConverter.encode(p, user))
|
.then(p => NoteConverter.encode(p, user))
|
||||||
.then(p => convertStatus(p));
|
.then(p => convertStatusIds(p));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -613,7 +613,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await PollHelpers.getPoll(note, user);
|
const data = await PollHelpers.getPoll(note, user);
|
||||||
ctx.body = convertPoll(data);
|
ctx.body = convertPollId(data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -649,7 +649,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await PollHelpers.voteInPoll(choices, note, user);
|
const data = await PollHelpers.voteInPoll(choices, note, user);
|
||||||
ctx.body = convertPoll(data);
|
ctx.body = convertPollId(data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import { getClient } from "../index.js";
|
import { getClient } from "../index.js";
|
||||||
import { ParsedUrlQuery } from "querystring";
|
import { ParsedUrlQuery } from "querystring";
|
||||||
import { convertConversation, convertStatus, } from "../converters.js";
|
import { convertConversationIds, convertStatusIds, } from "../converters.js";
|
||||||
import { convertId, IdType } from "../../index.js";
|
import { convertId, IdType } from "../../index.js";
|
||||||
import authenticate from "@/server/api/authenticate.js";
|
import authenticate from "@/server/api/authenticate.js";
|
||||||
import { TimelineHelpers } from "@/server/api/mastodon/helpers/timeline.js";
|
import { TimelineHelpers } from "@/server/api/mastodon/helpers/timeline.js";
|
||||||
|
@ -79,7 +79,7 @@ export function setupEndpointsTimeline(router: Router): void {
|
||||||
const tl = await TimelineHelpers.getPublicTimeline(user, args.max_id, args.since_id, args.min_id, args.limit, args.only_media, args.local, args.remote)
|
const tl = await TimelineHelpers.getPublicTimeline(user, args.max_id, args.since_id, args.min_id, args.limit, args.only_media, args.local, args.remote)
|
||||||
.then(n => NoteConverter.encodeMany(n, user, cache));
|
.then(n => NoteConverter.encodeMany(n, user, cache));
|
||||||
|
|
||||||
ctx.body = tl.map(s => convertStatus(s));
|
ctx.body = tl.map(s => convertStatusIds(s));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -111,7 +111,7 @@ export function setupEndpointsTimeline(router: Router): void {
|
||||||
const tl = await TimelineHelpers.getTagTimeline(user, tag, args.max_id, args.since_id, args.min_id, args.limit, args['any[]'] ?? [], args['all[]'] ?? [], args['none[]'] ?? [], args.only_media, args.local, args.remote)
|
const tl = await TimelineHelpers.getTagTimeline(user, tag, args.max_id, args.since_id, args.min_id, args.limit, args['any[]'] ?? [], args['all[]'] ?? [], args['none[]'] ?? [], args.only_media, args.local, args.remote)
|
||||||
.then(n => NoteConverter.encodeMany(n, user, cache));
|
.then(n => NoteConverter.encodeMany(n, user, cache));
|
||||||
|
|
||||||
ctx.body = tl.map(s => convertStatus(s));
|
ctx.body = tl.map(s => convertStatusIds(s));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
ctx.status = 400;
|
ctx.status = 400;
|
||||||
ctx.body = { error: e.message };
|
ctx.body = { error: e.message };
|
||||||
|
@ -133,7 +133,7 @@ export function setupEndpointsTimeline(router: Router): void {
|
||||||
const tl = await TimelineHelpers.getHomeTimeline(user, args.max_id, args.since_id, args.min_id, args.limit)
|
const tl = await TimelineHelpers.getHomeTimeline(user, args.max_id, args.since_id, args.min_id, args.limit)
|
||||||
.then(n => NoteConverter.encodeMany(n, user, cache));
|
.then(n => NoteConverter.encodeMany(n, user, cache));
|
||||||
|
|
||||||
ctx.body = tl.map(s => convertStatus(s));
|
ctx.body = tl.map(s => convertStatusIds(s));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -166,7 +166,7 @@ export function setupEndpointsTimeline(router: Router): void {
|
||||||
const tl = await TimelineHelpers.getListTimeline(user, list, args.max_id, args.since_id, args.min_id, args.limit)
|
const tl = await TimelineHelpers.getListTimeline(user, list, args.max_id, args.since_id, args.min_id, args.limit)
|
||||||
.then(n => NoteConverter.encodeMany(n, user, cache));
|
.then(n => NoteConverter.encodeMany(n, user, cache));
|
||||||
|
|
||||||
ctx.body = tl.map(s => convertStatus(s));
|
ctx.body = tl.map(s => convertStatusIds(s));
|
||||||
|
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -189,7 +189,7 @@ export function setupEndpointsTimeline(router: Router): void {
|
||||||
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query)));
|
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query)));
|
||||||
const res = await TimelineHelpers.getConversations(user, args.max_id, args.since_id, args.min_id, args.limit);
|
const res = await TimelineHelpers.getConversations(user, args.max_id, args.since_id, args.min_id, args.limit);
|
||||||
|
|
||||||
ctx.body = res.data.map(c => convertConversation(c));
|
ctx.body = res.data.map(c => convertConversationIds(c));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 20);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 20);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Instances, Notes, Users } from "@/models/index.js";
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import { awaitAll } from "@/prelude/await-all.js";
|
import { awaitAll } from "@/prelude/await-all.js";
|
||||||
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
||||||
import { convertAccount } from "@/server/api/mastodon/converters.js";
|
import { convertAccountId } from "@/server/api/mastodon/converters.js";
|
||||||
|
|
||||||
export class MiscHelpers {
|
export class MiscHelpers {
|
||||||
public static async getInstance(): Promise<MastodonEntity.Instance> {
|
public static async getInstance(): Promise<MastodonEntity.Instance> {
|
||||||
|
@ -22,7 +22,7 @@ export class MiscHelpers {
|
||||||
order: {id: "ASC"},
|
order: {id: "ASC"},
|
||||||
})
|
})
|
||||||
.then(p => p ? UserConverter.encode(p) : null)
|
.then(p => p ? UserConverter.encode(p) : null)
|
||||||
.then(p => p ? convertAccount(p) : null);
|
.then(p => p ? convertAccountId(p) : null);
|
||||||
const meta = await fetchMeta(true);
|
const meta = await fetchMeta(true);
|
||||||
|
|
||||||
const res = {
|
const res = {
|
||||||
|
|
Loading…
Reference in a new issue