diff --git a/components/webui/client/src/api/sql/index.ts b/components/webui/client/src/api/sql/index.ts index ff149a3456..3fd2b39928 100644 --- a/components/webui/client/src/api/sql/index.ts +++ b/components/webui/client/src/api/sql/index.ts @@ -8,7 +8,7 @@ import axios from "axios"; * @return */ const querySql = async (queryString: string) => { - return axios.post("/query/sql", {queryString}); + return axios.post("/api/archive-metadata/sql", {queryString}); }; export {querySql}; diff --git a/components/webui/server/eslint.config.mjs b/components/webui/server/eslint.config.mjs index 476fa04c30..a83674d43c 100644 --- a/components/webui/server/eslint.config.mjs +++ b/components/webui/server/eslint.config.mjs @@ -22,6 +22,7 @@ const EslintConfig = [ { // TypeBox imports capIsNewExceptions: [ + "Type.Any", "Type.Enum", "Type.Integer", "Type.Literal", diff --git a/components/webui/server/src/fastify-v2/routes/api/archive-metadata/index.ts b/components/webui/server/src/fastify-v2/routes/api/archive-metadata/index.ts new file mode 100644 index 0000000000..f52a9dc685 --- /dev/null +++ b/components/webui/server/src/fastify-v2/routes/api/archive-metadata/index.ts @@ -0,0 +1,39 @@ +import { + FastifyPluginAsyncTypebox, + Type, +} from "@fastify/type-provider-typebox"; +import {StatusCodes} from "http-status-codes"; + +import {SqlSchema} from "../../../schemas/archive-metadata.js"; + + +/** + * Archive metadata API routes. + * + * @param fastify + */ +const plugin: FastifyPluginAsyncTypebox = async (fastify) => { + const mysqlConnectionPool = fastify.mysql.pool; + + fastify.post( + "/sql", + { + schema: { + body: SqlSchema, + response: { + [StatusCodes.OK]: Type.Any(), + }, + tags: ["Archive Metadata"], + }, + }, + async (req, reply) => { + const {queryString} = req.body; + const [result] = await mysqlConnectionPool.query(queryString); + reply.code(StatusCodes.OK); + + return result; + }, + ); +}; + +export default plugin; diff --git a/components/webui/server/src/fastify-v2/schemas/archive-metadata.ts b/components/webui/server/src/fastify-v2/schemas/archive-metadata.ts new file mode 100644 index 0000000000..338d798197 --- /dev/null +++ b/components/webui/server/src/fastify-v2/schemas/archive-metadata.ts @@ -0,0 +1,13 @@ +import {Type} from "@sinclair/typebox"; + +import {StringSchema} from "./common.js"; + + +/** + * Schema for SQL query request. + */ +const SqlSchema = Type.Object({ + queryString: StringSchema, +}); + +export {SqlSchema}; diff --git a/components/webui/server/src/plugins/DbManager.ts b/components/webui/server/src/plugins/DbManager.ts index d42f513184..bc9abbdc56 100644 --- a/components/webui/server/src/plugins/DbManager.ts +++ b/components/webui/server/src/plugins/DbManager.ts @@ -82,18 +82,6 @@ class DbManager { }); } - /** - * Submits a query to MySQL. - * - * @param queryString - * @return The result from MySQL. - */ - async queryMySql (queryString: string) { - const [result] = await this.#mysqlConnectionPool.query(queryString); - return result; - } - - /** * Submits a stream extraction job to the scheduler and waits for it to finish. * diff --git a/components/webui/server/src/routes/query.ts b/components/webui/server/src/routes/query.ts index 30bd40d627..835d95a3f4 100644 --- a/components/webui/server/src/routes/query.ts +++ b/components/webui/server/src/routes/query.ts @@ -16,25 +16,9 @@ import { * @param app * @return */ -// eslint-disable-next-line max-lines-per-function const routes: FastifyPluginAsync = async (app) => { const fastify = app.withTypeProvider(); - fastify.post( - "/query/sql", - { - schema: { - body: Type.Object({ - queryString: Type.String({minLength: 1}), - }), - }, - }, - async (req) => { - const {queryString} = req.body; - return await fastify.dbManager.queryMySql(queryString); - }, - ); - fastify.post("/query/extract-stream", { schema: { body: Type.Object({