feat: 🔒 expand /api/v1/instance/peers to proper endpoint and check for private mode

Closes #10358
This commit is contained in:
ThatOneCalculator 2023-06-24 13:00:50 -07:00
parent 1560ece843
commit c252c16fc2
3 changed files with 33 additions and 17 deletions

View File

@ -1,11 +1,13 @@
import type { IEndpoint } from "./endpoints";
import * as cp___instanceInfo from "./endpoints/compatibility/instance-info.js";
import * as cp___customEmojis from "./endpoints/compatibility/custom-emojis.js";
import * as cp___instance_info from "./endpoints/compatibility/instance-info.js";
import * as cp___custom_emojis from "./endpoints/compatibility/custom-emojis.js";
import * as ep___instance_peers from "./endpoints/compatibility/peers.js";
const cps = [
["v1/instance", cp___instanceInfo],
["v1/custom_emojis", cp___customEmojis],
["v1/instance", cp___instance_info],
["v1/custom_emojis", cp___custom_emojis],
["v1/instance/peers", ep___instance_peers],
];
const compatibility: IEndpoint[] = cps.map(([name, cp]) => {

View File

@ -0,0 +1,25 @@
import { Instances } from "@/models/index.js";
import define from "../../define.js";
export const meta = {
tags: ["meta"],
requireCredential: false,
requireCredentialPrivateMode: true,
allowGet: true,
cacheSec: 60,
} as const;
export const paramDef = {
type: "object",
} as const;
export default define(meta, paramDef, async (ps) => {
const instances = await Instances.find({
select: ["host"],
where: {
isSuspended: false,
},
});
return instances.map((instance) => instance.host);
});

View File

@ -87,7 +87,7 @@ mastoFileRouter.post("/v1/media", upload.single("file"), async (ctx) => {
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
let multipartData = await ctx.file;
const multipartData = await ctx.file;
if (!multipartData) {
ctx.body = { error: "No image" };
ctx.status = 401;
@ -106,7 +106,7 @@ mastoFileRouter.post("/v2/media", upload.single("file"), async (ctx) => {
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
let multipartData = await ctx.file;
const multipartData = await ctx.file;
if (!multipartData) {
ctx.body = { error: "No image" };
ctx.status = 401;
@ -185,17 +185,6 @@ router.use(discord.routes());
router.use(github.routes());
router.use(twitter.routes());
router.get("/v1/instance/peers", async (ctx) => {
const instances = await Instances.find({
select: ["host"],
where: {
isSuspended: false,
},
});
ctx.body = instances.map((instance) => instance.host);
});
router.post("/miauth/:session/check", async (ctx) => {
const token = await AccessTokens.findOneBy({
session: ctx.params.session,