Add new /api/tools/<language> API endpoint (#7950)

This commit is contained in:
Patrick Quist
2025-07-27 13:47:06 +02:00
committed by GitHub
parent 0261d0a579
commit f70ab79be4
2 changed files with 49 additions and 0 deletions

View File

@@ -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/<language-id>` - 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/<linkid>` - return information about a given link
Returns information like Sourcecode, Compiler settings and libraries for a given link id. This request only returns data

View File

@@ -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'});