Feat/restructure api (#6664)

* Restructured rest api

* Added swagger ui

* Added reworked rest api

* Reformatted code, excluded unnecessary newlines and removed version 2.2.2
This commit is contained in:
SamTV12345 2024-09-21 13:00:39 +02:00 committed by GitHub
parent 76e52e51d9
commit 12f81cfb5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 1588 additions and 16 deletions

View file

@ -82,6 +82,12 @@
"expressCreateServer": "ep_etherpad-lite/node/hooks/express/errorhandling"
}
},
{
"name": "restApi",
"hooks": {
"expressCreateServer": "ep_etherpad-lite/node/handler/RestAPI"
}
},
{
"name": "socketio",
"hooks": {

View file

@ -24,10 +24,10 @@ import {MapArrayType} from "../types/MapType";
const api = require('../db/API');
const padManager = require('../db/PadManager');
import createHTTPError from 'http-errors';
import {Http2ServerRequest, Http2ServerResponse} from "node:http2";
import {Http2ServerRequest} from "node:http2";
import {publicKeyExported} from "../security/OAuth2Provider";
import {jwtVerify} from "jose";
import {apikey} from './APIKeyHandler'
import {APIFields, apikey} from './APIKeyHandler'
// a list of all functions
const version:MapArrayType<any> = {};
@ -141,6 +141,7 @@ version['1.3.0'] = {
setText: ['padID', 'text', 'authorId'],
};
// set the latest available API version here
exports.latestApiVersion = '1.3.0';
@ -148,13 +149,6 @@ exports.latestApiVersion = '1.3.0';
exports.version = version;
type APIFields = {
apikey: string;
api_key: string;
padID: string;
padName: string;
authorization: string;
}
/**
* Handles an HTTP API call

View file

@ -7,6 +7,16 @@ const settings = require('../utils/Settings');
const apiHandlerLogger = log4js.getLogger('APIHandler');
export type APIFields = {
apikey: string;
api_key: string;
padID: string;
padName: string;
authorization: string;
}
// ensure we have an apikey
export let apikey:string|null = null;
const apikeyFilename = absolutePaths.makeAbsolute(argv.apikey || './APIKEY.txt');

1527
src/node/handler/RestAPI.ts Normal file

File diff suppressed because it is too large Load diff

View file

@ -12,6 +12,7 @@ const webaccess = require('./webaccess');
const plugins = require('../../../static/js/pluginfw/plugin_defs');
import {build, buildSync} from 'esbuild'
import {ArgsExpressType} from "../../types/ArgsExpressType";
let ioI: { sockets: { sockets: any[]; }; } | null = null
exports.socketio = (hookName: string, {io}: any) => {
@ -19,7 +20,7 @@ exports.socketio = (hookName: string, {io}: any) => {
}
exports.expressPreSession = async (hookName:string, {app}:any) => {
exports.expressPreSession = async (hookName:string, {app}:ArgsExpressType) => {
// This endpoint is intended to conform to:
// https://www.ietf.org/archive/id/draft-inadarei-api-health-check-06.html
app.get('/health', (req:any, res:any) => {
@ -243,7 +244,7 @@ const convertTypescriptWatched = (content: string, cb: (output:string, hash: str
})
}
exports.expressCreateServer = async (hookName: string, args: any, cb: Function) => {
exports.expressCreateServer = async (hookName: string, args: ArgsExpressType, cb: Function) => {
const padString = eejs.require('ep_etherpad-lite/templates/padBootstrap.js', {
pluginModules: (() => {
const pluginModules = new Set();

View file

@ -153,7 +153,7 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp
});
args.app.post('/interaction/:uid', async (req: Http2ServerRequest, res: Http2ServerResponse, next:Function) => {
args.app.post('/interaction/:uid', async (req, res, next) => {
const formid = new IncomingForm();
try {
// @ts-ignore
@ -226,7 +226,7 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp
})
args.app.get('/interaction/:uid', async (req: Request, res: Response, next: Function) => {
args.app.get('/interaction/:uid', async (req, res, next) => {
try {
const {
uid, prompt, params, session,

View file

@ -1,5 +1,7 @@
import {Express} from "express";
export type ArgsExpressType = {
app:any,
app:Express,
io: any,
server:any
}
}

View file

@ -69,6 +69,7 @@
"socket.io": "^4.7.5",
"socket.io-client": "^4.7.5",
"superagent": "10.1.0",
"swagger-ui-express": "^5.0.1",
"tinycon": "0.6.8",
"tsx": "4.19.1",
"ueberdb2": "^5.0.2",
@ -97,6 +98,7 @@
"@types/semver": "^7.5.8",
"@types/sinon": "^17.0.3",
"@types/supertest": "^6.0.2",
"@types/swagger-ui-express": "^4.1.6",
"@types/underscore": "^1.11.15",
"@types/whatwg-mimetype": "^3.0.2",
"chokidar": "^4.0.0",