chore: formatting
This commit is contained in:
parent
9708170559
commit
ad969a28cc
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "calckey",
|
"name": "calckey",
|
||||||
"version": "13.2.0-dev41",
|
"version": "13.2.0-dev42",
|
||||||
"codename": "aqua",
|
"codename": "aqua",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -10,7 +10,13 @@ import { renderPerson } from "@/remote/activitypub/renderer/person.js";
|
||||||
import renderEmoji from "@/remote/activitypub/renderer/emoji.js";
|
import renderEmoji from "@/remote/activitypub/renderer/emoji.js";
|
||||||
import { inbox as processInbox } from "@/queue/index.js";
|
import { inbox as processInbox } from "@/queue/index.js";
|
||||||
import { isSelfHost, toPuny } from "@/misc/convert-host.js";
|
import { isSelfHost, toPuny } from "@/misc/convert-host.js";
|
||||||
import { Notes, Users, Emojis, NoteReactions, FollowRequests } from "@/models/index.js";
|
import {
|
||||||
|
Notes,
|
||||||
|
Users,
|
||||||
|
Emojis,
|
||||||
|
NoteReactions,
|
||||||
|
FollowRequests,
|
||||||
|
} from "@/models/index.js";
|
||||||
import type { ILocalUser, User } from "@/models/entities/user.js";
|
import type { ILocalUser, User } from "@/models/entities/user.js";
|
||||||
import { renderLike } from "@/remote/activitypub/renderer/like.js";
|
import { renderLike } from "@/remote/activitypub/renderer/like.js";
|
||||||
import { getUserKeypair } from "@/misc/keypair-store.js";
|
import { getUserKeypair } from "@/misc/keypair-store.js";
|
||||||
|
@ -330,7 +336,9 @@ router.get("/likes/:like", async (ctx) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// follow
|
// follow
|
||||||
router.get("/follows/:follower/:followee", async (ctx: Router.RouterContext) => {
|
router.get(
|
||||||
|
"/follows/:follower/:followee",
|
||||||
|
async (ctx: Router.RouterContext) => {
|
||||||
const verify = await checkFetch(ctx.req);
|
const verify = await checkFetch(ctx.req);
|
||||||
if (verify !== 200) {
|
if (verify !== 200) {
|
||||||
ctx.status = verify;
|
ctx.status = verify;
|
||||||
|
@ -363,7 +371,8 @@ router.get("/follows/:follower/:followee", async (ctx: Router.RouterContext) =>
|
||||||
ctx.set("Cache-Control", "public, max-age=180");
|
ctx.set("Cache-Control", "public, max-age=180");
|
||||||
}
|
}
|
||||||
setResponseType(ctx);
|
setResponseType(ctx);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// follow request
|
// follow request
|
||||||
router.get("/follows/:followRequestId", async (ctx: Router.RouterContext) => {
|
router.get("/follows/:followRequestId", async (ctx: Router.RouterContext) => {
|
||||||
|
|
|
@ -70,7 +70,9 @@ export function apiMastodonCompatible(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getInstanceAnnouncements();
|
const data = await client.getInstanceAnnouncements();
|
||||||
ctx.body = data.data.map(announcement => convertAnnouncement(announcement));
|
ctx.body = data.data.map((announcement) =>
|
||||||
|
convertAnnouncement(announcement),
|
||||||
|
);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -104,7 +106,7 @@ export function apiMastodonCompatible(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) => convertFilter(filter));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
|
|
@ -6,11 +6,21 @@ function simpleConvert(data: any) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertAccount(account: Entity.Account) { return simpleConvert(account); }
|
export function convertAccount(account: Entity.Account) {
|
||||||
export function convertAnnouncement(announcement: Entity.Announcement) { return simpleConvert(announcement); }
|
return simpleConvert(account);
|
||||||
export function convertAttachment(attachment: Entity.Attachment) { return simpleConvert(attachment); }
|
}
|
||||||
export function convertFilter(filter: Entity.Filter) { return simpleConvert(filter); }
|
export function convertAnnouncement(announcement: Entity.Announcement) {
|
||||||
export function convertList(list: Entity.List) { return simpleConvert(list); }
|
return simpleConvert(announcement);
|
||||||
|
}
|
||||||
|
export function convertAttachment(attachment: Entity.Attachment) {
|
||||||
|
return simpleConvert(attachment);
|
||||||
|
}
|
||||||
|
export function convertFilter(filter: Entity.Filter) {
|
||||||
|
return simpleConvert(filter);
|
||||||
|
}
|
||||||
|
export function convertList(list: Entity.List) {
|
||||||
|
return simpleConvert(list);
|
||||||
|
}
|
||||||
|
|
||||||
export function convertNotification(notification: Entity.Notification) {
|
export function convertNotification(notification: Entity.Notification) {
|
||||||
notification.account = convertAccount(notification.account);
|
notification.account = convertAccount(notification.account);
|
||||||
|
@ -20,25 +30,32 @@ export function convertNotification(notification: Entity.Notification) {
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertPoll(poll: Entity.Poll) { return simpleConvert(poll); }
|
export function convertPoll(poll: Entity.Poll) {
|
||||||
export function convertRelationship(relationship: Entity.Relationship) { return simpleConvert(relationship); }
|
return simpleConvert(poll);
|
||||||
|
}
|
||||||
|
export function convertRelationship(relationship: Entity.Relationship) {
|
||||||
|
return simpleConvert(relationship);
|
||||||
|
}
|
||||||
|
|
||||||
export function convertStatus(status: Entity.Status) {
|
export function convertStatus(status: Entity.Status) {
|
||||||
status.account = convertAccount(status.account);
|
status.account = convertAccount(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, IdType.MastodonId);
|
status.in_reply_to_account_id = convertId(
|
||||||
|
status.in_reply_to_account_id,
|
||||||
|
IdType.MastodonId,
|
||||||
|
);
|
||||||
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 => convertAttachment(attachment));
|
status.media_attachments = status.media_attachments.map((attachment) =>
|
||||||
status.mentions = status.mentions.map(mention => ({
|
convertAttachment(attachment),
|
||||||
|
);
|
||||||
|
status.mentions = status.mentions.map((mention) => ({
|
||||||
...mention,
|
...mention,
|
||||||
id: convertId(mention.id, IdType.MastodonId),
|
id: convertId(mention.id, IdType.MastodonId),
|
||||||
}));
|
}));
|
||||||
if (status.poll)
|
if (status.poll) status.poll = convertPoll(status.poll);
|
||||||
status.poll = convertPoll(status.poll);
|
if (status.reblog) status.reblog = convertStatus(status.reblog);
|
||||||
if (status.reblog)
|
|
||||||
status.reblog = convertStatus(status.reblog);
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,12 @@ import { FindOptionsWhere, IsNull } from "typeorm";
|
||||||
import { getClient } from "../ApiMastodonCompatibleService.js";
|
import { getClient } from "../ApiMastodonCompatibleService.js";
|
||||||
import { argsToBools, convertTimelinesArgsId, limitToInt } from "./timeline.js";
|
import { argsToBools, convertTimelinesArgsId, limitToInt } from "./timeline.js";
|
||||||
import { convertId, IdType } from "../../index.js";
|
import { convertId, IdType } from "../../index.js";
|
||||||
import { convertAccount, convertList, convertRelationship, convertStatus } from "../converters.js";
|
import {
|
||||||
|
convertAccount,
|
||||||
|
convertList,
|
||||||
|
convertRelationship,
|
||||||
|
convertStatus,
|
||||||
|
} from "../converters.js";
|
||||||
|
|
||||||
const relationshipModel = {
|
const relationshipModel = {
|
||||||
id: "",
|
id: "",
|
||||||
|
@ -112,7 +117,9 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await client.getRelationships(reqIds);
|
const data = await client.getRelationships(reqIds);
|
||||||
ctx.body = data.data.map(relationship => convertRelationship(relationship));
|
ctx.body = data.data.map((relationship) =>
|
||||||
|
convertRelationship(relationship),
|
||||||
|
);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
let data = e.response.data;
|
let data = e.response.data;
|
||||||
|
@ -148,7 +155,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
convertId(ctx.params.id, IdType.CalckeyId),
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
convertTimelinesArgsId(argsToBools(limitToInt(ctx.query as any))),
|
convertTimelinesArgsId(argsToBools(limitToInt(ctx.query as any))),
|
||||||
);
|
);
|
||||||
ctx.body = data.data.map(status => convertStatus(status));
|
ctx.body = data.data.map((status) => convertStatus(status));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -168,7 +175,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
convertId(ctx.params.id, IdType.CalckeyId),
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
convertTimelinesArgsId(limitToInt(ctx.query as any)),
|
convertTimelinesArgsId(limitToInt(ctx.query as any)),
|
||||||
);
|
);
|
||||||
ctx.body = data.data.map(account => convertAccount(account));
|
ctx.body = data.data.map((account) => convertAccount(account));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -188,7 +195,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
convertId(ctx.params.id, IdType.CalckeyId),
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
convertTimelinesArgsId(limitToInt(ctx.query as any)),
|
convertTimelinesArgsId(limitToInt(ctx.query as any)),
|
||||||
);
|
);
|
||||||
ctx.body = data.data.map(account => convertAccount(account));
|
ctx.body = data.data.map((account) => convertAccount(account));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -205,9 +212,9 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getAccountLists(
|
const data = await client.getAccountLists(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = data.data.map(list => convertList(list));
|
ctx.body = data.data.map((list) => convertList(list));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -340,10 +347,10 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const accessTokens = ctx.headers.authorization;
|
const accessTokens = ctx.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = (await client.getBookmarks(
|
const data = await client.getBookmarks(
|
||||||
convertTimelinesArgsId(limitToInt(ctx.query as any)),
|
convertTimelinesArgsId(limitToInt(ctx.query as any)),
|
||||||
));
|
);
|
||||||
ctx.body = data.data.map(status => convertStatus(status));
|
ctx.body = data.data.map((status) => convertStatus(status));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -356,8 +363,10 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const accessTokens = ctx.headers.authorization;
|
const accessTokens = ctx.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getFavourites(convertTimelinesArgsId(limitToInt(ctx.query as any)));
|
const data = await client.getFavourites(
|
||||||
ctx.body = data.data.map(status => convertStatus(status));
|
convertTimelinesArgsId(limitToInt(ctx.query as any)),
|
||||||
|
);
|
||||||
|
ctx.body = data.data.map((status) => convertStatus(status));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -370,8 +379,10 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const accessTokens = ctx.headers.authorization;
|
const accessTokens = ctx.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getMutes(convertTimelinesArgsId(limitToInt(ctx.query as any)));
|
const data = await client.getMutes(
|
||||||
ctx.body = data.data.map(account => convertAccount(account));
|
convertTimelinesArgsId(limitToInt(ctx.query as any)),
|
||||||
|
);
|
||||||
|
ctx.body = data.data.map((account) => convertAccount(account));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -384,8 +395,10 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const accessTokens = ctx.headers.authorization;
|
const accessTokens = ctx.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getBlocks(convertTimelinesArgsId(limitToInt(ctx.query as any)));
|
const data = await client.getBlocks(
|
||||||
ctx.body = data.data.map(account => convertAccount(account));
|
convertTimelinesArgsId(limitToInt(ctx.query as any)),
|
||||||
|
);
|
||||||
|
ctx.body = data.data.map((account) => convertAccount(account));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -401,7 +414,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const data = await client.getFollowRequests(
|
const data = await client.getFollowRequests(
|
||||||
((ctx.query as any) || { limit: 20 }).limit,
|
((ctx.query as any) || { limit: 20 }).limit,
|
||||||
);
|
);
|
||||||
ctx.body = data.data.map(account => convertAccount(account));
|
ctx.body = data.data.map((account) => convertAccount(account));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
|
|
@ -12,7 +12,7 @@ export function apiFilterMastodon(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) => convertFilter(filter));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -27,7 +27,7 @@ export function apiFilterMastodon(router: Router): void {
|
||||||
const body: any = ctx.request.body;
|
const body: any = ctx.request.body;
|
||||||
try {
|
try {
|
||||||
const data = await client.getFilter(
|
const data = await client.getFilter(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = convertFilter(data.data);
|
ctx.body = convertFilter(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -78,7 +78,7 @@ export function apiFilterMastodon(router: Router): void {
|
||||||
const body: any = ctx.request.body;
|
const body: any = ctx.request.body;
|
||||||
try {
|
try {
|
||||||
const data = await client.deleteFilter(
|
const data = await client.deleteFilter(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = data.data;
|
ctx.body = data.data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
|
@ -17,7 +17,9 @@ export function apiNotificationsMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
const body: any = ctx.request.body;
|
const body: any = ctx.request.body;
|
||||||
try {
|
try {
|
||||||
const data = await client.getNotifications(convertTimelinesArgsId(toLimitToInt(ctx.query)));
|
const data = await client.getNotifications(
|
||||||
|
convertTimelinesArgsId(toLimitToInt(ctx.query)),
|
||||||
|
);
|
||||||
const notfs = data.data;
|
const notfs = data.data;
|
||||||
const ret = notfs.map((n) => {
|
const ret = notfs.map((n) => {
|
||||||
n = convertNotification(n);
|
n = convertNotification(n);
|
||||||
|
@ -47,7 +49,7 @@ export function apiNotificationsMastodon(router: Router): void {
|
||||||
const body: any = ctx.request.body;
|
const body: any = ctx.request.body;
|
||||||
try {
|
try {
|
||||||
const dataRaw = await client.getNotification(
|
const dataRaw = await client.getNotification(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
const data = convertNotification(dataRaw.data);
|
const data = convertNotification(dataRaw.data);
|
||||||
if (data.type !== "follow" && data.type !== "follow_request") {
|
if (data.type !== "follow" && data.type !== "follow_request") {
|
||||||
|
@ -85,7 +87,7 @@ export function apiNotificationsMastodon(router: Router): void {
|
||||||
const body: any = ctx.request.body;
|
const body: any = ctx.request.body;
|
||||||
try {
|
try {
|
||||||
const data = await client.dismissNotification(
|
const data = await client.dismissNotification(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = data.data;
|
ctx.body = data.data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
|
@ -32,14 +32,16 @@ export function apiSearchMastodon(router: Router): void {
|
||||||
const type = query.type;
|
const type = query.type;
|
||||||
if (type) {
|
if (type) {
|
||||||
const data = await client.search(query.q, type, query);
|
const data = await client.search(query.q, type, query);
|
||||||
ctx.body = data.data.accounts.map(account => convertAccount(account));
|
ctx.body = data.data.accounts.map((account) => convertAccount(account));
|
||||||
} else {
|
} else {
|
||||||
const acct = await client.search(query.q, "accounts", query);
|
const acct = await client.search(query.q, "accounts", query);
|
||||||
const stat = await client.search(query.q, "statuses", query);
|
const stat = await client.search(query.q, "statuses", query);
|
||||||
const tags = await client.search(query.q, "hashtags", query);
|
const tags = await client.search(query.q, "hashtags", query);
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
accounts: acct.data.accounts.map(account => convertAccount(account)),
|
accounts: acct.data.accounts.map((account) =>
|
||||||
statuses: stat.data.statuses.map(status => convertStatus(status)),
|
convertAccount(account),
|
||||||
|
),
|
||||||
|
statuses: stat.data.statuses.map((status) => convertStatus(status)),
|
||||||
hashtags: tags.data.hashtags,
|
hashtags: tags.data.hashtags,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -58,7 +60,7 @@ export function apiSearchMastodon(router: Router): void {
|
||||||
ctx.request.hostname,
|
ctx.request.hostname,
|
||||||
accessTokens,
|
accessTokens,
|
||||||
);
|
);
|
||||||
ctx.body = data.map(status => convertStatus(status));
|
ctx.body = data.map((status) => convertStatus(status));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -76,7 +78,7 @@ export function apiSearchMastodon(router: Router): void {
|
||||||
accessTokens,
|
accessTokens,
|
||||||
query.limit || 20,
|
query.limit || 20,
|
||||||
);
|
);
|
||||||
data = data.map(suggestion => {
|
data = data.map((suggestion) => {
|
||||||
suggestion.account = convertAccount(suggestion.account);
|
suggestion.account = convertAccount(suggestion.account);
|
||||||
return suggestion;
|
return suggestion;
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,7 +6,12 @@ import querystring from "node:querystring";
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
import { convertTimelinesArgsId, limitToInt } from "./timeline.js";
|
import { convertTimelinesArgsId, limitToInt } from "./timeline.js";
|
||||||
import { convertId, IdType } from "../../index.js";
|
import { convertId, IdType } from "../../index.js";
|
||||||
import { convertAccount, convertAttachment, convertPoll, convertStatus } from "../converters.js";
|
import {
|
||||||
|
convertAccount,
|
||||||
|
convertAttachment,
|
||||||
|
convertPoll,
|
||||||
|
convertStatus,
|
||||||
|
} from "../converters.js";
|
||||||
|
|
||||||
function normalizeQuery(data: any) {
|
function normalizeQuery(data: any) {
|
||||||
const str = querystring.stringify(data);
|
const str = querystring.stringify(data);
|
||||||
|
@ -86,7 +91,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.deleteStatus(
|
const data = await client.deleteStatus(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = data.data;
|
ctx.body = data.data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -134,8 +139,12 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
text,
|
text,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
data.data.ancestors = data.data.ancestors.map(status => convertStatus(status));
|
data.data.ancestors = data.data.ancestors.map((status) =>
|
||||||
data.data.descendants = data.data.descendants.map(status => convertStatus(status));
|
convertStatus(status),
|
||||||
|
);
|
||||||
|
data.data.descendants = data.data.descendants.map((status) =>
|
||||||
|
convertStatus(status),
|
||||||
|
);
|
||||||
ctx.body = data.data;
|
ctx.body = data.data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -152,9 +161,9 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getStatusRebloggedBy(
|
const data = await client.getStatusRebloggedBy(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = data.data.map(account => convertAccount(account));
|
ctx.body = data.data.map((account) => convertAccount(account));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -200,7 +209,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
try {
|
try {
|
||||||
const data = await client.deleteEmojiReaction(
|
const data = await client.deleteEmojiReaction(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId),
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
react
|
react,
|
||||||
);
|
);
|
||||||
ctx.body = convertStatus(data.data);
|
ctx.body = convertStatus(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -219,7 +228,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.reblogStatus(
|
const data = await client.reblogStatus(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = convertStatus(data.data);
|
ctx.body = convertStatus(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -238,7 +247,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.unreblogStatus(
|
const data = await client.unreblogStatus(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = convertStatus(data.data);
|
ctx.body = convertStatus(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -257,7 +266,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.bookmarkStatus(
|
const data = await client.bookmarkStatus(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = convertStatus(data.data);
|
ctx.body = convertStatus(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -276,7 +285,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.unbookmarkStatus(
|
const data = await client.unbookmarkStatus(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = convertStatus(data.data);
|
ctx.body = convertStatus(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -295,7 +304,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.pinStatus(
|
const data = await client.pinStatus(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = convertStatus(data.data);
|
ctx.body = convertStatus(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -314,7 +323,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.unpinStatus(
|
const data = await client.unpinStatus(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = convertStatus(data.data);
|
ctx.body = convertStatus(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -330,7 +339,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getMedia(
|
const data = await client.getMedia(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = convertAttachment(data.data);
|
ctx.body = convertAttachment(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -361,7 +370,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getPoll(
|
const data = await client.getPoll(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId)
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
);
|
);
|
||||||
ctx.body = convertPoll(data.data);
|
ctx.body = convertPoll(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
|
@ -109,9 +109,13 @@ export function apiTimelineMastodon(router: Router): void {
|
||||||
try {
|
try {
|
||||||
const query: any = ctx.query;
|
const query: any = ctx.query;
|
||||||
const data = query.local
|
const data = query.local
|
||||||
? await client.getLocalTimeline(convertTimelinesArgsId(argsToBools(limitToInt(query))))
|
? await client.getLocalTimeline(
|
||||||
: await client.getPublicTimeline(convertTimelinesArgsId(argsToBools(limitToInt(query))));
|
convertTimelinesArgsId(argsToBools(limitToInt(query))),
|
||||||
let resp = data.data.map(status => convertStatus(status));
|
)
|
||||||
|
: await client.getPublicTimeline(
|
||||||
|
convertTimelinesArgsId(argsToBools(limitToInt(query))),
|
||||||
|
);
|
||||||
|
let resp = data.data.map((status) => convertStatus(status));
|
||||||
ctx.body = toTextWithReaction(resp, ctx.hostname);
|
ctx.body = toTextWithReaction(resp, ctx.hostname);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -131,7 +135,7 @@ export function apiTimelineMastodon(router: Router): void {
|
||||||
ctx.params.hashtag,
|
ctx.params.hashtag,
|
||||||
convertTimelinesArgsId(argsToBools(limitToInt(ctx.query))),
|
convertTimelinesArgsId(argsToBools(limitToInt(ctx.query))),
|
||||||
);
|
);
|
||||||
let resp = data.data.map(status => convertStatus(status));
|
let resp = data.data.map((status) => convertStatus(status));
|
||||||
ctx.body = toTextWithReaction(resp, ctx.hostname);
|
ctx.body = toTextWithReaction(resp, ctx.hostname);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -146,8 +150,10 @@ export function apiTimelineMastodon(router: Router): void {
|
||||||
const accessTokens = ctx.headers.authorization;
|
const accessTokens = ctx.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getHomeTimeline(convertTimelinesArgsId(limitToInt(ctx.query)));
|
const data = await client.getHomeTimeline(
|
||||||
let resp = data.data.map(status => convertStatus(status));
|
convertTimelinesArgsId(limitToInt(ctx.query)),
|
||||||
|
);
|
||||||
|
let resp = data.data.map((status) => convertStatus(status));
|
||||||
ctx.body = toTextWithReaction(resp, ctx.hostname);
|
ctx.body = toTextWithReaction(resp, ctx.hostname);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -167,7 +173,7 @@ export function apiTimelineMastodon(router: Router): void {
|
||||||
convertId(ctx.params.listId, IdType.CalckeyId),
|
convertId(ctx.params.listId, IdType.CalckeyId),
|
||||||
convertTimelinesArgsId(limitToInt(ctx.query)),
|
convertTimelinesArgsId(limitToInt(ctx.query)),
|
||||||
);
|
);
|
||||||
let resp = data.data.map(status => convertStatus(status));
|
let resp = data.data.map((status) => convertStatus(status));
|
||||||
ctx.body = toTextWithReaction(resp, ctx.hostname);
|
ctx.body = toTextWithReaction(resp, ctx.hostname);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -182,7 +188,9 @@ export function apiTimelineMastodon(router: Router): void {
|
||||||
const accessTokens = ctx.headers.authorization;
|
const accessTokens = ctx.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getConversationTimeline(convertTimelinesArgsId(limitToInt(ctx.query)));
|
const data = await client.getConversationTimeline(
|
||||||
|
convertTimelinesArgsId(limitToInt(ctx.query)),
|
||||||
|
);
|
||||||
ctx.body = data.data;
|
ctx.body = data.data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -197,7 +205,7 @@ export function apiTimelineMastodon(router: Router): void {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.getLists();
|
const data = await client.getLists();
|
||||||
ctx.body = data.data.map(list => convertList(list));
|
ctx.body = data.data.map((list) => convertList(list));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -247,7 +255,7 @@ export function apiTimelineMastodon(router: Router): void {
|
||||||
try {
|
try {
|
||||||
const data = await client.updateList(
|
const data = await client.updateList(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId),
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
(ctx.request.body as any).title
|
(ctx.request.body as any).title,
|
||||||
);
|
);
|
||||||
ctx.body = convertList(data.data);
|
ctx.body = convertList(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -288,7 +296,7 @@ export function apiTimelineMastodon(router: Router): void {
|
||||||
convertId(ctx.params.id, IdType.CalckeyId),
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
convertTimelinesArgsId(ctx.query as any),
|
convertTimelinesArgsId(ctx.query as any),
|
||||||
);
|
);
|
||||||
ctx.body = data.data.map(account => convertAccount(account));
|
ctx.body = data.data.map((account) => convertAccount(account));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -306,7 +314,9 @@ export function apiTimelineMastodon(router: Router): void {
|
||||||
try {
|
try {
|
||||||
const data = await client.addAccountsToList(
|
const data = await client.addAccountsToList(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId),
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
(ctx.query.account_ids as string[]).map(id => convertId(id, IdType.CalckeyId)),
|
(ctx.query.account_ids as string[]).map((id) =>
|
||||||
|
convertId(id, IdType.CalckeyId),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
ctx.body = data.data;
|
ctx.body = data.data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -326,7 +336,9 @@ export function apiTimelineMastodon(router: Router): void {
|
||||||
try {
|
try {
|
||||||
const data = await client.deleteAccountsFromList(
|
const data = await client.deleteAccountsFromList(
|
||||||
convertId(ctx.params.id, IdType.CalckeyId),
|
convertId(ctx.params.id, IdType.CalckeyId),
|
||||||
(ctx.query.account_ids as string[]).map(id => convertId(id, IdType.CalckeyId)),
|
(ctx.query.account_ids as string[]).map((id) =>
|
||||||
|
convertId(id, IdType.CalckeyId),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
ctx.body = data.data;
|
ctx.body = data.data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
|
@ -403,7 +403,9 @@ router.get("/notes/:note", async (ctx, next) => {
|
||||||
if (note) {
|
if (note) {
|
||||||
const _note = await Notes.pack(note);
|
const _note = await Notes.pack(note);
|
||||||
|
|
||||||
const profile = await UserProfiles.findOneByOrFail({ userId: note.userId });
|
const profile = await UserProfiles.findOneByOrFail({
|
||||||
|
userId: note.userId,
|
||||||
|
});
|
||||||
const meta = await fetchMeta();
|
const meta = await fetchMeta();
|
||||||
await ctx.render("note", {
|
await ctx.render("note", {
|
||||||
note: _note,
|
note: _note,
|
||||||
|
|
|
@ -462,18 +462,23 @@ if (
|
||||||
props.reply &&
|
props.reply &&
|
||||||
["home", "followers", "specified"].includes(props.reply.visibility)
|
["home", "followers", "specified"].includes(props.reply.visibility)
|
||||||
) {
|
) {
|
||||||
if (props.reply.visibility === 'home' && visibility === 'followers') {
|
if (props.reply.visibility === "home" && visibility === "followers") {
|
||||||
visibility = 'followers';
|
visibility = "followers";
|
||||||
} else if (['home', 'followers'].includes(props.reply.visibility) && visibility === 'specified') {
|
} else if (
|
||||||
visibility = 'specified';
|
["home", "followers"].includes(props.reply.visibility) &&
|
||||||
|
visibility === "specified"
|
||||||
|
) {
|
||||||
|
visibility = "specified";
|
||||||
} else {
|
} else {
|
||||||
visibility = props.reply.visibility;
|
visibility = props.reply.visibility;
|
||||||
}
|
}
|
||||||
if (visibility === 'specified') {
|
if (visibility === "specified") {
|
||||||
if (props.reply.visibleUserIds) {
|
if (props.reply.visibleUserIds) {
|
||||||
os.api('users/show', {
|
os.api("users/show", {
|
||||||
userIds: props.reply.visibleUserIds.filter(uid => uid !== $i.id && uid !== props.reply.userId),
|
userIds: props.reply.visibleUserIds.filter(
|
||||||
}).then(users => {
|
(uid) => uid !== $i.id && uid !== props.reply.userId
|
||||||
|
),
|
||||||
|
}).then((users) => {
|
||||||
users.forEach(pushVisibleUser);
|
users.forEach(pushVisibleUser);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,8 @@
|
||||||
<template>
|
<template>
|
||||||
<button
|
<button v-if="modelValue" class="fade _button" @click.stop="toggle">
|
||||||
v-if="modelValue"
|
|
||||||
class="fade _button"
|
|
||||||
@click.stop="toggle"
|
|
||||||
>
|
|
||||||
<span>{{ i18n.ts.showMore }}</span>
|
<span>{{ i18n.ts.showMore }}</span>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button v-if="!modelValue" class="showLess _button" @click.stop="toggle">
|
||||||
v-if="!modelValue"
|
|
||||||
class="showLess _button"
|
|
||||||
@click.stop="toggle"
|
|
||||||
>
|
|
||||||
<span>{{ i18n.ts.showLess }}</span>
|
<span>{{ i18n.ts.showLess }}</span>
|
||||||
</button>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -115,7 +115,10 @@
|
||||||
v-on:focus="cwButton?.focus()"
|
v-on:focus="cwButton?.focus()"
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
<XShowMoreButton v-if="isLong" v-model="collapsed"></XShowMoreButton>
|
<XShowMoreButton
|
||||||
|
v-if="isLong"
|
||||||
|
v-model="collapsed"
|
||||||
|
></XShowMoreButton>
|
||||||
<XCwButton v-if="note.cw" v-model="showContent" :note="note" />
|
<XCwButton v-if="note.cw" v-model="showContent" :note="note" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -58,7 +58,10 @@
|
||||||
:custom-emojis="user.emojis"
|
:custom-emojis="user.emojis"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<XShowMoreButton v-if="isLong" v-model="collapsed"></XShowMoreButton>
|
<XShowMoreButton
|
||||||
|
v-if="isLong"
|
||||||
|
v-model="collapsed"
|
||||||
|
></XShowMoreButton>
|
||||||
<div v-if="user.fields.length > 0" class="fields">
|
<div v-if="user.fields.length > 0" class="fields">
|
||||||
<dl
|
<dl
|
||||||
v-for="(field, i) in user.fields"
|
v-for="(field, i) in user.fields"
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export default {
|
export default {
|
||||||
mounted: (el) => el.focus()
|
mounted: (el) => el.focus(),
|
||||||
}
|
};
|
||||||
|
|
|
@ -87,23 +87,11 @@ export default {
|
||||||
self.hideTimer = window.setTimeout(self.close, delay);
|
self.hideTimer = window.setTimeout(self.close, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
el.addEventListener(
|
el.addEventListener(start, showTooltip, { passive: true });
|
||||||
start, showTooltip,
|
el.addEventListener("focusin", showTooltip, { passive: true });
|
||||||
{ passive: true },
|
|
||||||
);
|
|
||||||
el.addEventListener(
|
|
||||||
"focusin", showTooltip,
|
|
||||||
{ passive: true },
|
|
||||||
);
|
|
||||||
|
|
||||||
el.addEventListener(
|
el.addEventListener(end, hideTooltip, { passive: true });
|
||||||
end, hideTooltip,
|
el.addEventListener("focusout", hideTooltip, { passive: true });
|
||||||
{ passive: true },
|
|
||||||
);
|
|
||||||
el.addEventListener(
|
|
||||||
"focusout", hideTooltip,
|
|
||||||
{ passive: true },
|
|
||||||
);
|
|
||||||
|
|
||||||
el.addEventListener("click", () => {
|
el.addEventListener("click", () => {
|
||||||
window.clearTimeout(self.showTimer);
|
window.clearTimeout(self.showTimer);
|
||||||
|
|
Loading…
Reference in New Issue