feat: 🔒 expand /api/v1/instance/peers to proper endpoint and check for private mode
Closes #10358
This commit is contained in:
parent
0b2a84d805
commit
15e8db0563
|
@ -1,11 +1,13 @@
|
||||||
import type { IEndpoint } from "./endpoints";
|
import type { IEndpoint } from "./endpoints";
|
||||||
|
|
||||||
import * as cp___instanceInfo from "./endpoints/compatibility/instance-info.js";
|
import * as cp___instance_info from "./endpoints/compatibility/instance-info.js";
|
||||||
import * as cp___customEmojis from "./endpoints/compatibility/custom-emojis.js";
|
import * as cp___custom_emojis from "./endpoints/compatibility/custom-emojis.js";
|
||||||
|
import * as ep___instance_peers from "./endpoints/compatibility/peers.js";
|
||||||
|
|
||||||
const cps = [
|
const cps = [
|
||||||
["v1/instance", cp___instanceInfo],
|
["v1/instance", cp___instance_info],
|
||||||
["v1/custom_emojis", cp___customEmojis],
|
["v1/custom_emojis", cp___custom_emojis],
|
||||||
|
["v1/instance/peers", ep___instance_peers],
|
||||||
];
|
];
|
||||||
|
|
||||||
const compatibility: IEndpoint[] = cps.map(([name, cp]) => {
|
const compatibility: IEndpoint[] = cps.map(([name, cp]) => {
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
|
@ -87,7 +87,7 @@ mastoFileRouter.post("/v1/media", upload.single("file"), async (ctx) => {
|
||||||
const accessTokens = ctx.headers.authorization;
|
const accessTokens = ctx.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
let multipartData = await ctx.file;
|
const multipartData = await ctx.file;
|
||||||
if (!multipartData) {
|
if (!multipartData) {
|
||||||
ctx.body = { error: "No image" };
|
ctx.body = { error: "No image" };
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -106,7 +106,7 @@ mastoFileRouter.post("/v2/media", upload.single("file"), async (ctx) => {
|
||||||
const accessTokens = ctx.headers.authorization;
|
const accessTokens = ctx.headers.authorization;
|
||||||
const client = getClient(BASE_URL, accessTokens);
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
try {
|
try {
|
||||||
let multipartData = await ctx.file;
|
const multipartData = await ctx.file;
|
||||||
if (!multipartData) {
|
if (!multipartData) {
|
||||||
ctx.body = { error: "No image" };
|
ctx.body = { error: "No image" };
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
|
@ -185,17 +185,6 @@ router.use(discord.routes());
|
||||||
router.use(github.routes());
|
router.use(github.routes());
|
||||||
router.use(twitter.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) => {
|
router.post("/miauth/:session/check", async (ctx) => {
|
||||||
const token = await AccessTokens.findOneBy({
|
const token = await AccessTokens.findOneBy({
|
||||||
session: ctx.params.session,
|
session: ctx.params.session,
|
||||||
|
|
Loading…
Reference in New Issue