chore: Rome Formatting

This commit is contained in:
ThatOneCalculator 2023-02-10 15:41:19 -08:00
parent fadf8144de
commit fcc59cd35f
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
23 changed files with 1407 additions and 1165 deletions

View File

@ -197,7 +197,10 @@ export const NoteRepository = db.getRepository(Note).extend({
.map((x) => decodeReaction(x).reaction) .map((x) => decodeReaction(x).reaction)
.map((x) => x.replace(/:/g, "")); .map((x) => x.replace(/:/g, ""));
const noteEmoji = await populateEmojis(note.emojis.concat(reactionEmojiNames), host); const noteEmoji = await populateEmojis(
note.emojis.concat(reactionEmojiNames),
host,
);
const reactionEmoji = await populateEmojis(reactionEmojiNames, host); const reactionEmoji = await populateEmojis(reactionEmojiNames, host);
const packed: Packed<"Note"> = await awaitAll({ const packed: Packed<"Note"> = await awaitAll({
id: note.id, id: note.id,

View File

@ -161,8 +161,9 @@ export const packedNoteSchema = {
nullable: false, nullable: false,
}, },
emojis: { emojis: {
type: 'object', type: "object",
optional: true, nullable: true, optional: true,
nullable: true,
}, },
reactions: { reactions: {
type: "object", type: "object",

View File

@ -111,13 +111,13 @@ export async function createNote(
const note: IPost = object; const note: IPost = object;
if (note.id && !note.id.startsWith('https://')) { if (note.id && !note.id.startsWith("https://")) {
throw new Error(`unexpected shcema of note.id: ${note.id}`); throw new Error(`unexpected shcema of note.id: ${note.id}`);
} }
const url = getOneApHrefNullable(note.url); const url = getOneApHrefNullable(note.url);
if (url && !url.startsWith('https://')) { if (url && !url.startsWith("https://")) {
throw new Error(`unexpected shcema of note url: ${url}`); throw new Error(`unexpected shcema of note url: ${url}`);
} }
@ -133,7 +133,9 @@ export async function createNote(
// Skip if author is suspended. // Skip if author is suspended.
if (actor.isSuspended) { if (actor.isSuspended) {
logger.debug(`User ${actor.usernameLower}@${actor.host} suspended; discarding.`) logger.debug(
`User ${actor.usernameLower}@${actor.host} suspended; discarding.`,
);
return null; return null;
} }

View File

@ -197,7 +197,7 @@ export async function createPerson(
const url = getOneApHrefNullable(person.url); const url = getOneApHrefNullable(person.url);
if (url && !url.startsWith('https://')) { if (url && !url.startsWith("https://")) {
throw new Error(`unexpected shcema of person url: ${url}`); throw new Error(`unexpected shcema of person url: ${url}`);
} }
@ -395,7 +395,7 @@ export async function updatePerson(
const url = getOneApHrefNullable(person.url); const url = getOneApHrefNullable(person.url);
if (url && !url.startsWith('https://')) { if (url && !url.startsWith("https://")) {
throw new Error(`unexpected shcema of person url: ${url}`); throw new Error(`unexpected shcema of person url: ${url}`);
} }

View File

@ -198,7 +198,7 @@ import * as ep___i_readAnnouncement from "./endpoints/i/read-announcement.js";
import * as ep___i_regenerateToken from "./endpoints/i/regenerate-token.js"; import * as ep___i_regenerateToken from "./endpoints/i/regenerate-token.js";
import * as ep___i_registry_getAll from "./endpoints/i/registry/get-all.js"; import * as ep___i_registry_getAll from "./endpoints/i/registry/get-all.js";
import * as ep___i_registry_getDetail from "./endpoints/i/registry/get-detail.js"; import * as ep___i_registry_getDetail from "./endpoints/i/registry/get-detail.js";
import * as ep___i_registry_getUnsecure from './endpoints/i/registry/get-unsecure.js'; import * as ep___i_registry_getUnsecure from "./endpoints/i/registry/get-unsecure.js";
import * as ep___i_registry_get from "./endpoints/i/registry/get.js"; import * as ep___i_registry_get from "./endpoints/i/registry/get.js";
import * as ep___i_registry_keysWithType from "./endpoints/i/registry/keys-with-type.js"; import * as ep___i_registry_keysWithType from "./endpoints/i/registry/keys-with-type.js";
import * as ep___i_registry_keys from "./endpoints/i/registry/keys.js"; import * as ep___i_registry_keys from "./endpoints/i/registry/keys.js";
@ -767,10 +767,10 @@ export interface IEndpointMeta {
} }
export interface IEndpoint { export interface IEndpoint {
name: string, name: string;
exec: any, // TODO: may be obosolete @ThatOneCalculator exec: any; // TODO: may be obosolete @ThatOneCalculator
meta: IEndpointMeta, meta: IEndpointMeta;
params: Schema, params: Schema;
} }
const endpoints: IEndpoint[] = (eps as [string, any]).map(([name, ep]) => { const endpoints: IEndpoint[] = (eps as [string, any]).map(([name, ep]) => {

View File

@ -1,6 +1,6 @@
import { ApiError } from "../../../error.js"; import { ApiError } from "../../../error.js";
import define from "../../../define.js"; import define from "../../../define.js";
import {RegistryItems} from "@/models/index.js"; import { RegistryItems } from "@/models/index.js";
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,

View File

@ -7,7 +7,7 @@ import Router from "@koa/router";
import multer from "@koa/multer"; import multer from "@koa/multer";
import bodyParser from "koa-bodyparser"; import bodyParser from "koa-bodyparser";
import cors from "@koa/cors"; import cors from "@koa/cors";
import { apiMastodonCompatible } from './mastodon/ApiMastodonCompatibleService.js'; import { apiMastodonCompatible } from "./mastodon/ApiMastodonCompatibleService.js";
import { Instances, AccessTokens, Users } from "@/models/index.js"; import { Instances, AccessTokens, Users } from "@/models/index.js";
import config from "@/config/index.js"; import config from "@/config/index.js";
import endpoints from "./endpoints.js"; import endpoints from "./endpoints.js";
@ -19,7 +19,7 @@ import signupPending from "./private/signup-pending.js";
import discord from "./service/discord.js"; import discord from "./service/discord.js";
import github from "./service/github.js"; import github from "./service/github.js";
import twitter from "./service/twitter.js"; import twitter from "./service/twitter.js";
import {koaBody} from "koa-body"; import { koaBody } from "koa-body";
// Init app // Init app
const app = new Koa(); const app = new Koa();

View File

@ -1,32 +1,39 @@
import Router from "@koa/router"; import Router from "@koa/router";
import megalodon, { MegalodonInterface } from '@cutls/megalodon'; import megalodon, { MegalodonInterface } from "@cutls/megalodon";
import { apiAuthMastodon } from './endpoints/auth.js'; import { apiAuthMastodon } from "./endpoints/auth.js";
import { apiAccountMastodon } from './endpoints/account.js'; import { apiAccountMastodon } from "./endpoints/account.js";
import { apiStatusMastodon } from './endpoints/status.js'; import { apiStatusMastodon } from "./endpoints/status.js";
import { apiFilterMastodon } from './endpoints/filter.js'; import { apiFilterMastodon } from "./endpoints/filter.js";
import { apiTimelineMastodon } from './endpoints/timeline.js'; import { apiTimelineMastodon } from "./endpoints/timeline.js";
import { apiNotificationsMastodon } from './endpoints/notifications.js'; import { apiNotificationsMastodon } from "./endpoints/notifications.js";
import { apiSearchMastodon } from './endpoints/search.js'; import { apiSearchMastodon } from "./endpoints/search.js";
import { getInstance } from './endpoints/meta.js'; import { getInstance } from "./endpoints/meta.js";
export function getClient(BASE_URL: string, authorization: string | undefined): MegalodonInterface { export function getClient(
const accessTokenArr = authorization?.split(' ') ?? [null]; BASE_URL: string,
authorization: string | undefined,
): MegalodonInterface {
const accessTokenArr = authorization?.split(" ") ?? [null];
const accessToken = accessTokenArr[accessTokenArr.length - 1]; const accessToken = accessTokenArr[accessTokenArr.length - 1];
const generator = (megalodon as any).default const generator = (megalodon as any).default;
const client = generator('misskey', BASE_URL, accessToken) as MegalodonInterface; const client = generator(
return client "misskey",
BASE_URL,
accessToken,
) as MegalodonInterface;
return client;
} }
export function apiMastodonCompatible(router: Router): void { export function apiMastodonCompatible(router: Router): void {
apiAuthMastodon(router) apiAuthMastodon(router);
apiAccountMastodon(router) apiAccountMastodon(router);
apiStatusMastodon(router) apiStatusMastodon(router);
apiFilterMastodon(router) apiFilterMastodon(router);
apiTimelineMastodon(router) apiTimelineMastodon(router);
apiNotificationsMastodon(router) apiNotificationsMastodon(router);
apiSearchMastodon(router) apiSearchMastodon(router);
router.get('/v1/custom_emojis', async (ctx) => { router.get("/v1/custom_emojis", async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
@ -34,25 +41,24 @@ export function apiMastodonCompatible(router: Router): void {
const data = await client.getInstanceCustomEmojis(); const data = await client.getInstanceCustomEmojis();
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
router.get('/v1/instance', async (ctx) => { router.get("/v1/instance", async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); // we are using this here, because in private mode some info isnt const client = getClient(BASE_URL, accessTokens); // we are using this here, because in private mode some info isnt
// displayed without being logged in // displayed without being logged in
try { try {
const data = await client.getInstance(); const data = await client.getInstance();
ctx.body = getInstance(data.data); ctx.body = getInstance(data.data);
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
}
}

View File

@ -1,323 +1,376 @@
import megalodon, { MegalodonInterface } from '@cutls/megalodon'; import megalodon, { MegalodonInterface } from "@cutls/megalodon";
import Router from "@koa/router"; import Router from "@koa/router";
import { koaBody } from 'koa-body'; import { koaBody } from "koa-body";
import { getClient } from '../ApiMastodonCompatibleService.js'; import { getClient } from "../ApiMastodonCompatibleService.js";
import { toLimitToInt } from './timeline.js'; import { toLimitToInt } from "./timeline.js";
export function apiAccountMastodon(router: Router): void { export function apiAccountMastodon(router: Router): void {
router.get("/v1/accounts/verify_credentials", async (ctx, next) => {
router.get('/v1/accounts/verify_credentials', async (ctx, next) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; 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.verifyAccountCredentials();
const data = await client.verifyAccountCredentials(); const acct = data.data;
const acct = data.data; acct.url = `${BASE_URL}/@${acct.url}`;
acct.url = `${BASE_URL}/@${acct.url}` acct.note = "";
acct.note = '' acct.avatar_static = acct.avatar;
acct.avatar_static = acct.avatar acct.header = acct.header || "";
acct.header = acct.header || '' acct.header_static = acct.header || "";
acct.header_static = acct.header || '' acct.source = {
acct.source = { note: acct.note,
note: acct.note, fields: acct.fields,
fields: acct.fields, privacy: "public",
privacy: 'public', sensitive: false,
sensitive: false, language: "",
language: '' };
} ctx.body = acct;
ctx.body = acct } catch (e: any) {
} catch (e: any) { console.error(e);
console.error(e) console.error(e.response.data);
console.error(e.response.data) ctx.status = 401;
ctx.status =(401); ctx.body = e.response.data;
ctx.body = e.response.data; }
} });
}); router.patch("/v1/accounts/update_credentials", async (ctx) => {
router.patch('/v1/accounts/update_credentials', async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; 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.updateCredentials(
const data = await client.updateCredentials((ctx.request as any).body as any); (ctx.request as any).body as any,
ctx.body = data.data; );
} catch (e: any) { ctx.body = data.data;
console.error(e) } catch (e: any) {
console.error(e.response.data) console.error(e);
ctx.status =(401); console.error(e.response.data);
ctx.body = e.response.data; ctx.status = 401;
} ctx.body = e.response.data;
}); }
router.get<{ Params: { id: string } }>('/v1/accounts/:id', async (ctx, next) => { });
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; router.get<{ Params: { id: string } }>(
const accessTokens = ctx.headers.authorization; "/v1/accounts/:id",
const client = getClient(BASE_URL, accessTokens); async (ctx, next) => {
try { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const data = await client.getAccount(ctx.params.id); const accessTokens = ctx.headers.authorization;
ctx.body = data.data; const client = getClient(BASE_URL, accessTokens);
} catch (e: any) { try {
console.error(e) const data = await client.getAccount(ctx.params.id);
console.error(e.response.data) ctx.body = data.data;
ctx.status =(401); } catch (e: any) {
ctx.body = e.response.data; console.error(e);
} console.error(e.response.data);
}); ctx.status = 401;
router.get<{ Params: { id: string } }>('/v1/accounts/:id/statuses', async (ctx, next) => { ctx.body = e.response.data;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; }
const accessTokens = ctx.headers.authorization; },
const client = getClient(BASE_URL, accessTokens); );
try { router.get<{ Params: { id: string } }>(
const data = await client.getAccountStatuses(ctx.params.id, toLimitToInt(ctx.query as any)); "/v1/accounts/:id/statuses",
ctx.body = data.data; async (ctx, next) => {
} catch (e: any) { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
console.error(e) const accessTokens = ctx.headers.authorization;
console.error(e.response.data) const client = getClient(BASE_URL, accessTokens);
ctx.status =(401); try {
ctx.body = e.response.data; const data = await client.getAccountStatuses(
} ctx.params.id,
}); toLimitToInt(ctx.query as any),
router.get<{ Params: { id: string } }>('/v1/accounts/:id/followers', async (ctx, next) => { );
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; ctx.body = data.data;
const accessTokens = ctx.headers.authorization; } catch (e: any) {
const client = getClient(BASE_URL, accessTokens); console.error(e);
try { console.error(e.response.data);
const data = await client.getAccountFollowers(ctx.params.id, ctx.query as any); ctx.status = 401;
ctx.body = data.data; ctx.body = e.response.data;
} catch (e: any) { }
console.error(e) },
console.error(e.response.data) );
ctx.status =(401); router.get<{ Params: { id: string } }>(
ctx.body = e.response.data; "/v1/accounts/:id/followers",
} async (ctx, next) => {
}); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
router.get<{ Params: { id: string } }>('/v1/accounts/:id/following', async (ctx, next) => { const accessTokens = ctx.headers.authorization;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const client = getClient(BASE_URL, accessTokens);
const accessTokens = ctx.headers.authorization; try {
const client = getClient(BASE_URL, accessTokens); const data = await client.getAccountFollowers(
try { ctx.params.id,
const data = await client.getAccountFollowing(ctx.params.id, ctx.query as any); ctx.query as any,
ctx.body = data.data; );
} catch (e: any) { ctx.body = data.data;
console.error(e) } catch (e: any) {
console.error(e.response.data) console.error(e);
ctx.status =(401); console.error(e.response.data);
ctx.body = e.response.data; ctx.status = 401;
} ctx.body = e.response.data;
}); }
router.get<{ Params: { id: string } }>('/v1/accounts/:id/lists', async (ctx, next) => { },
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; );
const accessTokens = ctx.headers.authorization; router.get<{ Params: { id: string } }>(
const client = getClient(BASE_URL, accessTokens); "/v1/accounts/:id/following",
try { async (ctx, next) => {
const data = await client.getAccountLists(ctx.params.id); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.body = data.data; const accessTokens = ctx.headers.authorization;
} catch (e: any) { const client = getClient(BASE_URL, accessTokens);
console.error(e) try {
console.error(e.response.data) const data = await client.getAccountFollowing(
ctx.status =(401); ctx.params.id,
ctx.body = e.response.data; ctx.query as any,
} );
}); ctx.body = data.data;
router.post<{ Params: { id: string } }>('/v1/accounts/:id/follow', async (ctx, next) => { } catch (e: any) {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; console.error(e);
const accessTokens = ctx.headers.authorization; console.error(e.response.data);
const client = getClient(BASE_URL, accessTokens); ctx.status = 401;
try { ctx.body = e.response.data;
const data = await client.followAccount(ctx.params.id); }
const acct = data.data; },
acct.following = true; );
ctx.body = data.data; router.get<{ Params: { id: string } }>(
} catch (e: any) { "/v1/accounts/:id/lists",
console.error(e) async (ctx, next) => {
console.error(e.response.data) const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.status =(401); const accessTokens = ctx.headers.authorization;
ctx.body = e.response.data; const client = getClient(BASE_URL, accessTokens);
} try {
}); const data = await client.getAccountLists(ctx.params.id);
router.post<{ Params: { id: string } }>('/v1/accounts/:id/unfollow', async (ctx, next) => { ctx.body = data.data;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; } catch (e: any) {
const accessTokens = ctx.headers.authorization; console.error(e);
const client = getClient(BASE_URL, accessTokens); console.error(e.response.data);
try { ctx.status = 401;
const data = await client.unfollowAccount(ctx.params.id); ctx.body = e.response.data;
const acct = data.data; }
acct.following = false; },
ctx.body = data.data; );
} catch (e: any) { router.post<{ Params: { id: string } }>(
console.error(e) "/v1/accounts/:id/follow",
console.error(e.response.data) async (ctx, next) => {
ctx.status =(401); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.body = e.response.data; const accessTokens = ctx.headers.authorization;
} const client = getClient(BASE_URL, accessTokens);
}); try {
router.post<{ Params: { id: string } }>('/v1/accounts/:id/block', async (ctx, next) => { const data = await client.followAccount(ctx.params.id);
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const acct = data.data;
const accessTokens = ctx.headers.authorization; acct.following = true;
const client = getClient(BASE_URL, accessTokens); ctx.body = data.data;
try { } catch (e: any) {
const data = await client.blockAccount(ctx.params.id); console.error(e);
ctx.body = data.data; console.error(e.response.data);
} catch (e: any) { ctx.status = 401;
console.error(e) ctx.body = e.response.data;
console.error(e.response.data) }
ctx.status =(401); },
ctx.body = e.response.data; );
} router.post<{ Params: { id: string } }>(
}); "/v1/accounts/:id/unfollow",
router.post<{ Params: { id: string } }>('/v1/accounts/:id/unblock', async (ctx, next) => { async (ctx, next) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
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.unblockAccount(ctx.params.id); const data = await client.unfollowAccount(ctx.params.id);
ctx.body = data.data; const acct = data.data;
} catch (e: any) { acct.following = false;
console.error(e) ctx.body = data.data;
console.error(e.response.data) } catch (e: any) {
ctx.status =(401); console.error(e);
ctx.body = e.response.data; console.error(e.response.data);
} ctx.status = 401;
}); ctx.body = e.response.data;
router.post<{ Params: { id: string } }>('/v1/accounts/:id/mute', async (ctx) => { }
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; },
const accessTokens = ctx.headers.authorization; );
const client = getClient(BASE_URL, accessTokens); router.post<{ Params: { id: string } }>(
try { "/v1/accounts/:id/block",
const data = await client.muteAccount(ctx.params.id, (ctx.request as any).body as any); async (ctx, next) => {
ctx.body = data.data; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
} catch (e: any) { const accessTokens = ctx.headers.authorization;
console.error(e) const client = getClient(BASE_URL, accessTokens);
console.error(e.response.data) try {
ctx.status =(401); const data = await client.blockAccount(ctx.params.id);
ctx.body = e.response.data; ctx.body = data.data;
} } catch (e: any) {
}); console.error(e);
router.post<{ Params: { id: string } }>('/v1/accounts/:id/unmute', async (ctx, next) => { console.error(e.response.data);
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; ctx.status = 401;
const accessTokens = ctx.headers.authorization; ctx.body = e.response.data;
const client = getClient(BASE_URL, accessTokens); }
try { },
const data = await client.unmuteAccount(ctx.params.id); );
ctx.body = data.data; router.post<{ Params: { id: string } }>(
} catch (e: any) { "/v1/accounts/:id/unblock",
console.error(e) async (ctx, next) => {
console.error(e.response.data) const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.status =(401); const accessTokens = ctx.headers.authorization;
ctx.body = e.response.data; const client = getClient(BASE_URL, accessTokens);
} try {
}); const data = await client.unblockAccount(ctx.params.id);
router.get('/v1/accounts/relationships', async (ctx, next) => { ctx.body = data.data;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; } catch (e: any) {
const accessTokens = ctx.headers.authorization; console.error(e);
const client = getClient(BASE_URL, accessTokens); console.error(e.response.data);
try { ctx.status = 401;
const idsRaw = (ctx.query as any)['id[]'] ctx.body = e.response.data;
const ids = typeof idsRaw === 'string' ? [idsRaw] : idsRaw }
const data = await client.getRelationships(ids) as any; },
ctx.body = data.data; );
} catch (e: any) { router.post<{ Params: { id: string } }>(
console.error(e) "/v1/accounts/:id/mute",
console.error(e.response.data) async (ctx) => {
ctx.status =(401); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.body = e.response.data; const accessTokens = ctx.headers.authorization;
} const client = getClient(BASE_URL, accessTokens);
}); try {
router.get('/v1/bookmarks', async (ctx, next) => { const data = await client.muteAccount(
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; ctx.params.id,
const accessTokens = ctx.headers.authorization; (ctx.request as any).body as any,
const client = getClient(BASE_URL, accessTokens); );
try { ctx.body = data.data;
const data = await client.getBookmarks(ctx.query as any) as any; } catch (e: any) {
ctx.body = data.data; console.error(e);
} catch (e: any) { console.error(e.response.data);
console.error(e) ctx.status = 401;
console.error(e.response.data) ctx.body = e.response.data;
ctx.status =(401); }
ctx.body = e.response.data; },
} );
}); router.post<{ Params: { id: string } }>(
router.get('/v1/favourites', async (ctx, next) => { "/v1/accounts/:id/unmute",
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; async (ctx, next) => {
const accessTokens = ctx.headers.authorization; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const client = getClient(BASE_URL, accessTokens); const accessTokens = ctx.headers.authorization;
try { const client = getClient(BASE_URL, accessTokens);
const data = await client.getFavourites(ctx.query as any); try {
ctx.body = data.data; const data = await client.unmuteAccount(ctx.params.id);
} catch (e: any) { ctx.body = data.data;
console.error(e) } catch (e: any) {
console.error(e.response.data) console.error(e);
ctx.status =(401); console.error(e.response.data);
ctx.body = e.response.data; ctx.status = 401;
} ctx.body = e.response.data;
}); }
router.get('/v1/mutes', async (ctx, next) => { },
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; );
const accessTokens = ctx.headers.authorization; router.get("/v1/accounts/relationships", async (ctx, next) => {
const client = getClient(BASE_URL, accessTokens); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
try { const accessTokens = ctx.headers.authorization;
const data = await client.getMutes(ctx.query as any); const client = getClient(BASE_URL, accessTokens);
ctx.body = data.data; try {
} catch (e: any) { const idsRaw = (ctx.query as any)["id[]"];
console.error(e) const ids = typeof idsRaw === "string" ? [idsRaw] : idsRaw;
console.error(e.response.data) const data = (await client.getRelationships(ids)) as any;
ctx.status =(401); ctx.body = data.data;
ctx.body = e.response.data; } catch (e: any) {
} console.error(e);
}); console.error(e.response.data);
router.get('/v1/blocks', async (ctx, next) => { ctx.status = 401;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; ctx.body = e.response.data;
const accessTokens = ctx.headers.authorization; }
const client = getClient(BASE_URL, accessTokens); });
try { router.get("/v1/bookmarks", async (ctx, next) => {
const data = await client.getBlocks(ctx.query as any); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.body = data.data; const accessTokens = ctx.headers.authorization;
} catch (e: any) { const client = getClient(BASE_URL, accessTokens);
console.error(e) try {
console.error(e.response.data) const data = (await client.getBookmarks(ctx.query as any)) as any;
ctx.status =(401); ctx.body = data.data;
ctx.body = e.response.data; } catch (e: any) {
} console.error(e);
}); console.error(e.response.data);
router.get('/v1/follow_ctxs', async (ctx, next) => { ctx.status = 401;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; ctx.body = e.response.data;
const accessTokens = ctx.headers.authorization; }
const client = getClient(BASE_URL, accessTokens); });
try { router.get("/v1/favourites", async (ctx, next) => {
const data = await client.getFollowRequests((ctx.query as any || { limit: 20 }).limit); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.body = data.data; const accessTokens = ctx.headers.authorization;
} catch (e: any) { const client = getClient(BASE_URL, accessTokens);
console.error(e) try {
console.error(e.response.data) const data = await client.getFavourites(ctx.query as any);
ctx.status =(401); ctx.body = data.data;
ctx.body = e.response.data; } catch (e: any) {
} console.error(e);
}); console.error(e.response.data);
router.post<{ Params: { id: string } }>('/v1/follow_ctxs/:id/authorize', async (ctx, next) => { ctx.status = 401;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; ctx.body = e.response.data;
const accessTokens = ctx.headers.authorization; }
const client = getClient(BASE_URL, accessTokens); });
try { router.get("/v1/mutes", async (ctx, next) => {
const data = await client.acceptFollowRequest(ctx.params.id); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.body = data.data; const accessTokens = ctx.headers.authorization;
} catch (e: any) { const client = getClient(BASE_URL, accessTokens);
console.error(e) try {
console.error(e.response.data) const data = await client.getMutes(ctx.query as any);
ctx.status =(401); ctx.body = data.data;
ctx.body = e.response.data; } catch (e: any) {
} console.error(e);
}); console.error(e.response.data);
router.post<{ Params: { id: string } }>('/v1/follow_ctxs/:id/reject', async (ctx, next) => { ctx.status = 401;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; ctx.body = e.response.data;
const accessTokens = ctx.headers.authorization; }
const client = getClient(BASE_URL, accessTokens); });
try { router.get("/v1/blocks", async (ctx, next) => {
const data = await client.rejectFollowRequest(ctx.params.id); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.body = data.data; const accessTokens = ctx.headers.authorization;
} catch (e: any) { const client = getClient(BASE_URL, accessTokens);
console.error(e) try {
console.error(e.response.data) const data = await client.getBlocks(ctx.query as any);
ctx.status =(401); ctx.body = data.data;
ctx.body = e.response.data; } catch (e: any) {
} console.error(e);
}); console.error(e.response.data);
ctx.status = 401;
} ctx.body = e.response.data;
}
});
router.get("/v1/follow_ctxs", async (ctx, next) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.getFollowRequests(
((ctx.query as any) || { limit: 20 }).limit,
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
ctx.status = 401;
ctx.body = e.response.data;
}
});
router.post<{ Params: { id: string } }>(
"/v1/follow_ctxs/:id/authorize",
async (ctx, next) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.acceptFollowRequest(ctx.params.id);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.post<{ Params: { id: string } }>(
"/v1/follow_ctxs/:id/reject",
async (ctx, next) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.rejectFollowRequest(ctx.params.id);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
}

View File

@ -1,82 +1,84 @@
import megalodon, { MegalodonInterface } from '@cutls/megalodon'; import megalodon, { MegalodonInterface } from "@cutls/megalodon";
import Router from "@koa/router"; import Router from "@koa/router";
import { koaBody } from 'koa-body'; import { koaBody } from "koa-body";
import { getClient } from '../ApiMastodonCompatibleService.js'; import { getClient } from "../ApiMastodonCompatibleService.js";
import bodyParser from "koa-bodyparser"; import bodyParser from "koa-bodyparser";
const readScope = [ const readScope = [
'read:account', "read:account",
'read:drive', "read:drive",
'read:blocks', "read:blocks",
'read:favorites', "read:favorites",
'read:following', "read:following",
'read:messaging', "read:messaging",
'read:mutes', "read:mutes",
'read:notifications', "read:notifications",
'read:reactions', "read:reactions",
'read:pages', "read:pages",
'read:page-likes', "read:page-likes",
'read:user-groups', "read:user-groups",
'read:channels', "read:channels",
'read:gallery', "read:gallery",
'read:gallery-likes' "read:gallery-likes",
] ];
const writeScope = [ const writeScope = [
'write:account', "write:account",
'write:drive', "write:drive",
'write:blocks', "write:blocks",
'write:favorites', "write:favorites",
'write:following', "write:following",
'write:messaging', "write:messaging",
'write:mutes', "write:mutes",
'write:notes', "write:notes",
'write:notifications', "write:notifications",
'write:reactions', "write:reactions",
'write:votes', "write:votes",
'write:pages', "write:pages",
'write:page-likes', "write:page-likes",
'write:user-groups', "write:user-groups",
'write:channels', "write:channels",
'write:gallery', "write:gallery",
'write:gallery-likes' "write:gallery-likes",
] ];
export function apiAuthMastodon(router: Router): void { export function apiAuthMastodon(router: Router): void {
router.post("/v1/apps", async (ctx) => {
router.post('/v1/apps', async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
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 {
let scope = body.scopes let scope = body.scopes;
console.log(body) console.log(body);
if (typeof scope === 'string') scope = scope.split(' ') if (typeof scope === "string") scope = scope.split(" ");
const pushScope = new Set<string>() const pushScope = new Set<string>();
for (const s of scope) { for (const s of scope) {
if (s.match(/^read/)) for (const r of readScope) pushScope.add(r) if (s.match(/^read/)) for (const r of readScope) pushScope.add(r);
if (s.match(/^write/)) for (const r of writeScope) pushScope.add(r) if (s.match(/^write/)) for (const r of writeScope) pushScope.add(r);
} }
const scopeArr = Array.from(pushScope) const scopeArr = Array.from(pushScope);
let red = body.redirect_uris let red = body.redirect_uris;
if (red === 'urn:ietf:wg:oauth:2.0:oob') { if (red === "urn:ietf:wg:oauth:2.0:oob") {
red = 'https://thedesk.top/hello.html' red = "https://thedesk.top/hello.html";
} }
const appData = await client.registerApp(body.client_name, { scopes: scopeArr, redirect_uris: red, website: body.website }); const appData = await client.registerApp(body.client_name, {
scopes: scopeArr,
redirect_uris: red,
website: body.website,
});
ctx.body = { ctx.body = {
id: appData.id, id: appData.id,
name: appData.name, name: appData.name,
website: appData.website, website: appData.website,
redirect_uri: red, redirect_uri: red,
client_id: Buffer.from(appData.url || '').toString('base64'), client_id: Buffer.from(appData.url || "").toString("base64"),
client_secret: appData.clientSecret, client_secret: appData.clientSecret,
} };
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
} }

View File

@ -1,10 +1,9 @@
import megalodon, { MegalodonInterface } from '@cutls/megalodon'; import megalodon, { MegalodonInterface } from "@cutls/megalodon";
import Router from "@koa/router"; import Router from "@koa/router";
import { getClient } from '../ApiMastodonCompatibleService.js'; import { getClient } from "../ApiMastodonCompatibleService.js";
export function apiFilterMastodon(router: Router): void { export function apiFilterMastodon(router: Router): void {
router.get("/v1/filters", async (ctx) => {
router.get('/v1/filters', async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
@ -13,13 +12,13 @@ export function apiFilterMastodon(router: Router): void {
const data = await client.getFilters(); const data = await client.getFilters();
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
router.get('/v1/filters/:id', async (ctx) => { router.get("/v1/filters/:id", async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
@ -28,13 +27,13 @@ export function apiFilterMastodon(router: Router): void {
const data = await client.getFilter(ctx.params.id); const data = await client.getFilter(ctx.params.id);
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
router.post('/v1/filters', async (ctx) => { router.post("/v1/filters", async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
@ -43,28 +42,32 @@ export function apiFilterMastodon(router: Router): void {
const data = await client.createFilter(body.phrase, body.context, body); const data = await client.createFilter(body.phrase, body.context, body);
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
router.post('/v1/filters/:id', async (ctx) => { router.post("/v1/filters/:id", async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
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.updateFilter(ctx.params.id, body.phrase, body.context); const data = await client.updateFilter(
ctx.params.id,
body.phrase,
body.context,
);
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
router.delete('/v1/filters/:id', async (ctx) => { router.delete("/v1/filters/:id", async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
@ -73,10 +76,9 @@ export function apiFilterMastodon(router: Router): void {
const data = await client.deleteFilter(ctx.params.id); const data = await client.deleteFilter(ctx.params.id);
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
} }

View File

@ -1,16 +1,15 @@
import megalodon, { MegalodonInterface } from '@cutls/megalodon'; import megalodon, { MegalodonInterface } from "@cutls/megalodon";
import Router from "@koa/router"; import Router from "@koa/router";
import { koaBody } from 'koa-body'; import { koaBody } from "koa-body";
import { getClient } from '../ApiMastodonCompatibleService.js'; import { getClient } from "../ApiMastodonCompatibleService.js";
import { toTextWithReaction } from './timeline.js'; import { toTextWithReaction } from "./timeline.js";
function toLimitToInt(q: any) { function toLimitToInt(q: any) {
if (q.limit) if (typeof q.limit === 'string') q.limit = parseInt(q.limit, 10) if (q.limit) if (typeof q.limit === "string") q.limit = parseInt(q.limit, 10);
return q return q;
} }
export function apiNotificationsMastodon(router: Router): void { export function apiNotificationsMastodon(router: Router): void {
router.get("/v1/notifications", async (ctx) => {
router.get('/v1/notifications', async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
@ -19,23 +18,26 @@ export function apiNotificationsMastodon(router: Router): void {
const data = await client.getNotifications(toLimitToInt(ctx.query)); const data = await client.getNotifications(toLimitToInt(ctx.query));
const notfs = data.data; const notfs = data.data;
const ret = notfs.map((n) => { const ret = notfs.map((n) => {
if(n.type !== 'follow' && n.type !== 'follow_request') { if (n.type !== "follow" && n.type !== "follow_request") {
if (n.type === 'reaction') n.type = 'favourite' if (n.type === "reaction") n.type = "favourite";
n.status = toTextWithReaction(n.status ? [n.status] : [], ctx.hostname)[0] n.status = toTextWithReaction(
return n n.status ? [n.status] : [],
} else { ctx.hostname,
return n )[0];
} return n;
}) } else {
return n;
}
});
ctx.body = ret; ctx.body = ret;
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
router.get('/v1/notification/:id', async (ctx) => { router.get("/v1/notification/:id", async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
@ -43,20 +45,20 @@ export function apiNotificationsMastodon(router: Router): void {
try { try {
const dataRaw = await client.getNotification(ctx.params.id); const dataRaw = await client.getNotification(ctx.params.id);
const data = dataRaw.data; const data = dataRaw.data;
if(data.type !== 'follow' && data.type !== 'follow_request') { if (data.type !== "follow" && data.type !== "follow_request") {
if (data.type === 'reaction') data.type = 'favourite' if (data.type === "reaction") data.type = "favourite";
ctx.body = toTextWithReaction([data as any], ctx.request.hostname)[0] ctx.body = toTextWithReaction([data as any], ctx.request.hostname)[0];
} else { } else {
ctx.body = data ctx.body = data;
} }
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
router.post('/v1/notifications/clear', async (ctx) => { router.post("/v1/notifications/clear", async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
@ -65,13 +67,13 @@ export function apiNotificationsMastodon(router: Router): void {
const data = await client.dismissNotifications(); const data = await client.dismissNotifications();
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
router.post('/v1/notification/:id/dismiss', async (ctx) => { router.post("/v1/notification/:id/dismiss", async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
@ -80,10 +82,9 @@ export function apiNotificationsMastodon(router: Router): void {
const data = await client.dismissNotification(ctx.params.id); const data = await client.dismissNotification(ctx.params.id);
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
} }

View File

@ -1,24 +1,22 @@
import megalodon, { MegalodonInterface } from '@cutls/megalodon'; import megalodon, { MegalodonInterface } from "@cutls/megalodon";
import Router from "@koa/router"; import Router from "@koa/router";
import { getClient } from '../ApiMastodonCompatibleService.js'; import { getClient } from "../ApiMastodonCompatibleService.js";
export function apiSearchMastodon(router: Router): void { export function apiSearchMastodon(router: Router): void {
router.get("/v1/search", async (ctx) => {
router.get('/v1/search', async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization; const accessTokens = ctx.request.headers.authorization;
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 query: any = ctx.query const query: any = ctx.query;
const type = query.type || '' const type = query.type || "";
const data = await client.search(query.q, type, query); const data = await client.search(query.q, type, query);
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e);
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
} }

View File

@ -1,402 +1,483 @@
import Router from "@koa/router"; import Router from "@koa/router";
import megalodon, { MegalodonInterface } from '@cutls/megalodon'; import megalodon, { MegalodonInterface } from "@cutls/megalodon";
import { getClient } from '../ApiMastodonCompatibleService.js'; import { getClient } from "../ApiMastodonCompatibleService.js";
import fs from 'fs' import fs from "fs";
import { pipeline } from 'node:stream'; import { pipeline } from "node:stream";
import { promisify } from 'node:util'; import { promisify } from "node:util";
import { createTemp } from '@/misc/create-temp.js'; import { createTemp } from "@/misc/create-temp.js";
import { emojiRegex, emojiRegexAtStartToEnd } from '@/misc/emoji-regex.js'; import { emojiRegex, emojiRegexAtStartToEnd } from "@/misc/emoji-regex.js";
import axios from 'axios'; import axios from "axios";
const pump = promisify(pipeline); const pump = promisify(pipeline);
export function apiStatusMastodon(router: Router): void { export function apiStatusMastodon(router: Router): void {
router.post('/v1/statuses', async (ctx, reply) => { router.post("/v1/statuses", async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
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 body: any = ctx.request.body const body: any = ctx.request.body;
const text = body.status const text = body.status;
const removed = text.replace(/@\S+/g, '').replaceAll(' ', '') const removed = text.replace(/@\S+/g, "").replaceAll(" ", "");
const isDefaultEmoji = emojiRegexAtStartToEnd.test(removed) const isDefaultEmoji = emojiRegexAtStartToEnd.test(removed);
const isCustomEmoji = /^:[a-zA-Z0-9@_]+:$/.test(removed) const isCustomEmoji = /^:[a-zA-Z0-9@_]+:$/.test(removed);
if (body.in_reply_to_id && isDefaultEmoji || isCustomEmoji) { if ((body.in_reply_to_id && isDefaultEmoji) || isCustomEmoji) {
const a = await client.createEmojiReaction(body.in_reply_to_id, removed) const a = await client.createEmojiReaction(
ctx.body = a.data body.in_reply_to_id,
} removed,
if (body.in_reply_to_id && removed === '/unreact') { );
try { ctx.body = a.data;
const id = body.in_reply_to_id }
const post = await client.getStatus(id) if (body.in_reply_to_id && removed === "/unreact") {
const react = post.data.emoji_reactions.filter((e) => e.me)[0].name try {
const data = await client.deleteEmojiReaction(id, react); const id = body.in_reply_to_id;
ctx.body = data.data; const post = await client.getStatus(id);
} catch (e: any) { const react = post.data.emoji_reactions.filter((e) => e.me)[0].name;
console.error(e) const data = await client.deleteEmojiReaction(id, react);
ctx.status = (401); ctx.body = data.data;
ctx.body = e.response.data; } catch (e: any) {
} console.error(e);
} ctx.status = 401;
if (!body.media_ids) body.media_ids = undefined ctx.body = e.response.data;
if (body.media_ids && !body.media_ids.length) body.media_ids = undefined }
const data = await client.postStatus(text, body); }
ctx.body = data.data; if (!body.media_ids) body.media_ids = undefined;
} catch (e: any) { if (body.media_ids && !body.media_ids.length) body.media_ids = undefined;
console.error(e) const data = await client.postStatus(text, body);
ctx.status = (401); ctx.body = data.data;
ctx.body = e.response.data; } catch (e: any) {
} console.error(e);
}); ctx.status = 401;
router.get<{ Params: { id: string } }>('/v1/statuses/:id', async (ctx, reply) => { ctx.body = e.response.data;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; }
const accessTokens = ctx.headers.authorization; });
const client = getClient(BASE_URL, accessTokens); router.get<{ Params: { id: string } }>(
try { "/v1/statuses/:id",
const data = await client.getStatus(ctx.params.id); async (ctx, reply) => {
ctx.body = data.data; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
} catch (e: any) { const accessTokens = ctx.headers.authorization;
console.error(e) const client = getClient(BASE_URL, accessTokens);
ctx.status = (401); try {
ctx.body = e.response.data; const data = await client.getStatus(ctx.params.id);
} ctx.body = data.data;
}); } catch (e: any) {
router.delete<{ Params: { id: string } }>('/v1/statuses/:id', async (ctx, reply) => { console.error(e);
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; ctx.status = 401;
const accessTokens = ctx.headers.authorization; ctx.body = e.response.data;
const client = getClient(BASE_URL, accessTokens); }
try { },
const data = await client.deleteStatus(ctx.params.id); );
ctx.body = data.data; router.delete<{ Params: { id: string } }>(
} catch (e: any) { "/v1/statuses/:id",
console.error(e) async (ctx, reply) => {
ctx.status = (401); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.body = e.response.data; const accessTokens = ctx.headers.authorization;
} const client = getClient(BASE_URL, accessTokens);
}); try {
interface IReaction { const data = await client.deleteStatus(ctx.params.id);
id: string ctx.body = data.data;
createdAt: string } catch (e: any) {
user: MisskeyEntity.User, console.error(e);
type: string ctx.status = 401;
} ctx.body = e.response.data;
router.get<{ Params: { id: string } }>('/v1/statuses/:id/context', async (ctx, reply) => { }
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; },
const accessTokens = ctx.headers.authorization; );
const client = getClient(BASE_URL, accessTokens); interface IReaction {
try { id: string;
const id = ctx.params.id createdAt: string;
const data = await client.getStatusContext(id, ctx.query as any); user: MisskeyEntity.User;
const status = await client.getStatus(id); type: string;
const reactionsAxios = await axios.get(`${BASE_URL}/api/notes/reactions?noteId=${id}`) }
const reactions: IReaction[] = reactionsAxios.data router.get<{ Params: { id: string } }>(
const text = reactions.map((r) => `${r.type.replace('@.', '')} ${r.user.username}`).join('<br />') "/v1/statuses/:id/context",
data.data.descendants.unshift(statusModel(status.data.id, status.data.account.id, status.data.emojis, text)) async (ctx, reply) => {
ctx.body = data.data; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
} catch (e: any) { const accessTokens = ctx.headers.authorization;
console.error(e) const client = getClient(BASE_URL, accessTokens);
ctx.status = (401); try {
ctx.body = e.response.data; const id = ctx.params.id;
} const data = await client.getStatusContext(id, ctx.query as any);
}); const status = await client.getStatus(id);
router.get<{ Params: { id: string } }>('/v1/statuses/:id/reblogged_by', async (ctx, reply) => { const reactionsAxios = await axios.get(
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; `${BASE_URL}/api/notes/reactions?noteId=${id}`,
const accessTokens = ctx.headers.authorization; );
const client = getClient(BASE_URL, accessTokens); const reactions: IReaction[] = reactionsAxios.data;
try { const text = reactions
const data = await client.getStatusRebloggedBy(ctx.params.id); .map((r) => `${r.type.replace("@.", "")} ${r.user.username}`)
ctx.body = data.data; .join("<br />");
} catch (e: any) { data.data.descendants.unshift(
console.error(e) statusModel(
ctx.status = (401); status.data.id,
ctx.body = e.response.data; status.data.account.id,
} status.data.emojis,
}); text,
router.get<{ Params: { id: string } }>('/v1/statuses/:id/favourited_by', async (ctx, reply) => { ),
ctx.body = [] );
}); ctx.body = data.data;
router.post<{ Params: { id: string } }>('/v1/statuses/:id/favourite', async (ctx, reply) => { } catch (e: any) {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; console.error(e);
const accessTokens = ctx.headers.authorization; ctx.status = 401;
const client = getClient(BASE_URL, accessTokens); ctx.body = e.response.data;
const react = await getFirstReaction(BASE_URL, accessTokens); }
try { },
const a = await client.createEmojiReaction(ctx.params.id, react) as any; );
//const data = await client.favouriteStatus(ctx.params.id) as any; router.get<{ Params: { id: string } }>(
ctx.body = a.data; "/v1/statuses/:id/reblogged_by",
} catch (e: any) { async (ctx, reply) => {
console.error(e) const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
console.error(e.response.data) const accessTokens = ctx.headers.authorization;
ctx.status = (401); const client = getClient(BASE_URL, accessTokens);
ctx.body = e.response.data; try {
} const data = await client.getStatusRebloggedBy(ctx.params.id);
}); ctx.body = data.data;
router.post<{ Params: { id: string } }>('/v1/statuses/:id/unfavourite', async (ctx, reply) => { } catch (e: any) {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; console.error(e);
const accessTokens = ctx.headers.authorization; ctx.status = 401;
const client = getClient(BASE_URL, accessTokens); ctx.body = e.response.data;
const react = await getFirstReaction(BASE_URL, accessTokens); }
try { },
const data = await client.deleteEmojiReaction(ctx.params.id, react); );
ctx.body = data.data; router.get<{ Params: { id: string } }>(
} catch (e: any) { "/v1/statuses/:id/favourited_by",
console.error(e) async (ctx, reply) => {
ctx.status = (401); ctx.body = [];
ctx.body = e.response.data; },
} );
}); router.post<{ Params: { id: string } }>(
"/v1/statuses/:id/favourite",
async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
const react = await getFirstReaction(BASE_URL, accessTokens);
try {
const a = (await client.createEmojiReaction(
ctx.params.id,
react,
)) as any;
//const data = await client.favouriteStatus(ctx.params.id) as any;
ctx.body = a.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.post<{ Params: { id: string } }>(
"/v1/statuses/:id/unfavourite",
async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
const react = await getFirstReaction(BASE_URL, accessTokens);
try {
const data = await client.deleteEmojiReaction(ctx.params.id, react);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.post<{ Params: { id: string } }>('/v1/statuses/:id/reblog', async (ctx, reply) => { router.post<{ Params: { id: string } }>(
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; "/v1/statuses/:id/reblog",
const accessTokens = ctx.headers.authorization; async (ctx, reply) => {
const client = getClient(BASE_URL, accessTokens); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
try { const accessTokens = ctx.headers.authorization;
const data = await client.reblogStatus(ctx.params.id); const client = getClient(BASE_URL, accessTokens);
ctx.body = data.data; try {
} catch (e: any) { const data = await client.reblogStatus(ctx.params.id);
console.error(e) ctx.body = data.data;
ctx.status = (401); } catch (e: any) {
ctx.body = e.response.data; console.error(e);
} ctx.status = 401;
}); ctx.body = e.response.data;
}
},
);
router.post<{ Params: { id: string } }>('/v1/statuses/:id/unreblog', async (ctx, reply) => { router.post<{ Params: { id: string } }>(
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; "/v1/statuses/:id/unreblog",
const accessTokens = ctx.headers.authorization; async (ctx, reply) => {
const client = getClient(BASE_URL, accessTokens); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
try { const accessTokens = ctx.headers.authorization;
const data = await client.unreblogStatus(ctx.params.id); const client = getClient(BASE_URL, accessTokens);
ctx.body = data.data; try {
} catch (e: any) { const data = await client.unreblogStatus(ctx.params.id);
console.error(e) ctx.body = data.data;
ctx.status = (401); } catch (e: any) {
ctx.body = e.response.data; console.error(e);
} ctx.status = 401;
}); ctx.body = e.response.data;
}
},
);
router.post<{ Params: { id: string } }>('/v1/statuses/:id/bookmark', async (ctx, reply) => { router.post<{ Params: { id: string } }>(
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; "/v1/statuses/:id/bookmark",
const accessTokens = ctx.headers.authorization; async (ctx, reply) => {
const client = getClient(BASE_URL, accessTokens); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
try { const accessTokens = ctx.headers.authorization;
const data = await client.bookmarkStatus(ctx.params.id); const client = getClient(BASE_URL, accessTokens);
ctx.body = data.data; try {
} catch (e: any) { const data = await client.bookmarkStatus(ctx.params.id);
console.error(e) ctx.body = data.data;
ctx.status = (401); } catch (e: any) {
ctx.body = e.response.data; console.error(e);
} ctx.status = 401;
}); ctx.body = e.response.data;
}
},
);
router.post<{ Params: { id: string } }>('/v1/statuses/:id/unbookmark', async (ctx, reply) => { router.post<{ Params: { id: string } }>(
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; "/v1/statuses/:id/unbookmark",
const accessTokens = ctx.headers.authorization; async (ctx, reply) => {
const client = getClient(BASE_URL, accessTokens); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
try { const accessTokens = ctx.headers.authorization;
const data = await client.unbookmarkStatus(ctx.params.id) as any; const client = getClient(BASE_URL, accessTokens);
ctx.body = data.data; try {
} catch (e: any) { const data = (await client.unbookmarkStatus(ctx.params.id)) as any;
console.error(e) ctx.body = data.data;
ctx.status = (401); } catch (e: any) {
ctx.body = e.response.data; console.error(e);
} ctx.status = 401;
}); ctx.body = e.response.data;
}
},
);
router.post<{ Params: { id: string } }>('/v1/statuses/:id/pin', async (ctx, reply) => { router.post<{ Params: { id: string } }>(
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; "/v1/statuses/:id/pin",
const accessTokens = ctx.headers.authorization; async (ctx, reply) => {
const client = getClient(BASE_URL, accessTokens); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
try { const accessTokens = ctx.headers.authorization;
const data = await client.pinStatus(ctx.params.id); const client = getClient(BASE_URL, accessTokens);
ctx.body = data.data; try {
} catch (e: any) { const data = await client.pinStatus(ctx.params.id);
console.error(e) ctx.body = data.data;
ctx.status = (401); } catch (e: any) {
ctx.body = e.response.data; console.error(e);
} ctx.status = 401;
}); ctx.body = e.response.data;
}
router.post<{ Params: { id: string } }>('/v1/statuses/:id/unpin', async (ctx, reply) => { },
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; );
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.unpinStatus(ctx.params.id);
ctx.body = data.data;
} catch (e: any) {
console.error(e)
ctx.status = (401);
ctx.body = e.response.data;
}
});
router.post('/v1/media', async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const multipartData = await ctx.file;
if (!multipartData) {
ctx.body = { error: 'No image' };
return;
}
const [path] = await createTemp();
await pump(multipartData.buffer, fs.createWriteStream(path));
const image = fs.readFileSync(path);
const data = await client.uploadMedia(image);
ctx.body = data.data;
} catch (e: any) {
console.error(e)
ctx.status = (401);
ctx.body = e.response.data;
}
});
router.post('/v2/media', async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const multipartData = await ctx.file;
if (!multipartData) {
ctx.body = { error: 'No image' };
return;
}
const [path] = await createTemp();
await pump(multipartData.buffer, fs.createWriteStream(path));
const image = fs.readFileSync(path);
const data = await client.uploadMedia(image);
ctx.body = data.data;
} catch (e: any) {
console.error(e)
ctx.status = (401);
ctx.body = e.response.data;
}
});
router.get<{ Params: { id: string } }>('/v1/media/:id', async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.getMedia(ctx.params.id);
ctx.body = data.data;
} catch (e: any) {
console.error(e)
ctx.status = (401);
ctx.body = e.response.data;
}
});
router.put<{ Params: { id: string } }>('/v1/media/:id',async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.updateMedia(ctx.params.id, ctx.request.body as any);
ctx.body = data.data;
} catch (e: any) {
console.error(e)
ctx.status = (401);
ctx.body = e.response.data;
}
});
router.get<{ Params: { id: string } }>('/v1/polls/:id', async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.getPoll(ctx.params.id);
ctx.body = data.data;
} catch (e: any) {
console.error(e)
ctx.status = (401);
ctx.body = e.response.data;
}
});
router.post<{ Params: { id: string } }>('/v1/polls/:id/votes', async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.votePoll(ctx.params.id, (ctx.request.body as any).choices);
ctx.body = data.data;
} catch (e: any) {
console.error(e)
ctx.status = (401);
ctx.body = e.response.data;
}
});
router.post<{ Params: { id: string } }>(
"/v1/statuses/:id/unpin",
async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.unpinStatus(ctx.params.id);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.post("/v1/media", async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const multipartData = await ctx.file;
if (!multipartData) {
ctx.body = { error: "No image" };
return;
}
const [path] = await createTemp();
await pump(multipartData.buffer, fs.createWriteStream(path));
const image = fs.readFileSync(path);
const data = await client.uploadMedia(image);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
});
router.post("/v2/media", async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const multipartData = await ctx.file;
if (!multipartData) {
ctx.body = { error: "No image" };
return;
}
const [path] = await createTemp();
await pump(multipartData.buffer, fs.createWriteStream(path));
const image = fs.readFileSync(path);
const data = await client.uploadMedia(image);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
});
router.get<{ Params: { id: string } }>(
"/v1/media/:id",
async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.getMedia(ctx.params.id);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.put<{ Params: { id: string } }>(
"/v1/media/:id",
async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.updateMedia(
ctx.params.id,
ctx.request.body as any,
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.get<{ Params: { id: string } }>(
"/v1/polls/:id",
async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.getPoll(ctx.params.id);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.post<{ Params: { id: string } }>(
"/v1/polls/:id/votes",
async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.votePoll(
ctx.params.id,
(ctx.request.body as any).choices,
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
} }
async function getFirstReaction(BASE_URL: string, accessTokens: string | undefined) { async function getFirstReaction(
const accessTokenArr = accessTokens?.split(' ') ?? [null]; BASE_URL: string,
const accessToken = accessTokenArr[accessTokenArr.length - 1]; accessTokens: string | undefined,
let react = '👍' ) {
try { const accessTokenArr = accessTokens?.split(" ") ?? [null];
const api = await axios.post(`${BASE_URL}/api/i/registry/get-unsecure`, { const accessToken = accessTokenArr[accessTokenArr.length - 1];
scope: ['client', 'base'], let react = "👍";
key: 'reactions', try {
i: accessToken const api = await axios.post(`${BASE_URL}/api/i/registry/get-unsecure`, {
}) scope: ["client", "base"],
const reactRaw = api.data key: "reactions",
react = Array.isArray(reactRaw) ? api.data[0] : '👍' i: accessToken,
console.log(api.data) });
return react const reactRaw = api.data;
} catch (e) { react = Array.isArray(reactRaw) ? api.data[0] : "👍";
return react console.log(api.data);
} return react;
} catch (e) {
return react;
}
} }
export function statusModel(id: string | null, acctId: string | null, emojis: MastodonEntity.Emoji[], content: string) { export function statusModel(
const now = "1970-01-02T00:00:00.000Z" id: string | null,
return { acctId: string | null,
id: '9atm5frjhb', emojis: MastodonEntity.Emoji[],
uri: 'https://http.cat/404', // "" content: string,
url: 'https://http.cat/404', // "", ) {
account: { const now = "1970-01-02T00:00:00.000Z";
id: '9arzuvv0sw', return {
username: 'ReactionBot', id: "9atm5frjhb",
acct: 'ReactionBot', uri: "https://http.cat/404", // ""
display_name: 'ReactionOfThisPost', url: "https://http.cat/404", // "",
locked: false, account: {
created_at: now, id: "9arzuvv0sw",
followers_count: 0, username: "ReactionBot",
following_count: 0, acct: "ReactionBot",
statuses_count: 0, display_name: "ReactionOfThisPost",
note: '', locked: false,
url: 'https://http.cat/404', created_at: now,
avatar: 'https://http.cat/404', followers_count: 0,
avatar_static: 'https://http.cat/404', following_count: 0,
header: 'https://http.cat/404', // "" statuses_count: 0,
header_static: 'https://http.cat/404', // "" note: "",
emojis: [], url: "https://http.cat/404",
fields: [], avatar: "https://http.cat/404",
moved: null, avatar_static: "https://http.cat/404",
bot: false, header: "https://http.cat/404", // ""
}, header_static: "https://http.cat/404", // ""
in_reply_to_id: id, emojis: [],
in_reply_to_account_id: acctId, fields: [],
reblog: null, moved: null,
content: `<p>${content}</p>`, bot: false,
plain_content: null, },
created_at: now, in_reply_to_id: id,
emojis: emojis, in_reply_to_account_id: acctId,
replies_count: 0, reblog: null,
reblogs_count: 0, content: `<p>${content}</p>`,
favourites_count: 0, plain_content: null,
favourited: false, created_at: now,
reblogged: false, emojis: emojis,
muted: false, replies_count: 0,
sensitive: false, reblogs_count: 0,
spoiler_text: '', favourites_count: 0,
visibility: 'public' as const, favourited: false,
media_attachments: [], reblogged: false,
mentions: [], muted: false,
tags: [], sensitive: false,
card: null, spoiler_text: "",
poll: null, visibility: "public" as const,
application: null, media_attachments: [],
language: null, mentions: [],
pinned: false, tags: [],
emoji_reactions: [], card: null,
bookmarked: false, poll: null,
quote: false, application: null,
} language: null,
} pinned: false,
emoji_reactions: [],
bookmarked: false,
quote: false,
};
}

View File

@ -1,245 +1,305 @@
import Router from "@koa/router"; import Router from "@koa/router";
import megalodon, { Entity, MegalodonInterface } from '@cutls/megalodon'; import megalodon, { Entity, MegalodonInterface } from "@cutls/megalodon";
import { getClient } from '../ApiMastodonCompatibleService.js' import { getClient } from "../ApiMastodonCompatibleService.js";
import { statusModel } from './status.js'; import { statusModel } from "./status.js";
import Autolinker from 'autolinker'; import Autolinker from "autolinker";
import { ParsedUrlQuery } from "querystring"; import { ParsedUrlQuery } from "querystring";
export function toLimitToInt(q: ParsedUrlQuery) { export function toLimitToInt(q: ParsedUrlQuery) {
if (q.limit) if (typeof q.limit === 'string') q.limit = parseInt(q.limit, 10).toString() if (q.limit)
return q if (typeof q.limit === "string") q.limit = parseInt(q.limit, 10).toString();
return q;
} }
export function toTextWithReaction(status: Entity.Status[], host: string) { export function toTextWithReaction(status: Entity.Status[], host: string) {
return status.map((t) => { return status.map((t) => {
if (!t) return statusModel(null, null, [], 'no content') if (!t) return statusModel(null, null, [], "no content");
if (!t.emoji_reactions) return t if (!t.emoji_reactions) return t;
if (t.reblog) t.reblog = toTextWithReaction([t.reblog], host)[0] if (t.reblog) t.reblog = toTextWithReaction([t.reblog], host)[0];
const reactions = t.emoji_reactions.map((r) => `${r.name.replace('@.', '')} (${r.count}${r.me ? "* " : ''})`); const reactions = t.emoji_reactions.map(
//t.emojis = getEmoji(t.content, host) (r) => `${r.name.replace("@.", "")} (${r.count}${r.me ? "* " : ""})`,
t.content = `<p>${autoLinker(t.content, host)}</p><p>${reactions.join(', ')}</p>` );
return t //t.emojis = getEmoji(t.content, host)
}) t.content = `<p>${autoLinker(t.content, host)}</p><p>${reactions.join(
", ",
)}</p>`;
return t;
});
} }
export function autoLinker(input: string, host: string) { export function autoLinker(input: string, host: string) {
return Autolinker.link(input, { return Autolinker.link(input, {
hashtag: 'twitter', hashtag: "twitter",
mention: 'twitter', mention: "twitter",
email: false, email: false,
stripPrefix: false, stripPrefix: false,
replaceFn : function (match) { replaceFn: function (match) {
switch(match.type) { switch (match.type) {
case 'url': case "url":
return true return true;
case 'mention': case "mention":
console.log("Mention: ", match.getMention()); console.log("Mention: ", match.getMention());
console.log("Mention Service Name: ", match.getServiceName()); console.log("Mention Service Name: ", match.getServiceName());
return `<a href="https://${host}/@${encodeURIComponent(match.getMention())}" target="_blank">@${match.getMention()}</a>`; return `<a href="https://${host}/@${encodeURIComponent(
case 'hashtag': match.getMention(),
console.log("Hashtag: ", match.getHashtag()); )}" target="_blank">@${match.getMention()}</a>`;
return `<a href="https://${host}/tags/${encodeURIComponent(match.getHashtag())}" target="_blank">#${match.getHashtag()}</a>`; case "hashtag":
} console.log("Hashtag: ", match.getHashtag());
return false return `<a href="https://${host}/tags/${encodeURIComponent(
} match.getHashtag(),
} ); )}" target="_blank">#${match.getHashtag()}</a>`;
}
return false;
},
});
} }
export function apiTimelineMastodon(router: Router): void { export function apiTimelineMastodon(router: Router): void {
router.get('/v1/timelines/public', async (ctx, reply) => { router.get("/v1/timelines/public", async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
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 query: any = ctx.query const query: any = ctx.query;
const data = query.local ? await client.getLocalTimeline(toLimitToInt(query)) : await client.getPublicTimeline(toLimitToInt(query)); const data = query.local
ctx.body = toTextWithReaction(data.data, ctx.hostname); ? await client.getLocalTimeline(toLimitToInt(query))
} catch (e: any) { : await client.getPublicTimeline(toLimitToInt(query));
console.error(e) ctx.body = toTextWithReaction(data.data, ctx.hostname);
console.error(e.response.data) } catch (e: any) {
ctx.status = (401); console.error(e);
ctx.body = e.response.data; console.error(e.response.data);
} ctx.status = 401;
}); ctx.body = e.response.data;
router.get<{ Params: { hashtag: string } }>('/v1/timelines/tag/:hashtag', async (ctx, reply) => { }
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; });
const accessTokens = ctx.headers.authorization; router.get<{ Params: { hashtag: string } }>(
const client = getClient(BASE_URL, accessTokens); "/v1/timelines/tag/:hashtag",
try { async (ctx, reply) => {
const data = await client.getTagTimeline(ctx.params.hashtag, toLimitToInt(ctx.query)); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.body = toTextWithReaction(data.data, ctx.hostname); const accessTokens = ctx.headers.authorization;
} catch (e: any) { const client = getClient(BASE_URL, accessTokens);
console.error(e) try {
console.error(e.response.data) const data = await client.getTagTimeline(
ctx.status = (401); ctx.params.hashtag,
ctx.body = e.response.data; toLimitToInt(ctx.query),
} );
}); ctx.body = toTextWithReaction(data.data, ctx.hostname);
router.get<{ Params: { hashtag: string } }>('/v1/timelines/home', async (ctx, reply) => { } catch (e: any) {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; console.error(e);
const accessTokens = ctx.headers.authorization; console.error(e.response.data);
const client = getClient(BASE_URL, accessTokens); ctx.status = 401;
try { ctx.body = e.response.data;
const data = await client.getHomeTimeline(toLimitToInt(ctx.query)); }
ctx.body = toTextWithReaction(data.data, ctx.hostname); },
} catch (e: any) { );
console.error(e) router.get<{ Params: { hashtag: string } }>(
console.error(e.response.data) "/v1/timelines/home",
ctx.status = (401); async (ctx, reply) => {
ctx.body = e.response.data; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
} const accessTokens = ctx.headers.authorization;
}); const client = getClient(BASE_URL, accessTokens);
router.get<{ Params: { listId: string } }>('/v1/timelines/list/:listId', async (ctx, reply) => { try {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const data = await client.getHomeTimeline(toLimitToInt(ctx.query));
const accessTokens = ctx.headers.authorization; ctx.body = toTextWithReaction(data.data, ctx.hostname);
const client = getClient(BASE_URL, accessTokens); } catch (e: any) {
try { console.error(e);
const data = await client.getListTimeline(ctx.params.listId, toLimitToInt(ctx.query)); console.error(e.response.data);
ctx.body = toTextWithReaction(data.data, ctx.hostname); ctx.status = 401;
} catch (e: any) { ctx.body = e.response.data;
console.error(e) }
console.error(e.response.data) },
ctx.status = (401); );
ctx.body = e.response.data; router.get<{ Params: { listId: string } }>(
} "/v1/timelines/list/:listId",
}); async (ctx, reply) => {
router.get('/v1/conversations', async (ctx, reply) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; 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.getListTimeline(
const data = await client.getConversationTimeline(toLimitToInt(ctx.query)); ctx.params.listId,
ctx.body = data.data; toLimitToInt(ctx.query),
} catch (e: any) { );
console.error(e) ctx.body = toTextWithReaction(data.data, ctx.hostname);
console.error(e.response.data) } catch (e: any) {
ctx.status = (401); console.error(e);
ctx.body = e.response.data; console.error(e.response.data);
} ctx.status = 401;
}); ctx.body = e.response.data;
router.get('/v1/lists', async (ctx, reply) => { }
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; },
const accessTokens = ctx.headers.authorization; );
const client = getClient(BASE_URL, accessTokens); router.get("/v1/conversations", async (ctx, reply) => {
try { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const data = await client.getLists(); const accessTokens = ctx.headers.authorization;
ctx.body = data.data; const client = getClient(BASE_URL, accessTokens);
} catch (e: any) { try {
console.error(e) const data = await client.getConversationTimeline(
console.error(e.response.data) toLimitToInt(ctx.query),
ctx.status = (401); );
ctx.body = e.response.data; ctx.body = data.data;
} } catch (e: any) {
}); console.error(e);
router.get<{ Params: { id: string } }>('/v1/lists/:id', async (ctx, reply) => { console.error(e.response.data);
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; ctx.status = 401;
const accessTokens = ctx.headers.authorization; ctx.body = e.response.data;
const client = getClient(BASE_URL, accessTokens); }
try { });
const data = await client.getList(ctx.params.id); router.get("/v1/lists", async (ctx, reply) => {
ctx.body = data.data; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
} catch (e: any) { const accessTokens = ctx.headers.authorization;
console.error(e) const client = getClient(BASE_URL, accessTokens);
console.error(e.response.data) try {
ctx.status = (401); const data = await client.getLists();
ctx.body = e.response.data; ctx.body = data.data;
} } catch (e: any) {
}); console.error(e);
router.post('/v1/lists', async (ctx, reply) => { console.error(e.response.data);
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; ctx.status = 401;
const accessTokens = ctx.headers.authorization; ctx.body = e.response.data;
const client = getClient(BASE_URL, accessTokens); }
try { });
const data = await client.createList((ctx.query as any).title); router.get<{ Params: { id: string } }>(
ctx.body = data.data; "/v1/lists/:id",
} catch (e: any) { async (ctx, reply) => {
console.error(e) const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
console.error(e.response.data) const accessTokens = ctx.headers.authorization;
ctx.status = (401); const client = getClient(BASE_URL, accessTokens);
ctx.body = e.response.data; try {
} const data = await client.getList(ctx.params.id);
}); ctx.body = data.data;
router.put<{ Params: { id: string } }>('/v1/lists/:id', async (ctx, reply) => { } catch (e: any) {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; console.error(e);
const accessTokens = ctx.headers.authorization; console.error(e.response.data);
const client = getClient(BASE_URL, accessTokens); ctx.status = 401;
try { ctx.body = e.response.data;
const data = await client.updateList(ctx.params.id, ctx.query as any); }
ctx.body = data.data; },
} catch (e: any) { );
console.error(e) router.post("/v1/lists", async (ctx, reply) => {
console.error(e.response.data) const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
ctx.status = (401); const accessTokens = ctx.headers.authorization;
ctx.body = e.response.data; const client = getClient(BASE_URL, accessTokens);
} try {
}); const data = await client.createList((ctx.query as any).title);
router.delete<{ Params: { id: string } }>('/v1/lists/:id', async (ctx, reply) => { ctx.body = data.data;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; } catch (e: any) {
const accessTokens = ctx.headers.authorization; console.error(e);
const client = getClient(BASE_URL, accessTokens); console.error(e.response.data);
try { ctx.status = 401;
const data = await client.deleteList(ctx.params.id); ctx.body = e.response.data;
ctx.body = data.data; }
} catch (e: any) { });
console.error(e) router.put<{ Params: { id: string } }>(
console.error(e.response.data) "/v1/lists/:id",
ctx.status = (401); async (ctx, reply) => {
ctx.body = e.response.data; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
} const accessTokens = ctx.headers.authorization;
}); const client = getClient(BASE_URL, accessTokens);
router.get<{ Params: { id: string } }>('/v1/lists/:id/accounts', async (ctx, reply) => { try {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const data = await client.updateList(ctx.params.id, ctx.query as any);
const accessTokens = ctx.headers.authorization; ctx.body = data.data;
const client = getClient(BASE_URL, accessTokens); } catch (e: any) {
try { console.error(e);
const data = await client.getAccountsInList(ctx.params.id, ctx.query as any); console.error(e.response.data);
ctx.body = data.data; ctx.status = 401;
} catch (e: any) { ctx.body = e.response.data;
console.error(e) }
console.error(e.response.data) },
ctx.status = (401); );
ctx.body = e.response.data; router.delete<{ Params: { id: string } }>(
} "/v1/lists/:id",
}); async (ctx, reply) => {
router.post<{ Params: { id: string } }>('/v1/lists/:id/accounts', async (ctx, reply) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; 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.deleteList(ctx.params.id);
const data = await client.addAccountsToList(ctx.params.id, (ctx.query as any).account_ids); ctx.body = data.data;
ctx.body = data.data; } catch (e: any) {
} catch (e: any) { console.error(e);
console.error(e) console.error(e.response.data);
console.error(e.response.data) ctx.status = 401;
ctx.status = (401); ctx.body = e.response.data;
ctx.body = e.response.data; }
} },
}); );
router.delete<{ Params: { id: string } }>('/v1/lists/:id/accounts', async (ctx, reply) => { router.get<{ Params: { id: string } }>(
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; "/v1/lists/:id/accounts",
const accessTokens = ctx.headers.authorization; async (ctx, reply) => {
const client = getClient(BASE_URL, accessTokens); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
try { const accessTokens = ctx.headers.authorization;
const data = await client.deleteAccountsFromList(ctx.params.id, (ctx.query as any).account_ids); const client = getClient(BASE_URL, accessTokens);
ctx.body = data.data; try {
} catch (e: any) { const data = await client.getAccountsInList(
console.error(e) ctx.params.id,
console.error(e.response.data) ctx.query as any,
ctx.status = (401); );
ctx.body = e.response.data; ctx.body = data.data;
} } catch (e: any) {
}); console.error(e);
console.error(e.response.data);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.post<{ Params: { id: string } }>(
"/v1/lists/:id/accounts",
async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.addAccountsToList(
ctx.params.id,
(ctx.query as any).account_ids,
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.delete<{ Params: { id: string } }>(
"/v1/lists/:id/accounts",
async (ctx, reply) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.deleteAccountsFromList(
ctx.params.id,
(ctx.query as any).account_ids,
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
} }
function escapeHTML(str: string) { function escapeHTML(str: string) {
if (!str) { if (!str) {
return '' return "";
} }
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;') return str
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
} }
function nl2br(str: string) { function nl2br(str: string) {
if (!str) { if (!str) {
return '' return "";
} }
str = str.replace(/\r\n/g, '<br />') str = str.replace(/\r\n/g, "<br />");
str = str.replace(/(\n|\r)/g, '<br />') str = str.replace(/(\n|\r)/g, "<br />");
return str return str;
} }

View File

@ -152,7 +152,7 @@ export default class Connection {
} catch (e) { } catch (e) {
return; return;
} }
const simpleObj = objs[0]; const simpleObj = objs[0];
if (simpleObj.stream) { if (simpleObj.stream) {
// is Mastodon Compatible // is Mastodon Compatible

View File

@ -16,7 +16,7 @@ export const initializeStreamingServer = (server: http.Server) => {
ws.on("request", async (request) => { ws.on("request", async (request) => {
const q = request.resourceURL.query as ParsedUrlQuery; const q = request.resourceURL.query as ParsedUrlQuery;
const headers = request.httpRequest.headers['sec-websocket-protocol'] || ''; const headers = request.httpRequest.headers["sec-websocket-protocol"] || "";
const cred = q.i || q.access_token || headers; const cred = q.i || q.access_token || headers;
const accessToken = cred.toString(); const accessToken = cred.toString();
@ -48,9 +48,17 @@ export const initializeStreamingServer = (server: http.Server) => {
redisClient.on("message", onRedisMessage); redisClient.on("message", onRedisMessage);
const host = `https://${request.host}`; const host = `https://${request.host}`;
const prepareStream = q.stream?.toString(); const prepareStream = q.stream?.toString();
console.log('start', q); console.log("start", q);
const main = new MainStreamConnection(connection, ev, user, app, host, accessToken, prepareStream); const main = new MainStreamConnection(
connection,
ev,
user,
app,
host,
accessToken,
prepareStream,
);
const intervalId = user const intervalId = user
? setInterval(() => { ? setInterval(() => {

View File

@ -20,7 +20,7 @@ import { createTemp } from "@/misc/create-temp.js";
import { publishMainStream } from "@/services/stream.js"; import { publishMainStream } from "@/services/stream.js";
import * as Acct from "@/misc/acct.js"; import * as Acct from "@/misc/acct.js";
import { envOption } from "@/env.js"; import { envOption } from "@/env.js";
import megalodon, { MegalodonInterface } from '@cutls/megalodon'; import megalodon, { MegalodonInterface } from "@cutls/megalodon";
import activityPub from "./activitypub.js"; import activityPub from "./activitypub.js";
import nodeinfo from "./nodeinfo.js"; import nodeinfo from "./nodeinfo.js";
import wellKnown from "./well-known.js"; import wellKnown from "./well-known.js";
@ -29,7 +29,7 @@ import fileServer from "./file/index.js";
import proxyServer from "./proxy/index.js"; import proxyServer from "./proxy/index.js";
import webServer from "./web/index.js"; import webServer from "./web/index.js";
import { initializeStreamingServer } from "./api/streaming.js"; import { initializeStreamingServer } from "./api/streaming.js";
import {koaBody} from "koa-body"; import { koaBody } from "koa-body";
export const serverLogger = new Logger("server", "gray", false); export const serverLogger = new Logger("server", "gray", false);
@ -141,26 +141,30 @@ router.get("/verify-email/:code", async (ctx) => {
mastoRouter.get("/oauth/authorize", async (ctx) => { mastoRouter.get("/oauth/authorize", async (ctx) => {
const client_id = ctx.request.query.client_id; const client_id = ctx.request.query.client_id;
console.log(ctx.request.req); console.log(ctx.request.req);
ctx.redirect(Buffer.from(client_id?.toString() || '', 'base64').toString()); ctx.redirect(Buffer.from(client_id?.toString() || "", "base64").toString());
}); });
mastoRouter.post("/oauth/token", async (ctx) => { mastoRouter.post("/oauth/token", async (ctx) => {
const body: any = ctx.request.body; const body: any = ctx.request.body;
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const generator = (megalodon as any).default; const generator = (megalodon as any).default;
const client = generator('misskey', BASE_URL, null) as MegalodonInterface; const client = generator("misskey", BASE_URL, null) as MegalodonInterface;
const m = body.code.match(/^[a-zA-Z0-9-]+/); const m = body.code.match(/^[a-zA-Z0-9-]+/);
if (!m.length) { if (!m.length) {
ctx.body = {error: 'Invalid code'} ctx.body = { error: "Invalid code" };
return return;
} }
try { try {
const atData = await client.fetchAccessToken(null, body.client_secret, m[0]); const atData = await client.fetchAccessToken(
null,
body.client_secret,
m[0],
);
ctx.body = { ctx.body = {
access_token: atData.accessToken, access_token: atData.accessToken,
token_type: 'Bearer', token_type: "Bearer",
scope: 'read write follow', scope: "read write follow",
created_at: new Date().getTime() / 1000 created_at: new Date().getTime() / 1000,
}; };
} catch (err: any) { } catch (err: any) {
console.error(err); console.error(err);

View File

@ -44,12 +44,21 @@ export const urlPreviewHandler = async (ctx: Koa.Context) => {
logger.succ(`Got preview of ${url}: ${summary.title}`); logger.succ(`Got preview of ${url}: ${summary.title}`);
if (summary.url && !(summary.url.startsWith('http://') || summary.url.startsWith('https://'))) { if (
throw new Error('unsupported schema included'); summary.url &&
!(summary.url.startsWith("http://") || summary.url.startsWith("https://"))
) {
throw new Error("unsupported schema included");
} }
if (summary.player?.url && !(summary.player.url.startsWith('http://') || summary.player.url.startsWith('https://'))) { if (
throw new Error('unsupported schema included'); summary.player?.url &&
!(
summary.player.url.startsWith("http://") ||
summary.player.url.startsWith("https://")
)
) {
throw new Error("unsupported schema included");
} }
summary.icon = wrap(summary.icon); summary.icon = wrap(summary.icon);

View File

@ -377,12 +377,7 @@ export default defineComponent({
case "quote": { case "quote": {
if (!this.nowrap) { if (!this.nowrap) {
return [ return [h("blockquote", genEl(token.children))];
h(
"blockquote",
genEl(token.children),
),
];
} else { } else {
return [ return [
h( h(

View File

@ -5,10 +5,10 @@ import * as os from "@/os";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { ui } from "@/config"; import { ui } from "@/config";
import { unisonReload } from "@/scripts/unison-reload"; import { unisonReload } from "@/scripts/unison-reload";
import { defaultStore } from '@/store'; import { defaultStore } from "@/store";
import { instance } from '@/instance'; import { instance } from "@/instance";
import { host } from '@/config'; import { host } from "@/config";
import XTutorial from '@/components/MkTutorialDialog.vue'; import XTutorial from "@/components/MkTutorialDialog.vue";
export const navbarItemDef = reactive({ export const navbarItemDef = reactive({
notifications: { notifications: {
@ -152,54 +152,68 @@ export const navbarItemDef = reactive({
title: "help", title: "help",
icon: "ph-question-bold ph-lg", icon: "ph-question-bold ph-lg",
action: (ev) => { action: (ev) => {
os.popupMenu([{ os.popupMenu(
text: instance.name ?? host, [
type: 'label', {
}, { text: instance.name ?? host,
type: 'link', type: "label",
text: i18n.ts.instanceInfo,
icon: 'ph-info-bold ph-lg',
to: '/about',
}, {
type: 'link',
text: i18n.ts.aboutMisskey,
icon: 'ph-lightbulb-bold ph-lg',
to: '/about-calckey',
}, {
type: 'link',
text: i18n.ts._apps.apps,
icon: 'ph-device-mobile-bold ph-lg',
to: '/apps',
}, {
type: 'button',
action: async () => {
defaultStore.set('tutorial', 0);
os.popup(XTutorial, {}, {}, 'closed');
}, },
text: i18n.ts.replayTutorial, {
icon: 'ph-circle-wavy-question-bold ph-lg', type: "link",
}, null, { text: i18n.ts.instanceInfo,
type: 'parent', icon: "ph-info-bold ph-lg",
text: i18n.ts.developer, to: "/about",
icon: 'ph-code-bold ph-lg', },
children: [{ {
type: 'link', type: "link",
to: '/api-console', text: i18n.ts.aboutMisskey,
text: 'API Console', icon: "ph-lightbulb-bold ph-lg",
icon: 'ph-terminal-window-bold ph-lg', to: "/about-calckey",
}, { },
text: i18n.ts.document, {
icon: 'ph-file-doc-bold ph-lg', type: "link",
action: () => { text: i18n.ts._apps.apps,
window.open('/api-doc', '_blank'); icon: "ph-device-mobile-bold ph-lg",
to: "/apps",
},
{
type: "button",
action: async () => {
defaultStore.set("tutorial", 0);
os.popup(XTutorial, {}, {}, "closed");
}, },
}, { text: i18n.ts.replayTutorial,
type: 'link', icon: "ph-circle-wavy-question-bold ph-lg",
to: '/scratchpad', },
text: 'AiScript Scratchpad', null,
icon: 'ph-scribble-loop-bold ph-lg', {
}] type: "parent",
}], ev.currentTarget ?? ev.target, text: i18n.ts.developer,
icon: "ph-code-bold ph-lg",
children: [
{
type: "link",
to: "/api-console",
text: "API Console",
icon: "ph-terminal-window-bold ph-lg",
},
{
text: i18n.ts.document,
icon: "ph-file-doc-bold ph-lg",
action: () => {
window.open("/api-doc", "_blank");
},
},
{
type: "link",
to: "/scratchpad",
text: "AiScript Scratchpad",
icon: "ph-scribble-loop-bold ph-lg",
},
],
},
],
ev.currentTarget ?? ev.target,
); );
}, },
}, },

View File

@ -27,7 +27,7 @@ export function createAiScriptEnv(opts) {
if (token) { if (token) {
utils.assertString(token); utils.assertString(token);
// バグがあればundefinedもあり得るため念のため // バグがあればundefinedもあり得るため念のため
if (typeof token.value !== 'string') throw new Error('invalid token'); if (typeof token.value !== "string") throw new Error("invalid token");
} }
apiRequests++; apiRequests++;
if (apiRequests > 16) return values.NULL; if (apiRequests > 16) return values.NULL;

View File

@ -125,19 +125,22 @@ export function getUserMenu(user, router: Router = mainRouter) {
) )
return; return;
await os.apiWithDialog(user.isBlocking ? "blocking/delete" : "blocking/create", { await os.apiWithDialog(
userId: user.id, user.isBlocking ? "blocking/delete" : "blocking/create",
}) {
userId: user.id,
},
);
user.isBlocking = !user.isBlocking; user.isBlocking = !user.isBlocking;
await os.api(user.isBlocking ? "mute/create" : "mute/delete", { await os.api(user.isBlocking ? "mute/create" : "mute/delete", {
userId: user.id, userId: user.id,
}) });
user.isMuted = user.isBlocking; user.isMuted = user.isBlocking;
if (user.isBlocking) { if (user.isBlocking) {
await os.api('following/delete', { await os.api("following/delete", {
userId: user.id, userId: user.id,
}); });
user.isFollowing = false user.isFollowing = false;
} }
} }