Finish misc. routes.

This commit is contained in:
Paul
2021-07-11 19:17:00 +01:00
parent a4cd54d579
commit ddc634b1d2
7 changed files with 1371 additions and 1134 deletions
+1225 -1103
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,6 +1,6 @@
import { OpenAPIV3 } from "openapi-types";
export async function success(description: string, json?: Promise<OpenAPIV3.MediaTypeObject> | OpenAPIV3.MediaTypeObject | OpenAPIV3.ReferenceObject): Promise<{ responses: OpenAPIV3.ResponsesObject }> {
export async function success(description: string, json?: Promise<OpenAPIV3.MediaTypeObject> | OpenAPIV3.MediaTypeObject | OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject): Promise<{ responses: OpenAPIV3.ResponsesObject }> {
const response: OpenAPIV3.ResponseObject = {
description
};
+5 -4
View File
@@ -1,8 +1,9 @@
export async function load() {
await import('./core.js');
await import('./users.js');
await import('./channels.js');
await import('./servers.js');
// await import('./core.js');
// await import('./users.js');
// await import('./channels.js');
// await import('./servers.js');
await import('./misc.js');
}
await load();
+131
View File
@@ -0,0 +1,131 @@
import { body, parameter, ref, success } from "../openapi/generators.js";
import { group, resource, route, routeAuthenticated, tag } from "../openapi/paths.js";
import { schema } from "../typescript.js";
group("Miscellaneous");
//#region Invites
tag("Invites", "View, join and delete invites");
const inviteParams = {
parameters: [
await parameter("invite", "Invite Code", { type: 'string' })
]
}
resource('/invites/:invite', {
get: routeAuthenticated(
"Fetch Invite",
"Fetch an invite by its ID.",
{
...inviteParams,
...await success("Invite", ref("RetrievedInvite"))
}
),
post: routeAuthenticated(
"Join Invite",
"Join an invite by its ID.",
{
...inviteParams,
...await success("Invite", schema`
import { Channel } from './Channels';
import { Server } from './Servers';
interface ${'InviteData'} {
type: 'Server',
channel: Channel,
server: Server
}
`)
}
),
delete: routeAuthenticated(
"Delete Invite",
"Delete an invite by its ID.",
{
...inviteParams,
...await success("Deleted invite.")
}
),
});
//#endregion
//#region Sync
tag("Sync", "Upload and retrieve any JSON data between clients");
resource('/sync/settings/fetch', {
post: routeAuthenticated(
"Fetch Settings",
"Fetch settings from server filtered by keys.\n\nThis will return an object with the requested keys, each value is a tuple of `(timestamp, value)`, the value is the previously uploaded data.",
{
...await body("Options", schema`
interface ${'FetchSettingsOptions'} {
/**
* Keys to fetch
*/
keys: string[]
}
`),
...await success("Settings Data", schema`
type ${'SettingsData'} = { [key: string]: [ number, string ] };
`)
}
)
});
resource('/sync/settings/set', {
post: routeAuthenticated(
"Set Settings",
"Upload data to save to settings.",
{
parameters: [
{
name: 'timestamp',
in: 'query',
description: "Timestamp of settings change. Useful to prevent a feedback loop.",
schema: {
type: 'number'
}
}
],
...await body("Settings Data", schema`
interface ${'SetSettingsData'} {
[key: string]: string
}
`),
...await success("Successfully synced data.")
}
)
});
resource('/sync/unreads', {
post: routeAuthenticated(
"Fetch Unreads",
"Fetch information about unread state on channels.",
await success("Unreads Data", ref("ChannelUnread"))
)
});
//#endregion
//#region Web Push
tag("Web Push", "Subscribe to and receive Revolt push notifications while offline");
resource('/push/subscribe', {
post: routeAuthenticated(
"Subscribe",
"Create a new Web Push subscription.\n\nIf an existing subscription exists on this session, it will be removed.",
{
...await body("Web Push Subscription", ref("WebPushSubscription")),
...await success("Subscribed successfully.")
}
)
});
resource('/push/unsubscribe', {
post: routeAuthenticated(
"Unsubscribe",
"Remove the Web Push subscription associated with the current session.",
await success("Unsubscribed successfully.")
)
});
//#endregion
+1 -1
View File
File diff suppressed because one or more lines are too long
+6
View File
@@ -15,3 +15,9 @@ export interface ChannelUnread {
last_id: string,
mentions?: string[]
}
export interface WebPushSubscription {
endpoint: String,
p256dh: String,
auth: String,
}
+2 -25
View File
@@ -1,28 +1,5 @@
import type { Status } from './Users';
import type { AutumnId } from './_common';
interface EditUser {
status?: Status;
/**
* User profile data
**/
profile?: {
/**
* Text to set as user profile description
* @maxLength 2000
*/
content?: string;
background?: AutumnId;
}
avatar?: AutumnId;
/**
* Field to remove from user object
*/
remove?: 'ProfileContent' | 'ProfileBackground' | 'StatusText' | 'Avatar';
interface SetSettingsData {
[key: string]: string
}