mirror of
https://github.com/txtdot/txtdot
synced 2024-10-18 14:40:19 +03:00
commit
9fd3fdfa7e
38
package-lock.json
generated
38
package-lock.json
generated
@ -19,7 +19,8 @@
|
||||
"ejs": "^3.1.9",
|
||||
"fastify": "^4.21.0",
|
||||
"ip-range-check": "^0.2.0",
|
||||
"jsdom": "^22.1.0"
|
||||
"jsdom": "^22.1.0",
|
||||
"json-schema-to-ts": "^2.9.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ejs": "^3.1.2",
|
||||
@ -43,6 +44,17 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/runtime": {
|
||||
"version": "7.22.11",
|
||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.22.11.tgz",
|
||||
"integrity": "sha512-ee7jVNlWN09+KftVOu9n7S8gQzD/Z6hN/I8VBRXW4P1+Xe7kJGXMwu8vds4aGIMHZnNbdpSWCfZZtinytpcAvA==",
|
||||
"dependencies": {
|
||||
"regenerator-runtime": "^0.14.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint-community/eslint-utils": {
|
||||
"version": "4.4.0",
|
||||
"dev": true,
|
||||
@ -401,7 +413,6 @@
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.12",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/mime": {
|
||||
@ -2142,6 +2153,19 @@
|
||||
"url": "https://github.com/Eomm/json-schema-resolver?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/json-schema-to-ts": {
|
||||
"version": "2.9.2",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-to-ts/-/json-schema-to-ts-2.9.2.tgz",
|
||||
"integrity": "sha512-h9WqLkTVpBbiaPb5OmeUpz/FBLS/kvIJw4oRCPiEisIu2WjMh+aai0QIY2LoOhRFx5r92taGLcerIrzxKBAP6g==",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@types/json-schema": "^7.0.9",
|
||||
"ts-algebra": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"node_modules/json-schema-traverse": {
|
||||
"version": "0.4.1",
|
||||
"dev": true,
|
||||
@ -2647,6 +2671,11 @@
|
||||
"node": ">= 12.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/regenerator-runtime": {
|
||||
"version": "0.14.0",
|
||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.0.tgz",
|
||||
"integrity": "sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA=="
|
||||
},
|
||||
"node_modules/require-directory": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||
@ -3084,6 +3113,11 @@
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/ts-algebra": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-algebra/-/ts-algebra-1.2.0.tgz",
|
||||
"integrity": "sha512-kMuJJd8B2N/swCvIvn1hIFcIOrLGbWl9m/J6O3kHx9VRaevh00nvgjPiEGaRee7DRaAczMYR2uwWvXU22VFltw=="
|
||||
},
|
||||
"node_modules/ts-api-utils": {
|
||||
"version": "1.0.1",
|
||||
"dev": true,
|
||||
|
@ -15,7 +15,8 @@
|
||||
"ejs": "^3.1.9",
|
||||
"fastify": "^4.21.0",
|
||||
"ip-range-check": "^0.2.0",
|
||||
"jsdom": "^22.1.0"
|
||||
"jsdom": "^22.1.0",
|
||||
"json-schema-to-ts": "^2.9.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ejs": "^3.1.2",
|
||||
|
@ -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…
Reference in New Issue
Block a user