mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-26 19:13:08 +02:00
chore: lint and update package name
This commit is contained in:
parent
410e6515d3
commit
db6dc1b52e
12 changed files with 1636 additions and 1683 deletions
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "misskey",
|
"name": "sharkey",
|
||||||
"version": "2023.9.0-beta.10",
|
"version": "2023.9.0-beta.10",
|
||||||
"codename": "nasubi",
|
"codename": "nasubi",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/misskey-dev/misskey.git"
|
"url": "https://github.com/transfem-org/sharkey.git"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@8.7.6",
|
"packageManager": "pnpm@8.7.6",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import megalodon, { Entity, MegalodonInterface } from 'megalodon';
|
||||||
|
import { IsNull } from 'typeorm';
|
||||||
|
import multer from 'fastify-multer';
|
||||||
import type { UsersRepository } from '@/models/_.js';
|
import type { UsersRepository } from '@/models/_.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import megalodon, { Entity, MegalodonInterface } from 'megalodon';
|
|
||||||
import type { FastifyInstance, FastifyPluginOptions } from 'fastify';
|
|
||||||
import { convertId, IdConvertType as IdType, convertAccount, convertAnnouncement, convertFilter, convertAttachment, convertFeaturedTag, convertList } from './converters.js';
|
|
||||||
import { IsNull } from 'typeorm';
|
|
||||||
import type { Config } from '@/config.js';
|
import type { Config } from '@/config.js';
|
||||||
import { getInstance } from './endpoints/meta.js';
|
|
||||||
import { MetaService } from '@/core/MetaService.js';
|
import { MetaService } from '@/core/MetaService.js';
|
||||||
import multer from 'fastify-multer';
|
import { convertId, IdConvertType as IdType, convertAccount, convertAnnouncement, convertFilter, convertAttachment, convertFeaturedTag, convertList } from './converters.js';
|
||||||
import { apiAuthMastodon, apiAccountMastodon, apiFilterMastodon, apiNotifyMastodon, apiSearchMastodon, apiTimelineMastodon, apiStatusMastodon } from './endpoints.js';
|
import { getInstance } from './endpoints/meta.js';
|
||||||
|
import { ApiAuthMastodon, ApiAccountMastodon, ApiFilterMastodon, ApiNotifyMastodon, ApiSearchMastodon, ApiTimelineMastodon, ApiStatusMastodon } from './endpoints.js';
|
||||||
const staticAssets = fileURLToPath(new URL('../../../../assets/', import.meta.url));
|
import type { FastifyInstance, FastifyPluginOptions } from 'fastify';
|
||||||
|
|
||||||
export function getClient(BASE_URL: string, authorization: string | undefined): MegalodonInterface {
|
export function getClient(BASE_URL: string, authorization: string | undefined): MegalodonInterface {
|
||||||
const accessTokenArr = authorization?.split(' ') ?? [null];
|
const accessTokenArr = authorization?.split(' ') ?? [null];
|
||||||
|
@ -101,7 +98,7 @@ export class MastodonApiServerService {
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.dismissInstanceAnnouncement(
|
const data = await client.dismissInstanceAnnouncement(
|
||||||
convertId(_request.body['id'], IdType.SharkeyId)
|
convertId(_request.body['id'], IdType.SharkeyId),
|
||||||
);
|
);
|
||||||
reply.send(data.data);
|
reply.send(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -180,7 +177,7 @@ export class MastodonApiServerService {
|
||||||
const client = getClient(BASE_URL, ''); // we are using this here, because in private mode some info isnt
|
const client = getClient(BASE_URL, ''); // 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 apiAuthMastodon(_request, client);
|
const data = await ApiAuthMastodon(_request, client);
|
||||||
reply.send(data);
|
reply.send(data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -209,7 +206,7 @@ export class MastodonApiServerService {
|
||||||
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 account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.verifyCredentials());
|
reply.send(await account.verifyCredentials());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -223,7 +220,7 @@ export class MastodonApiServerService {
|
||||||
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 account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.updateCredentials());
|
reply.send(await account.updateCredentials());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -237,7 +234,7 @@ export class MastodonApiServerService {
|
||||||
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 account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.lookup());
|
reply.send(await account.lookup());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -257,11 +254,11 @@ export class MastodonApiServerService {
|
||||||
ids = [ids];
|
ids = [ids];
|
||||||
}
|
}
|
||||||
users = ids;
|
users = ids;
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.getRelationships(users));
|
reply.send(await account.getRelationships(users));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
let data = e.response.data;
|
const data = e.response.data;
|
||||||
data.users = users;
|
data.users = users;
|
||||||
console.error(data);
|
console.error(data);
|
||||||
reply.code(401).send(data);
|
reply.code(401).send(data);
|
||||||
|
@ -288,7 +285,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.getStatuses());
|
reply.send(await account.getStatuses());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -316,7 +313,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.getFollowers());
|
reply.send(await account.getFollowers());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -330,7 +327,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.getFollowing());
|
reply.send(await account.getFollowing());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -358,7 +355,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.addFollow());
|
reply.send(await account.addFollow());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -372,7 +369,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.rmFollow());
|
reply.send(await account.rmFollow());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -386,7 +383,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.addBlock());
|
reply.send(await account.addBlock());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -400,7 +397,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.rmBlock());
|
reply.send(await account.rmBlock());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -414,7 +411,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.addMute());
|
reply.send(await account.addMute());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -428,7 +425,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.rmMute());
|
reply.send(await account.rmMute());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -456,7 +453,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.getBookmarks());
|
reply.send(await account.getBookmarks());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -470,7 +467,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.getFavourites());
|
reply.send(await account.getFavourites());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -484,7 +481,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.getMutes());
|
reply.send(await account.getMutes());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -498,7 +495,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.getBlocks());
|
reply.send(await account.getBlocks());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -526,7 +523,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.acceptFollow());
|
reply.send(await account.acceptFollow());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -540,7 +537,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const account = new apiAccountMastodon(_request, client, BASE_URL);
|
const account = new ApiAccountMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await account.rejectFollow());
|
reply.send(await account.rejectFollow());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -556,7 +553,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const search = new apiSearchMastodon(_request, client, BASE_URL);
|
const search = new ApiSearchMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await search.SearchV1());
|
reply.send(await search.SearchV1());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -570,7 +567,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const search = new apiSearchMastodon(_request, client, BASE_URL);
|
const search = new ApiSearchMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await search.SearchV2());
|
reply.send(await search.SearchV2());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -584,7 +581,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const search = new apiSearchMastodon(_request, client, BASE_URL);
|
const search = new ApiSearchMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await search.getStatusTrends());
|
reply.send(await search.getStatusTrends());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -598,7 +595,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const search = new apiSearchMastodon(_request, client, BASE_URL);
|
const search = new ApiSearchMastodon(_request, client, BASE_URL);
|
||||||
reply.send(await search.getSuggestions());
|
reply.send(await search.getSuggestions());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -614,7 +611,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const notify = new apiNotifyMastodon(_request, client);
|
const notify = new ApiNotifyMastodon(_request, client);
|
||||||
reply.send(await notify.getNotifications());
|
reply.send(await notify.getNotifications());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -628,7 +625,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const notify = new apiNotifyMastodon(_request, client);
|
const notify = new ApiNotifyMastodon(_request, client);
|
||||||
reply.send(await notify.getNotification());
|
reply.send(await notify.getNotification());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -642,7 +639,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const notify = new apiNotifyMastodon(_request, client);
|
const notify = new ApiNotifyMastodon(_request, client);
|
||||||
reply.send(await notify.rmNotification());
|
reply.send(await notify.rmNotification());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -656,7 +653,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const notify = new apiNotifyMastodon(_request, client);
|
const notify = new ApiNotifyMastodon(_request, client);
|
||||||
reply.send(await notify.rmNotifications());
|
reply.send(await notify.rmNotifications());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -672,7 +669,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const filter = new apiFilterMastodon(_request, client);
|
const filter = new ApiFilterMastodon(_request, client);
|
||||||
!_request.params.id ? reply.send(await filter.getFilters()) : reply.send(await filter.getFilter());
|
!_request.params.id ? reply.send(await filter.getFilters()) : reply.send(await filter.getFilter());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -686,7 +683,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const filter = new apiFilterMastodon(_request, client);
|
const filter = new ApiFilterMastodon(_request, client);
|
||||||
reply.send(await filter.createFilter());
|
reply.send(await filter.createFilter());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -700,7 +697,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const filter = new apiFilterMastodon(_request, client);
|
const filter = new ApiFilterMastodon(_request, client);
|
||||||
reply.send(await filter.updateFilter());
|
reply.send(await filter.updateFilter());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -714,7 +711,7 @@ export class MastodonApiServerService {
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const filter = new apiFilterMastodon(_request, client);
|
const filter = new ApiFilterMastodon(_request, client);
|
||||||
reply.send(await filter.rmFilter());
|
reply.send(await filter.rmFilter());
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -725,7 +722,7 @@ export class MastodonApiServerService {
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Timelines
|
//#region Timelines
|
||||||
const TLEndpoint = new apiTimelineMastodon(fastify);
|
const TLEndpoint = new ApiTimelineMastodon(fastify);
|
||||||
|
|
||||||
// GET Endpoints
|
// GET Endpoints
|
||||||
TLEndpoint.getTL();
|
TLEndpoint.getTL();
|
||||||
|
@ -750,7 +747,7 @@ export class MastodonApiServerService {
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Status
|
//#region Status
|
||||||
const NoteEndpoint = new apiStatusMastodon(fastify);
|
const NoteEndpoint = new ApiStatusMastodon(fastify);
|
||||||
|
|
||||||
// GET Endpoints
|
// GET Endpoints
|
||||||
NoteEndpoint.getStatus();
|
NoteEndpoint.getStatus();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Entity } from 'megalodon';
|
import { Entity } from 'megalodon';
|
||||||
|
|
||||||
const CHAR_COLLECTION: string = '0123456789abcdefghijklmnopqrstuvwxyz';
|
const CHAR_COLLECTION = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||||
|
|
||||||
export enum IdConvertType {
|
export enum IdConvertType {
|
||||||
MastodonId,
|
MastodonId,
|
||||||
|
@ -9,25 +9,27 @@ export enum IdConvertType {
|
||||||
|
|
||||||
export function convertId(in_id: string, id_convert_type: IdConvertType): string {
|
export function convertId(in_id: string, id_convert_type: IdConvertType): string {
|
||||||
switch (id_convert_type) {
|
switch (id_convert_type) {
|
||||||
case IdConvertType.MastodonId:
|
case IdConvertType.MastodonId: {
|
||||||
let out: bigint = BigInt(0);
|
let out = BigInt(0);
|
||||||
const lowerCaseId = in_id.toLowerCase();
|
const lowerCaseId = in_id.toLowerCase();
|
||||||
for (let i = 0; i < lowerCaseId.length; i++) {
|
for (let i = 0; i < lowerCaseId.length; i++) {
|
||||||
const charValue = numFromChar(lowerCaseId.charAt(i));
|
const charValue = numFromChar(lowerCaseId.charAt(i));
|
||||||
out += BigInt(charValue) * BigInt(36) ** BigInt(i);
|
out += BigInt(charValue) * BigInt(36) ** BigInt(i);
|
||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
case IdConvertType.SharkeyId:
|
case IdConvertType.SharkeyId: {
|
||||||
let input: bigint = BigInt(in_id);
|
let input = BigInt(in_id);
|
||||||
let outStr = '';
|
let outStr = '';
|
||||||
while (input > BigInt(0)) {
|
while (input > BigInt(0)) {
|
||||||
const remainder = Number(input % BigInt(36));
|
const remainder = Number(input % BigInt(36));
|
||||||
outStr = charFromNum(remainder) + outStr;
|
outStr = charFromNum(remainder) + outStr;
|
||||||
input /= BigInt(36);
|
input /= BigInt(36);
|
||||||
}
|
}
|
||||||
let ReversedoutStr = outStr.split('').reduce((acc, char) => char + acc, '');
|
const ReversedoutStr = outStr.split('').reduce((acc, char) => char + acc, '');
|
||||||
return ReversedoutStr;
|
return ReversedoutStr;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error('Invalid ID conversion type');
|
throw new Error('Invalid ID conversion type');
|
||||||
|
@ -81,8 +83,7 @@ export function convertFeaturedTag(tag: Entity.FeaturedTag) {
|
||||||
export function convertNotification(notification: Entity.Notification) {
|
export function convertNotification(notification: Entity.Notification) {
|
||||||
notification.account = convertAccount(notification.account);
|
notification.account = convertAccount(notification.account);
|
||||||
notification.id = convertId(notification.id, IdConvertType.MastodonId);
|
notification.id = convertId(notification.id, IdConvertType.MastodonId);
|
||||||
if (notification.status)
|
if (notification.status) notification.status = convertStatus(notification.status);
|
||||||
notification.status = convertStatus(notification.status);
|
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,13 +103,11 @@ export function convertRelationship(relationship: Entity.Relationship) {
|
||||||
export function convertStatus(status: Entity.Status) {
|
export function convertStatus(status: Entity.Status) {
|
||||||
status.account = convertAccount(status.account);
|
status.account = convertAccount(status.account);
|
||||||
status.id = convertId(status.id, IdConvertType.MastodonId);
|
status.id = convertId(status.id, IdConvertType.MastodonId);
|
||||||
if (status.in_reply_to_account_id)
|
if (status.in_reply_to_account_id) status.in_reply_to_account_id = convertId(
|
||||||
status.in_reply_to_account_id = convertId(
|
|
||||||
status.in_reply_to_account_id,
|
status.in_reply_to_account_id,
|
||||||
IdConvertType.MastodonId,
|
IdConvertType.MastodonId,
|
||||||
);
|
);
|
||||||
if (status.in_reply_to_id)
|
if (status.in_reply_to_id) status.in_reply_to_id = convertId(status.in_reply_to_id, IdConvertType.MastodonId);
|
||||||
status.in_reply_to_id = convertId(status.in_reply_to_id, IdConvertType.MastodonId);
|
|
||||||
status.media_attachments = status.media_attachments.map((attachment) =>
|
status.media_attachments = status.media_attachments.map((attachment) =>
|
||||||
convertAttachment(attachment),
|
convertAttachment(attachment),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
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 { apiSearchMastodon } from './endpoints/search.js';
|
import { ApiSearchMastodon } from './endpoints/search.js';
|
||||||
import { apiNotifyMastodon } from './endpoints/notifications.js';
|
import { ApiNotifyMastodon } from './endpoints/notifications.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 { apiStatusMastodon } from './endpoints/status.js';
|
import { ApiStatusMastodon } from './endpoints/status.js';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
apiAccountMastodon,
|
ApiAccountMastodon,
|
||||||
apiAuthMastodon,
|
ApiAuthMastodon,
|
||||||
apiSearchMastodon,
|
ApiSearchMastodon,
|
||||||
apiNotifyMastodon,
|
ApiNotifyMastodon,
|
||||||
apiFilterMastodon,
|
ApiFilterMastodon,
|
||||||
apiTimelineMastodon,
|
ApiTimelineMastodon,
|
||||||
apiStatusMastodon
|
ApiStatusMastodon,
|
||||||
}
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
import { convertId, IdConvertType as IdType, convertAccount, convertRelationship, convertStatus } from '../converters.js';
|
||||||
|
import { argsToBools, convertTimelinesArgsId, limitToInt } from './timeline.js';
|
||||||
import type { MegalodonInterface } from 'megalodon';
|
import type { MegalodonInterface } from 'megalodon';
|
||||||
import type { FastifyRequest } from 'fastify';
|
import type { FastifyRequest } from 'fastify';
|
||||||
import { argsToBools, convertTimelinesArgsId, limitToInt } from './timeline.js';
|
|
||||||
import { convertId, IdConvertType as IdType, convertAccount, convertRelationship, convertStatus } from '../converters.js';
|
|
||||||
|
|
||||||
const relationshipModel = {
|
const relationshipModel = {
|
||||||
id: '',
|
id: '',
|
||||||
|
@ -20,7 +20,7 @@ const relationshipModel = {
|
||||||
note: '',
|
note: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export class apiAccountMastodon {
|
export class ApiAccountMastodon {
|
||||||
private request: FastifyRequest;
|
private request: FastifyRequest;
|
||||||
private client: MegalodonInterface;
|
private client: MegalodonInterface;
|
||||||
private BASE_URL: string;
|
private BASE_URL: string;
|
||||||
|
@ -34,7 +34,7 @@ export class apiAccountMastodon {
|
||||||
public async verifyCredentials() {
|
public async verifyCredentials() {
|
||||||
try {
|
try {
|
||||||
const data = await this.client.verifyAccountCredentials();
|
const data = await this.client.verifyAccountCredentials();
|
||||||
let acct = data.data;
|
const acct = data.data;
|
||||||
acct.id = convertId(acct.id, IdType.MastodonId);
|
acct.id = convertId(acct.id, IdType.MastodonId);
|
||||||
acct.display_name = acct.display_name || acct.username;
|
acct.display_name = acct.display_name || acct.username;
|
||||||
acct.url = `${this.BASE_URL}/@${acct.url}`;
|
acct.url = `${this.BASE_URL}/@${acct.url}`;
|
||||||
|
@ -82,13 +82,13 @@ export class apiAccountMastodon {
|
||||||
|
|
||||||
public async getRelationships(users: [string]) {
|
public async getRelationships(users: [string]) {
|
||||||
try {
|
try {
|
||||||
relationshipModel.id = users?.toString() || '1';
|
relationshipModel.id = users.toString() || '1';
|
||||||
|
|
||||||
if (!users) {
|
if (!(users.length > 0)) {
|
||||||
return [relationshipModel];
|
return [relationshipModel];
|
||||||
}
|
}
|
||||||
|
|
||||||
let reqIds = [];
|
const reqIds = [];
|
||||||
for (let i = 0; i < users.length; i++) {
|
for (let i = 0; i < users.length; i++) {
|
||||||
reqIds.push(convertId(users[i], IdType.SharkeyId));
|
reqIds.push(convertId(users[i], IdType.SharkeyId));
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ export class apiAccountMastodon {
|
||||||
try {
|
try {
|
||||||
const data = await this.client.getAccountStatuses(
|
const data = await this.client.getAccountStatuses(
|
||||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||||
convertTimelinesArgsId(argsToBools(limitToInt(this.request.query as any)))
|
convertTimelinesArgsId(argsToBools(limitToInt(this.request.query as any))),
|
||||||
);
|
);
|
||||||
return data.data.map((status) => convertStatus(status));
|
return data.data.map((status) => convertStatus(status));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -120,7 +120,7 @@ export class apiAccountMastodon {
|
||||||
try {
|
try {
|
||||||
const data = await this.client.getAccountFollowers(
|
const data = await this.client.getAccountFollowers(
|
||||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||||
convertTimelinesArgsId(limitToInt(this.request.query as any))
|
convertTimelinesArgsId(limitToInt(this.request.query as any)),
|
||||||
);
|
);
|
||||||
return data.data.map((account) => convertAccount(account));
|
return data.data.map((account) => convertAccount(account));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -134,7 +134,7 @@ export class apiAccountMastodon {
|
||||||
try {
|
try {
|
||||||
const data = await this.client.getAccountFollowing(
|
const data = await this.client.getAccountFollowing(
|
||||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||||
convertTimelinesArgsId(limitToInt(this.request.query as any))
|
convertTimelinesArgsId(limitToInt(this.request.query as any)),
|
||||||
);
|
);
|
||||||
return data.data.map((account) => convertAccount(account));
|
return data.data.map((account) => convertAccount(account));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -147,7 +147,7 @@ export class apiAccountMastodon {
|
||||||
public async addFollow() {
|
public async addFollow() {
|
||||||
try {
|
try {
|
||||||
const data = await this.client.followAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
const data = await this.client.followAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||||
let acct = convertRelationship(data.data);
|
const acct = convertRelationship(data.data);
|
||||||
acct.following = true;
|
acct.following = true;
|
||||||
return acct;
|
return acct;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -160,7 +160,7 @@ export class apiAccountMastodon {
|
||||||
public async rmFollow() {
|
public async rmFollow() {
|
||||||
try {
|
try {
|
||||||
const data = await this.client.unfollowAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
const data = await this.client.unfollowAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||||
let acct = convertRelationship(data.data);
|
const acct = convertRelationship(data.data);
|
||||||
acct.following = false;
|
acct.following = false;
|
||||||
return acct;
|
return acct;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -196,7 +196,7 @@ export class apiAccountMastodon {
|
||||||
try {
|
try {
|
||||||
const data = await this.client.muteAccount(
|
const data = await this.client.muteAccount(
|
||||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||||
this.request.body as any
|
this.request.body as any,
|
||||||
);
|
);
|
||||||
return convertRelationship(data.data);
|
return convertRelationship(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ const writeScope = [
|
||||||
'write:gallery-likes',
|
'write:gallery-likes',
|
||||||
];
|
];
|
||||||
|
|
||||||
export async function apiAuthMastodon(request: FastifyRequest, client: MegalodonInterface) {
|
export async function ApiAuthMastodon(request: FastifyRequest, client: MegalodonInterface) {
|
||||||
const body: any = request.body || request.query;
|
const body: any = request.body || request.query;
|
||||||
try {
|
try {
|
||||||
let scope = body.scopes;
|
let scope = body.scopes;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
import { IdConvertType as IdType, convertId, convertFilter } from '../converters.js';
|
||||||
import type { MegalodonInterface } from 'megalodon';
|
import type { MegalodonInterface } from 'megalodon';
|
||||||
import type { FastifyRequest } from 'fastify';
|
import type { FastifyRequest } from 'fastify';
|
||||||
import { IdConvertType as IdType, convertId, convertFilter } from '../converters.js';
|
|
||||||
|
|
||||||
export class apiFilterMastodon {
|
export class ApiFilterMastodon {
|
||||||
private request: FastifyRequest;
|
private request: FastifyRequest;
|
||||||
private client: MegalodonInterface;
|
private client: MegalodonInterface;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ export async function getInstance(
|
||||||
meta.description?.substring(0, 50) || 'See real server website',
|
meta.description?.substring(0, 50) || 'See real server website',
|
||||||
description:
|
description:
|
||||||
meta.description ||
|
meta.description ||
|
||||||
"This is a vanilla Sharkey Instance. It doesn't seem to have a description.",
|
'This is a vanilla Sharkey Instance. It doesn\'t seem to have a description.',
|
||||||
email: response.email || '',
|
email: response.email || '',
|
||||||
version: `3.0.0 (compatible; Sharkey ${config.version})`,
|
version: `3.0.0 (compatible; Sharkey ${config.version})`,
|
||||||
urls: response.urls,
|
urls: response.urls,
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import type { MegalodonInterface } from 'megalodon';
|
|
||||||
import type { FastifyRequest } from 'fastify';
|
|
||||||
import { convertTimelinesArgsId } from './timeline.js';
|
|
||||||
import { IdConvertType as IdType, convertId, convertNotification } from '../converters.js';
|
import { IdConvertType as IdType, convertId, convertNotification } from '../converters.js';
|
||||||
|
import { convertTimelinesArgsId } from './timeline.js';
|
||||||
|
import type { MegalodonInterface, Entity } from 'megalodon';
|
||||||
|
import type { FastifyRequest } from 'fastify';
|
||||||
|
|
||||||
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 class apiNotifyMastodon {
|
export class ApiNotifyMastodon {
|
||||||
private request: FastifyRequest;
|
private request: FastifyRequest;
|
||||||
private client: MegalodonInterface;
|
private client: MegalodonInterface;
|
||||||
|
|
||||||
|
@ -21,13 +21,13 @@ export class apiNotifyMastodon {
|
||||||
try {
|
try {
|
||||||
const data = await this.client.getNotifications( convertTimelinesArgsId(toLimitToInt(this.request.query)) );
|
const data = await this.client.getNotifications( convertTimelinesArgsId(toLimitToInt(this.request.query)) );
|
||||||
const notifs = data.data;
|
const notifs = data.data;
|
||||||
const processed = notifs.map((n) => {
|
const processed = notifs.map((n: Entity.Notification) => {
|
||||||
n = convertNotification(n);
|
let convertedn = convertNotification(n);
|
||||||
if (n.type !== 'follow' && n.type !== 'follow_request') {
|
if (convertedn.type !== 'follow' && convertedn.type !== 'follow_request') {
|
||||||
if (n.type === 'reaction') n.type = 'favourite';
|
if (convertedn.type === 'reaction') convertedn.type = 'favourite';
|
||||||
return n;
|
return convertedn;
|
||||||
} else {
|
} else {
|
||||||
return n;
|
return convertedn;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return processed;
|
return processed;
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
import type { MegalodonInterface } from 'megalodon';
|
|
||||||
import { Converter } from 'megalodon';
|
import { Converter } from 'megalodon';
|
||||||
import type { FastifyRequest } from 'fastify';
|
|
||||||
import { convertTimelinesArgsId, limitToInt } from './timeline.js';
|
|
||||||
import { convertAccount, convertStatus } from '../converters.js';
|
import { convertAccount, convertStatus } from '../converters.js';
|
||||||
|
import { convertTimelinesArgsId, limitToInt } from './timeline.js';
|
||||||
|
import type { MegalodonInterface } from 'megalodon';
|
||||||
|
import type { FastifyRequest } from 'fastify';
|
||||||
|
|
||||||
async function getHighlight(
|
async function getHighlight(
|
||||||
BASE_URL: string,
|
BASE_URL: string,
|
||||||
domain: string,
|
domain: string,
|
||||||
accessTokens: string | undefined,
|
accessTokens: string | undefined,
|
||||||
) {
|
) {
|
||||||
const accessTokenArr = accessTokens?.split(" ") ?? [null];
|
const accessTokenArr = accessTokens?.split(' ') ?? [null];
|
||||||
const accessToken = accessTokenArr[accessTokenArr.length - 1];
|
const accessToken = accessTokenArr[accessTokenArr.length - 1];
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const apicall = await fetch(`${BASE_URL}/api/notes/featured`,
|
const apicall = await fetch(`${BASE_URL}/api/notes/featured`,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json, text/plain, */*',
|
'Accept': 'application/json, text/plain, */*',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({i: accessToken})
|
body: JSON.stringify({ i: accessToken }),
|
||||||
});
|
});
|
||||||
const api = await apicall.json();
|
const api = await apicall.json();
|
||||||
const data: MisskeyEntity.Note[] = api;
|
const data: MisskeyEntity.Note[] = api;
|
||||||
|
@ -33,7 +32,7 @@ async function getHighlight(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFeaturedUser( BASE_URL: string, host: string, accessTokens: string | undefined, limit: number ) {
|
async function getFeaturedUser( BASE_URL: string, host: string, accessTokens: string | undefined, limit: number ) {
|
||||||
const accessTokenArr = accessTokens?.split(" ") ?? [null];
|
const accessTokenArr = accessTokens?.split(' ') ?? [null];
|
||||||
const accessToken = accessTokenArr[accessTokenArr.length - 1];
|
const accessToken = accessTokenArr[accessTokenArr.length - 1];
|
||||||
try {
|
try {
|
||||||
const apicall = await fetch(`${BASE_URL}/api/users`,
|
const apicall = await fetch(`${BASE_URL}/api/users`,
|
||||||
|
@ -41,15 +40,15 @@ async function getFeaturedUser( BASE_URL: string, host: string, accessTokens: st
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json, text/plain, */*',
|
'Accept': 'application/json, text/plain, */*',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({i: accessToken, limit, origin: "local", sort: "+follower", state: "alive"})
|
body: JSON.stringify({ i: accessToken, limit, origin: 'local', sort: '+follower', state: 'alive' }),
|
||||||
});
|
});
|
||||||
const api = await apicall.json();
|
const api = await apicall.json();
|
||||||
const data: MisskeyEntity.UserDetail[] = api;
|
const data: MisskeyEntity.UserDetail[] = api;
|
||||||
return data.map((u) => {
|
return data.map((u) => {
|
||||||
return {
|
return {
|
||||||
source: "past_interactions",
|
source: 'past_interactions',
|
||||||
account: Converter.userDetail(u, host),
|
account: Converter.userDetail(u, host),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -59,7 +58,7 @@ async function getFeaturedUser( BASE_URL: string, host: string, accessTokens: st
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class apiSearchMastodon {
|
export class ApiSearchMastodon {
|
||||||
private request: FastifyRequest;
|
private request: FastifyRequest;
|
||||||
private client: MegalodonInterface;
|
private client: MegalodonInterface;
|
||||||
private BASE_URL: string;
|
private BASE_URL: string;
|
||||||
|
@ -73,7 +72,7 @@ export class apiSearchMastodon {
|
||||||
public async SearchV1() {
|
public async SearchV1() {
|
||||||
try {
|
try {
|
||||||
const query: any = convertTimelinesArgsId(limitToInt(this.request.query as any));
|
const query: any = convertTimelinesArgsId(limitToInt(this.request.query as any));
|
||||||
const type = query.type || "";
|
const type = query.type || '';
|
||||||
const data = await this.client.search(query.q, { type: type, ...query });
|
const data = await this.client.search(query.q, { type: type, ...query });
|
||||||
return data.data;
|
return data.data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -86,13 +85,13 @@ export class apiSearchMastodon {
|
||||||
try {
|
try {
|
||||||
const query: any = convertTimelinesArgsId(limitToInt(this.request.query as any));
|
const query: any = convertTimelinesArgsId(limitToInt(this.request.query as any));
|
||||||
const type = query.type;
|
const type = query.type;
|
||||||
const acct = !type || type === "accounts" ? await this.client.search(query.q, { type: "accounts", ...query }) : null;
|
const acct = !type || type === 'accounts' ? await this.client.search(query.q, { type: 'accounts', ...query }) : null;
|
||||||
const stat = !type || type === "statuses" ? await this.client.search(query.q, { type: "statuses", ...query }) : null;
|
const stat = !type || type === 'statuses' ? await this.client.search(query.q, { type: 'statuses', ...query }) : null;
|
||||||
const tags = !type || type === "hashtags" ? await this.client.search(query.q, { type: "hashtags", ...query }) : null;
|
const tags = !type || type === 'hashtags' ? await this.client.search(query.q, { type: 'hashtags', ...query }) : null;
|
||||||
const data = {
|
const data = {
|
||||||
accounts: acct?.data.accounts.map((account) => convertAccount(account)) ?? [],
|
accounts: acct?.data.accounts.map((account) => convertAccount(account)) ?? [],
|
||||||
statuses: stat?.data.statuses.map((status) => convertStatus(status)) ?? [],
|
statuses: stat?.data.statuses.map((status) => convertStatus(status)) ?? [],
|
||||||
hashtags: tags?.data.hashtags ?? []
|
hashtags: tags?.data.hashtags ?? [],
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
|
@ -1,27 +1,25 @@
|
||||||
import { convertId, IdConvertType as IdType, convertAccount, convertAttachment, convertPoll, convertStatus } from '../converters.js';
|
|
||||||
import querystring from 'querystring';
|
import querystring from 'querystring';
|
||||||
import type { Entity, MegalodonInterface } from 'megalodon';
|
import { emojiRegexAtStartToEnd } from '@/misc/emoji-regex.js';
|
||||||
import type { FastifyInstance } from 'fastify';
|
import { convertId, IdConvertType as IdType, convertAccount, convertAttachment, convertPoll, convertStatus } from '../converters.js';
|
||||||
import { getClient } from '../MastodonApiServerService.js';
|
import { getClient } from '../MastodonApiServerService.js';
|
||||||
import { convertTimelinesArgsId, limitToInt } from './timeline.js';
|
import { convertTimelinesArgsId, limitToInt } from './timeline.js';
|
||||||
import { emojiRegexAtStartToEnd } from "@/misc/emoji-regex.js";
|
import type { Entity } from 'megalodon';
|
||||||
import { MetaService } from '@/core/MetaService.js';
|
import type { FastifyInstance } from 'fastify';
|
||||||
|
|
||||||
function normalizeQuery(data: any) {
|
function normalizeQuery(data: any) {
|
||||||
const str = querystring.stringify(data);
|
const str = querystring.stringify(data);
|
||||||
return querystring.parse(str);
|
return querystring.parse(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
export class apiStatusMastodon {
|
export class ApiStatusMastodon {
|
||||||
private fastify: FastifyInstance;
|
private fastify: FastifyInstance;
|
||||||
private metaService: MetaService;
|
|
||||||
|
|
||||||
constructor(fastify: FastifyInstance) {
|
constructor(fastify: FastifyInstance) {
|
||||||
this.fastify = fastify;
|
this.fastify = fastify;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getStatus() {
|
public async getStatus() {
|
||||||
this.fastify.get<{ Params: { id: string } }>("/v1/statuses/:id", async (_request, reply) => {
|
this.fastify.get<{ Params: { id: string } }>('/v1/statuses/:id', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -36,7 +34,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getContext() {
|
public async getContext() {
|
||||||
this.fastify.get<{ Params: { id: string } }>("/v1/statuses/:id/context", async (_request, reply) => {
|
this.fastify.get<{ Params: { id: string } }>('/v1/statuses/:id/context', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -44,7 +42,7 @@ export class apiStatusMastodon {
|
||||||
try {
|
try {
|
||||||
const data = await client.getStatusContext(
|
const data = await client.getStatusContext(
|
||||||
convertId(_request.params.id, IdType.SharkeyId),
|
convertId(_request.params.id, IdType.SharkeyId),
|
||||||
convertTimelinesArgsId(limitToInt(query))
|
convertTimelinesArgsId(limitToInt(query)),
|
||||||
);
|
);
|
||||||
data.data.ancestors = data.data.ancestors.map((status: Entity.Status) => convertStatus(status));
|
data.data.ancestors = data.data.ancestors.map((status: Entity.Status) => convertStatus(status));
|
||||||
data.data.descendants = data.data.descendants.map((status: Entity.Status) => convertStatus(status));
|
data.data.descendants = data.data.descendants.map((status: Entity.Status) => convertStatus(status));
|
||||||
|
@ -57,7 +55,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getHistory() {
|
public async getHistory() {
|
||||||
this.fastify.get<{ Params: { id: string } }>("/v1/statuses/:id/history", async (_request, reply) => {
|
this.fastify.get<{ Params: { id: string } }>('/v1/statuses/:id/history', async (_request, reply) => {
|
||||||
try {
|
try {
|
||||||
reply.code(401).send({ message: 'Not Implemented' });
|
reply.code(401).send({ message: 'Not Implemented' });
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -68,7 +66,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getReblogged() {
|
public async getReblogged() {
|
||||||
this.fastify.get<{ Params: { id: string } }>("/v1/statuses/:id/reblogged_by", async (_request, reply) => {
|
this.fastify.get<{ Params: { id: string } }>('/v1/statuses/:id/reblogged_by', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -83,7 +81,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getFavourites() {
|
public async getFavourites() {
|
||||||
this.fastify.get<{ Params: { id: string } }>("/v1/statuses/:id/favourited_by", async (_request, reply) => {
|
this.fastify.get<{ Params: { id: string } }>('/v1/statuses/:id/favourited_by', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -98,7 +96,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getMedia() {
|
public async getMedia() {
|
||||||
this.fastify.get<{ Params: { id: string } }>("/v1/media/:id", async (_request, reply) => {
|
this.fastify.get<{ Params: { id: string } }>('/v1/media/:id', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -113,7 +111,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getPoll() {
|
public async getPoll() {
|
||||||
this.fastify.get<{ Params: { id: string } }>("/v1/polls/:id", async (_request, reply) => {
|
this.fastify.get<{ Params: { id: string } }>('/v1/polls/:id', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -128,7 +126,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async votePoll() {
|
public async votePoll() {
|
||||||
this.fastify.post<{ Params: { id: string } }>("/v1/polls/:id/votes", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string } }>('/v1/polls/:id/votes', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -144,24 +142,22 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async postStatus() {
|
public async postStatus() {
|
||||||
this.fastify.post("/v1/statuses", async (_request, reply) => {
|
this.fastify.post('/v1/statuses', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
let body: any = _request.body;
|
let body: any = _request.body;
|
||||||
try {
|
try {
|
||||||
if (body.in_reply_to_id)
|
if (body.in_reply_to_id) body.in_reply_to_id = convertId(body.in_reply_to_id, IdType.SharkeyId);
|
||||||
body.in_reply_to_id = convertId(body.in_reply_to_id, IdType.SharkeyId);
|
if (body.quote_id) body.quote_id = convertId(body.quote_id, IdType.SharkeyId);
|
||||||
if (body.quote_id)
|
|
||||||
body.quote_id = convertId(body.quote_id, IdType.SharkeyId);
|
|
||||||
if (
|
if (
|
||||||
(!body.poll && body["poll[options][]"]) ||
|
(!body.poll && body['poll[options][]']) ||
|
||||||
(!body.media_ids && body["media_ids[]"])
|
(!body.media_ids && body['media_ids[]'])
|
||||||
) {
|
) {
|
||||||
body = normalizeQuery(body);
|
body = normalizeQuery(body);
|
||||||
}
|
}
|
||||||
const text = body.status;
|
const text = body.status;
|
||||||
const removed = text.replace(/@\S+/g, "").replace(/\s|/g, "");
|
const removed = text.replace(/@\S+/g, '').replace(/\s|/g, '');
|
||||||
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) {
|
||||||
|
@ -171,7 +167,7 @@ export class apiStatusMastodon {
|
||||||
);
|
);
|
||||||
reply.send(a.data);
|
reply.send(a.data);
|
||||||
}
|
}
|
||||||
if (body.in_reply_to_id && removed === "/unreact") {
|
if (body.in_reply_to_id && removed === '/unreact') {
|
||||||
try {
|
try {
|
||||||
const id = body.in_reply_to_id;
|
const id = body.in_reply_to_id;
|
||||||
const post = await client.getStatus(id);
|
const post = await client.getStatus(id);
|
||||||
|
@ -186,28 +182,25 @@ export class apiStatusMastodon {
|
||||||
if (!body.media_ids) body.media_ids = undefined;
|
if (!body.media_ids) body.media_ids = undefined;
|
||||||
if (body.media_ids && !body.media_ids.length) body.media_ids = undefined;
|
if (body.media_ids && !body.media_ids.length) body.media_ids = undefined;
|
||||||
if (body.media_ids) {
|
if (body.media_ids) {
|
||||||
body.media_ids = (body.media_ids as string[]).map((p) =>convertId(p, IdType.SharkeyId));
|
body.media_ids = (body.media_ids as string[]).map((p) => convertId(p, IdType.SharkeyId));
|
||||||
}
|
}
|
||||||
|
|
||||||
const { sensitive } = body;
|
const { sensitive } = body;
|
||||||
body.sensitive = typeof sensitive === "string" ? sensitive === "true" : sensitive;
|
body.sensitive = typeof sensitive === 'string' ? sensitive === 'true' : sensitive;
|
||||||
|
|
||||||
if (body.poll) {
|
if (body.poll) {
|
||||||
if (
|
if (
|
||||||
body.poll.expires_in != null &&
|
body.poll.expires_in != null &&
|
||||||
typeof body.poll.expires_in === "string"
|
typeof body.poll.expires_in === 'string'
|
||||||
)
|
) body.poll.expires_in = parseInt(body.poll.expires_in);
|
||||||
body.poll.expires_in = parseInt(body.poll.expires_in);
|
|
||||||
if (
|
if (
|
||||||
body.poll.multiple != null &&
|
body.poll.multiple != null &&
|
||||||
typeof body.poll.multiple === "string"
|
typeof body.poll.multiple === 'string'
|
||||||
)
|
) body.poll.multiple = body.poll.multiple === 'true';
|
||||||
body.poll.multiple = body.poll.multiple == "true";
|
|
||||||
if (
|
if (
|
||||||
body.poll.hide_totals != null &&
|
body.poll.hide_totals != null &&
|
||||||
typeof body.poll.hide_totals === "string"
|
typeof body.poll.hide_totals === 'string'
|
||||||
)
|
) body.poll.hide_totals = body.poll.hide_totals === 'true';
|
||||||
body.poll.hide_totals = body.poll.hide_totals == "true";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await client.postStatus(text, body);
|
const data = await client.postStatus(text, body);
|
||||||
|
@ -220,14 +213,14 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async addFavourite() {
|
public async addFavourite() {
|
||||||
this.fastify.post<{ Params: { id: string } }>("/v1/statuses/:id/favourite", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string } }>('/v1/statuses/:id/favourite', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = (await client.createEmojiReaction(
|
const data = (await client.createEmojiReaction(
|
||||||
convertId(_request.params.id, IdType.SharkeyId),
|
convertId(_request.params.id, IdType.SharkeyId),
|
||||||
'⭐'
|
'⭐',
|
||||||
)) as any;
|
)) as any;
|
||||||
reply.send(convertStatus(data.data));
|
reply.send(convertStatus(data.data));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -238,14 +231,14 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async rmFavourite() {
|
public async rmFavourite() {
|
||||||
this.fastify.post<{ Params: { id: string } }>("/v1/statuses/:id/unfavourite", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string } }>('/v1/statuses/:id/unfavourite', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
const data = await client.deleteEmojiReaction(
|
const data = await client.deleteEmojiReaction(
|
||||||
convertId(_request.params.id, IdType.SharkeyId),
|
convertId(_request.params.id, IdType.SharkeyId),
|
||||||
'⭐'
|
'⭐',
|
||||||
);
|
);
|
||||||
reply.send(convertStatus(data.data));
|
reply.send(convertStatus(data.data));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -256,7 +249,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async reblogStatus() {
|
public async reblogStatus() {
|
||||||
this.fastify.post<{ Params: { id: string } }>("/v1/statuses/:id/reblog", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string } }>('/v1/statuses/:id/reblog', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -271,7 +264,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async unreblogStatus() {
|
public async unreblogStatus() {
|
||||||
this.fastify.post<{ Params: { id: string } }>("/v1/statuses/:id/unreblog", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string } }>('/v1/statuses/:id/unreblog', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -286,7 +279,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async bookmarkStatus() {
|
public async bookmarkStatus() {
|
||||||
this.fastify.post<{ Params: { id: string } }>("/v1/statuses/:id/bookmark", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string } }>('/v1/statuses/:id/bookmark', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -301,7 +294,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async unbookmarkStatus() {
|
public async unbookmarkStatus() {
|
||||||
this.fastify.post<{ Params: { id: string } }>("/v1/statuses/:id/unbookmark", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string } }>('/v1/statuses/:id/unbookmark', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -316,7 +309,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async pinStatus() {
|
public async pinStatus() {
|
||||||
this.fastify.post<{ Params: { id: string } }>("/v1/statuses/:id/pin", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string } }>('/v1/statuses/:id/pin', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -331,7 +324,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async unpinStatus() {
|
public async unpinStatus() {
|
||||||
this.fastify.post<{ Params: { id: string } }>("/v1/statuses/:id/unpin", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string } }>('/v1/statuses/:id/unpin', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -346,7 +339,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async reactStatus() {
|
public async reactStatus() {
|
||||||
this.fastify.post<{ Params: { id: string, name: string } }>("/v1/statuses/:id/react/:name", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string, name: string } }>('/v1/statuses/:id/react/:name', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -361,7 +354,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async unreactStatus() {
|
public async unreactStatus() {
|
||||||
this.fastify.post<{ Params: { id: string, name: string } }>("/v1/statuses/:id/unreact/:name", async (_request, reply) => {
|
this.fastify.post<{ Params: { id: string, name: string } }>('/v1/statuses/:id/unreact/:name', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -376,7 +369,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateMedia() {
|
public async updateMedia() {
|
||||||
this.fastify.put<{ Params: { id: string } }>("/v1/media/:id", async (_request, reply) => {
|
this.fastify.put<{ Params: { id: string } }>('/v1/media/:id', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
@ -391,7 +384,7 @@ export class apiStatusMastodon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteStatus() {
|
public async deleteStatus() {
|
||||||
this.fastify.delete<{ Params: { id: string } }>("/v1/statuses/:id", async (_request, reply) => {
|
this.fastify.delete<{ Params: { id: string } }>('/v1/statuses/:id', async (_request, reply) => {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
const accessTokens = _request.headers.authorization;
|
const accessTokens = _request.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
import { convertId, IdConvertType as IdType, convertAccount, convertConversation, convertList, convertStatus } from '../converters.js';
|
|
||||||
import { ParsedUrlQuery } from 'querystring';
|
import { ParsedUrlQuery } from 'querystring';
|
||||||
import type { Entity, MegalodonInterface } from 'megalodon';
|
import { convertId, IdConvertType as IdType, convertAccount, convertConversation, convertList, convertStatus } from '../converters.js';
|
||||||
import type { FastifyInstance } from 'fastify';
|
|
||||||
import { getClient } from '../MastodonApiServerService.js';
|
import { getClient } from '../MastodonApiServerService.js';
|
||||||
|
import type { Entity } from 'megalodon';
|
||||||
|
import type { FastifyInstance } from 'fastify';
|
||||||
|
|
||||||
export function limitToInt(q: ParsedUrlQuery) {
|
export function limitToInt(q: ParsedUrlQuery) {
|
||||||
let object: any = q;
|
const object: any = q;
|
||||||
if (q.limit)
|
if (q.limit) if (typeof q.limit === 'string') object.limit = parseInt(q.limit, 10);
|
||||||
if (typeof q.limit === 'string') object.limit = parseInt(q.limit, 10);
|
if (q.offset) if (typeof q.offset === 'string') object.offset = parseInt(q.offset, 10);
|
||||||
if (q.offset)
|
|
||||||
if (typeof q.offset === 'string') object.offset = parseInt(q.offset, 10);
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,55 +20,23 @@ export function argsToBools(q: ParsedUrlQuery) {
|
||||||
// - https://docs.joinmastodon.org/methods/accounts/#statuses
|
// - https://docs.joinmastodon.org/methods/accounts/#statuses
|
||||||
// - https://docs.joinmastodon.org/methods/timelines/#public
|
// - https://docs.joinmastodon.org/methods/timelines/#public
|
||||||
// - https://docs.joinmastodon.org/methods/timelines/#tag
|
// - https://docs.joinmastodon.org/methods/timelines/#tag
|
||||||
let object: any = q;
|
const object: any = q;
|
||||||
if (q.only_media)
|
if (q.only_media) if (typeof q.only_media === 'string') object.only_media = toBoolean(q.only_media);
|
||||||
if (typeof q.only_media === 'string')
|
if (q.exclude_replies) if (typeof q.exclude_replies === 'string') object.exclude_replies = toBoolean(q.exclude_replies);
|
||||||
object.only_media = toBoolean(q.only_media);
|
if (q.exclude_reblogs) if (typeof q.exclude_reblogs === 'string') object.exclude_reblogs = toBoolean(q.exclude_reblogs);
|
||||||
if (q.exclude_replies)
|
if (q.pinned) if (typeof q.pinned === 'string') object.pinned = toBoolean(q.pinned);
|
||||||
if (typeof q.exclude_replies === 'string')
|
if (q.local) if (typeof q.local === 'string') object.local = toBoolean(q.local);
|
||||||
object.exclude_replies = toBoolean(q.exclude_replies);
|
|
||||||
if (q.exclude_reblogs)
|
|
||||||
if (typeof q.exclude_reblogs === 'string')
|
|
||||||
object.exclude_reblogs = toBoolean(q.exclude_reblogs);
|
|
||||||
if (q.pinned)
|
|
||||||
if (typeof q.pinned === 'string') object.pinned = toBoolean(q.pinned);
|
|
||||||
if (q.local)
|
|
||||||
if (typeof q.local === 'string') object.local = toBoolean(q.local);
|
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertTimelinesArgsId(q: ParsedUrlQuery) {
|
export function convertTimelinesArgsId(q: ParsedUrlQuery) {
|
||||||
if (typeof q.min_id === 'string')
|
if (typeof q.min_id === 'string') q.min_id = convertId(q.min_id, IdType.SharkeyId);
|
||||||
q.min_id = convertId(q.min_id, IdType.SharkeyId);
|
if (typeof q.max_id === 'string') q.max_id = convertId(q.max_id, IdType.SharkeyId);
|
||||||
if (typeof q.max_id === 'string')
|
if (typeof q.since_id === 'string') q.since_id = convertId(q.since_id, IdType.SharkeyId);
|
||||||
q.max_id = convertId(q.max_id, IdType.SharkeyId);
|
|
||||||
if (typeof q.since_id === 'string')
|
|
||||||
q.since_id = convertId(q.since_id, IdType.SharkeyId);
|
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeHTML(str: string) {
|
export class ApiTimelineMastodon {
|
||||||
if (!str) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return str
|
|
||||||
.replace(/&/g, '&')
|
|
||||||
.replace(/</g, '<')
|
|
||||||
.replace(/>/g, '>')
|
|
||||||
.replace(/'/g, '"')
|
|
||||||
.replace(/'/g, ''');
|
|
||||||
}
|
|
||||||
|
|
||||||
function nl2br(str: string) {
|
|
||||||
if (!str) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
str = str.replace(/\r\n/g, '<br />');
|
|
||||||
str = str.replace(/(\n|\r)/g, '<br />');
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class apiTimelineMastodon {
|
|
||||||
private fastify: FastifyInstance;
|
private fastify: FastifyInstance;
|
||||||
|
|
||||||
constructor(fastify: FastifyInstance) {
|
constructor(fastify: FastifyInstance) {
|
||||||
|
@ -166,7 +132,7 @@ export class apiTimelineMastodon {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getList(){
|
public async getList() {
|
||||||
this.fastify.get<{ Params: { id: string } }>('/v1/lists/:id', async (_request, reply) => {
|
this.fastify.get<{ Params: { id: string } }>('/v1/lists/:id', async (_request, reply) => {
|
||||||
try {
|
try {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
|
@ -199,7 +165,7 @@ export class apiTimelineMastodon {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getListAccounts(){
|
public async getListAccounts() {
|
||||||
this.fastify.get<{ Params: { id: string } }>('/v1/lists/:id/accounts', async (_request, reply) => {
|
this.fastify.get<{ Params: { id: string } }>('/v1/lists/:id/accounts', async (_request, reply) => {
|
||||||
try {
|
try {
|
||||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||||
|
@ -209,7 +175,7 @@ export class apiTimelineMastodon {
|
||||||
const query: any = _request.query;
|
const query: any = _request.query;
|
||||||
const data = await client.getAccountsInList(
|
const data = await client.getAccountsInList(
|
||||||
convertId(params.id, IdType.SharkeyId),
|
convertId(params.id, IdType.SharkeyId),
|
||||||
convertTimelinesArgsId(query)
|
convertTimelinesArgsId(query),
|
||||||
);
|
);
|
||||||
reply.send(data.data.map((account: Entity.Account) => convertAccount(account)));
|
reply.send(data.data.map((account: Entity.Account) => convertAccount(account)));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -230,7 +196,7 @@ export class apiTimelineMastodon {
|
||||||
const query: any = _request.query;
|
const query: any = _request.query;
|
||||||
const data = await client.addAccountsToList(
|
const data = await client.addAccountsToList(
|
||||||
convertId(params.id, IdType.SharkeyId),
|
convertId(params.id, IdType.SharkeyId),
|
||||||
(query.accounts_id as string[]).map((id) => convertId(id, IdType.SharkeyId))
|
(query.accounts_id as string[]).map((id) => convertId(id, IdType.SharkeyId)),
|
||||||
);
|
);
|
||||||
reply.send(data.data);
|
reply.send(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -251,7 +217,7 @@ export class apiTimelineMastodon {
|
||||||
const query: any = _request.query;
|
const query: any = _request.query;
|
||||||
const data = await client.deleteAccountsFromList(
|
const data = await client.deleteAccountsFromList(
|
||||||
convertId(params.id, IdType.SharkeyId),
|
convertId(params.id, IdType.SharkeyId),
|
||||||
(query.accounts_id as string[]).map((id) => convertId(id, IdType.SharkeyId))
|
(query.accounts_id as string[]).map((id) => convertId(id, IdType.SharkeyId)),
|
||||||
);
|
);
|
||||||
reply.send(data.data);
|
reply.send(data.data);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -313,5 +279,4 @@ export class apiTimelineMastodon {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue