feat: convert json-schema to typescript
No more code duplication
This commit is contained in:
parent
29604a2ed1
commit
8b8844f9fb
@ -1,7 +1,6 @@
|
||||
export interface IFastifyValidationError {
|
||||
statusCode?: number;
|
||||
code?: string;
|
||||
validation?: any;
|
||||
}
|
||||
|
||||
export function getFastifyError(error: Error) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
|
||||
import { IParseSchema, rawHtmlSchema } from "../types/requests/api";
|
||||
import { GetRequest } from "../types/requests/browser";
|
||||
|
||||
import handlePage from "../handlers/main";
|
||||
import { generateRequestUrl } from "../utils/generate";
|
||||
@ -10,7 +9,7 @@ export default async function rawHtml(fastify: FastifyInstance) {
|
||||
fastify.get<IParseSchema>(
|
||||
"/api/raw-html",
|
||||
{ schema: rawHtmlSchema },
|
||||
async (request: GetRequest) => {
|
||||
async (request) => {
|
||||
return (
|
||||
await handlePage(
|
||||
request.query.url,
|
||||
|
@ -2,21 +2,13 @@ import { FastifySchema, FastifyRequest } from "fastify";
|
||||
import { IApiError, errorResponseSchema } from "../../errors/api";
|
||||
import { handlerSchema } from "../../handlers/handler.interface";
|
||||
import { engineList } from "../../handlers/main";
|
||||
import { FromSchema } from "json-schema-to-ts";
|
||||
|
||||
export interface IApiResponse<T> {
|
||||
data?: T;
|
||||
error?: IApiError;
|
||||
}
|
||||
|
||||
export interface IParseQuery {
|
||||
url: string;
|
||||
engine?: string;
|
||||
}
|
||||
|
||||
export interface IParseSchema {
|
||||
Querystring: IParseQuery;
|
||||
}
|
||||
|
||||
export const parseQuerySchema = {
|
||||
type: "object",
|
||||
required: ["url"],
|
||||
@ -30,7 +22,7 @@ export const parseQuerySchema = {
|
||||
enum: [...engineList, ""],
|
||||
},
|
||||
},
|
||||
};
|
||||
} as const;
|
||||
|
||||
export const parseSchema: FastifySchema = {
|
||||
description: "Parse the page and get all data from the engine",
|
||||
@ -52,6 +44,10 @@ export const parseSchema: FastifySchema = {
|
||||
produces: ["text/json"],
|
||||
};
|
||||
|
||||
export interface IParseSchema {
|
||||
Querystring: FromSchema<typeof parseQuerySchema>;
|
||||
}
|
||||
|
||||
export const rawHtmlSchema: FastifySchema = {
|
||||
description: "Parse the page and get raw HTML from the engine",
|
||||
querystring: parseQuerySchema,
|
||||
|
@ -1,18 +1,9 @@
|
||||
import { FastifyRequest, FastifySchema } from "fastify";
|
||||
import { FastifySchema } from "fastify";
|
||||
import { engineList } from "../../handlers/main";
|
||||
|
||||
export type GetRequest = FastifyRequest<{
|
||||
Querystring: IGetQuery;
|
||||
}>;
|
||||
|
||||
export interface IGetQuery {
|
||||
url: string;
|
||||
format?: string;
|
||||
engine?: string;
|
||||
}
|
||||
import { FromSchema } from "json-schema-to-ts";
|
||||
|
||||
export interface IGetSchema {
|
||||
Querystring: IGetQuery;
|
||||
Querystring: IGetQuerySchema;
|
||||
}
|
||||
|
||||
export const indexSchema = {
|
||||
@ -38,7 +29,8 @@ export const getQuerySchema = {
|
||||
enum: [...engineList, ""],
|
||||
},
|
||||
},
|
||||
};
|
||||
} as const;
|
||||
export type IGetQuerySchema = FromSchema<typeof getQuerySchema>;
|
||||
|
||||
export const GetSchema: FastifySchema = {
|
||||
description: "Get page",
|
||||
|
Loading…
x
Reference in New Issue
Block a user