oapi: policies
This commit is contained in:
parent
1b1fbce4d3
commit
3fa2a95429
Binary file not shown.
Binary file not shown.
@ -16,25 +16,38 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import { Config } from "@spacebar/util";
|
import { Config } from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get(
|
||||||
const { cdn, gateway, api } = Config.get();
|
"/",
|
||||||
|
route({
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
body: "InstanceDomainsResponse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response) => {
|
||||||
|
const { cdn, gateway, api } = Config.get();
|
||||||
|
|
||||||
const IdentityForm = {
|
const IdentityForm = {
|
||||||
cdn: cdn.endpointPublic || process.env.CDN || "http://localhost:3001",
|
cdn:
|
||||||
gateway:
|
cdn.endpointPublic ||
|
||||||
gateway.endpointPublic ||
|
process.env.CDN ||
|
||||||
process.env.GATEWAY ||
|
"http://localhost:3001",
|
||||||
"ws://localhost:3001",
|
gateway:
|
||||||
defaultApiVersion: api.defaultVersion ?? 9,
|
gateway.endpointPublic ||
|
||||||
apiEndpoint: api.endpointPublic ?? "http://localhost:3001/api/",
|
process.env.GATEWAY ||
|
||||||
};
|
"ws://localhost:3001",
|
||||||
|
defaultApiVersion: api.defaultVersion ?? 9,
|
||||||
|
apiEndpoint: api.endpointPublic ?? "http://localhost:3001/api/",
|
||||||
|
};
|
||||||
|
|
||||||
res.json(IdentityForm);
|
res.json(IdentityForm);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@ -16,14 +16,24 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import { Config } from "@spacebar/util";
|
import { Config } from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get(
|
||||||
const { general } = Config.get();
|
"/",
|
||||||
res.json(general);
|
route({
|
||||||
});
|
responses: {
|
||||||
|
200: {
|
||||||
|
body: "GeneralConfigurationResponse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response) => {
|
||||||
|
const { general } = Config.get();
|
||||||
|
res.json(general);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@ -16,14 +16,24 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import { Config } from "@spacebar/util";
|
import { Config } from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get(
|
||||||
const { limits } = Config.get();
|
"/",
|
||||||
res.json(limits);
|
route({
|
||||||
});
|
responses: {
|
||||||
|
200: {
|
||||||
|
body: "LimitsConfigurationResponse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response) => {
|
||||||
|
const { limits } = Config.get();
|
||||||
|
res.json(limits);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@ -28,20 +28,33 @@ import {
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get(
|
||||||
if (!Config.get().security.statsWorldReadable) {
|
"/",
|
||||||
const rights = await getRights(req.user_id);
|
route({
|
||||||
rights.hasThrow("VIEW_SERVER_STATS");
|
responses: {
|
||||||
}
|
200: {
|
||||||
|
body: "InstanceStatsResponse",
|
||||||
res.json({
|
},
|
||||||
counts: {
|
403: {
|
||||||
user: await User.count(),
|
body: "APIErrorResponse",
|
||||||
guild: await Guild.count(),
|
},
|
||||||
message: await Message.count(),
|
|
||||||
members: await Member.count(),
|
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
});
|
async (req: Request, res: Response) => {
|
||||||
|
if (!Config.get().security.statsWorldReadable) {
|
||||||
|
const rights = await getRights(req.user_id);
|
||||||
|
rights.hasThrow("VIEW_SERVER_STATS");
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
counts: {
|
||||||
|
user: await User.count(),
|
||||||
|
guild: await Guild.count(),
|
||||||
|
message: await Message.count(),
|
||||||
|
members: await Member.count(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@ -16,11 +16,11 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { RouteRateLimit, RateLimitOptions } from ".";
|
import { RateLimitOptions, RouteRateLimit } from ".";
|
||||||
|
|
||||||
export class RateLimits {
|
export class RateLimits {
|
||||||
enabled: boolean = false;
|
enabled: boolean = false;
|
||||||
ip: Omit<RateLimitOptions, "bot_count"> = {
|
ip: RateLimitOptions = {
|
||||||
count: 500,
|
count: 500,
|
||||||
window: 5,
|
window: 5,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
import { GeneralConfiguration } from "../../config";
|
||||||
|
|
||||||
|
export type GeneralConfigurationResponse = GeneralConfiguration;
|
||||||
6
src/util/schemas/responses/InstanceDomainsResponse.ts
Normal file
6
src/util/schemas/responses/InstanceDomainsResponse.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export interface InstanceDomainsResponse {
|
||||||
|
cdn: string;
|
||||||
|
gateway: string;
|
||||||
|
defaultApiVersion: string;
|
||||||
|
apiEndpoint: string;
|
||||||
|
}
|
||||||
8
src/util/schemas/responses/InstanceStatsResponse.ts
Normal file
8
src/util/schemas/responses/InstanceStatsResponse.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export interface InstanceStatsResponse {
|
||||||
|
counts: {
|
||||||
|
user: number;
|
||||||
|
guild: number;
|
||||||
|
message: number;
|
||||||
|
members: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
import { LimitsConfiguration } from "../../config";
|
||||||
|
|
||||||
|
export type LimitsConfigurationResponse = LimitsConfiguration;
|
||||||
@ -11,6 +11,7 @@ export * from "./ChannelPinsResponse";
|
|||||||
export * from "./ChannelWebhooksResponse";
|
export * from "./ChannelWebhooksResponse";
|
||||||
export * from "./GatewayBotResponse";
|
export * from "./GatewayBotResponse";
|
||||||
export * from "./GatewayResponse";
|
export * from "./GatewayResponse";
|
||||||
|
export * from "./GeneralConfigurationResponse";
|
||||||
export * from "./GenerateRegistrationTokensResponse";
|
export * from "./GenerateRegistrationTokensResponse";
|
||||||
export * from "./GuildBansResponse";
|
export * from "./GuildBansResponse";
|
||||||
export * from "./GuildChannelsResponse";
|
export * from "./GuildChannelsResponse";
|
||||||
@ -29,6 +30,9 @@ export * from "./GuildVanityUrl";
|
|||||||
export * from "./GuildVoiceRegionsResponse";
|
export * from "./GuildVoiceRegionsResponse";
|
||||||
export * from "./GuildWidgetJsonResponse";
|
export * from "./GuildWidgetJsonResponse";
|
||||||
export * from "./GuildWidgetSettingsResponse";
|
export * from "./GuildWidgetSettingsResponse";
|
||||||
|
export * from "./InstanceDomainsResponse";
|
||||||
|
export * from "./InstanceStatsResponse";
|
||||||
|
export * from "./LimitsConfigurationResponse";
|
||||||
export * from "./LocationMetadataResponse";
|
export * from "./LocationMetadataResponse";
|
||||||
export * from "./MemberJoinGuildResponse";
|
export * from "./MemberJoinGuildResponse";
|
||||||
export * from "./OAuthAuthorizeResponse";
|
export * from "./OAuthAuthorizeResponse";
|
||||||
|
|||||||
Reference in New Issue
Block a user