diff --git a/docs/API.md b/docs/API.md index 691936eb7..3a2d3e564 100644 --- a/docs/API.md +++ b/docs/API.md @@ -46,6 +46,19 @@ You can use the given include paths to supply in the userArguments for compilati You will need the library id's, and the version id's to supply to **compile** if you want to include libraries during compilation. +### `GET /api/tools/` - return a list of tools available for a language + +Returns a list of tools available for the provided language id. This request only returns data in JSON. + +The response contains an array of tool objects, each with: +- `id`: Tool identifier +- `name`: Human-readable tool name +- `type`: Tool type (e.g., "postprocessor") +- `languageId`: Language the tool supports +- `allowStdin`: Boolean indicating if the tool accepts stdin input + +You can use the tool id's in the `tools` array when making compilation requests. + ### `GET /api/shortlinkinfo/` - return information about a given link Returns information like Sourcecode, Compiler settings and libraries for a given link id. This request only returns data diff --git a/lib/handlers/api.ts b/lib/handlers/api.ts index 88695f64e..6671d483b 100644 --- a/lib/handlers/api.ts +++ b/lib/handlers/api.ts @@ -91,6 +91,8 @@ export class ApiHandler { this.handle.route('/libraries').get(this.handleAllLibraries.bind(this)).all(methodNotAllowed); + this.handle.route('/tools/:language').get(this.handleLangTools.bind(this)).all(methodNotAllowed); + this.handle .route('/asm/:opcode') .get((req, res) => res.redirect(`amd64/${req.params.opcode}`)) @@ -247,6 +249,22 @@ export class ApiHandler { }); } + getToolsAsArray(languageId: LanguageKey) { + const toolsForLanguageObj = unwrap(this.options).options.tools[languageId]; + if (!toolsForLanguageObj) return []; + + return Object.keys(toolsForLanguageObj).map(key => { + const tool = toolsForLanguageObj[key]; + return { + id: key, + name: tool.name, + type: tool.type, + languageId: tool.languageId || languageId, + allowStdin: tool.stdinHint !== 'disabled', + }; + }); + } + handleLangLibraries(req: express.Request, res: express.Response, next: express.NextFunction) { if (this.options) { if (req.params.language) { @@ -265,6 +283,24 @@ export class ApiHandler { } } + handleLangTools(req: express.Request, res: express.Response, next: express.NextFunction) { + if (this.options) { + if (req.params.language) { + res.send(this.getToolsAsArray(req.params.language as LanguageKey)); + } else { + next({ + statusCode: 404, + message: 'Language is required', + }); + } + } else { + next({ + statusCode: 500, + message: 'Internal error', + }); + } + } + async handleLocalExecution(req: express.Request, res: express.Response, next: express.NextFunction) { if (!req.params.hash) { next({statusCode: 404, message: 'No hash supplied'});