mirror of
https://github.com/txtdot/txtdot
synced 2024-10-18 14:40:19 +03:00
doc: schema for get
This commit is contained in:
parent
9da9ea3ade
commit
20755f2b89
@ -1,11 +1,14 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
|
||||
import { GetRequest } from "../types/requests";
|
||||
import { GetSchema, IGetSchema } from "../types/requests";
|
||||
import handlePage from "../handlers/main";
|
||||
import { generateRequestUrl } from "../utils";
|
||||
|
||||
export default async function getRoute(fastify: FastifyInstance) {
|
||||
fastify.get("/get", async (request: GetRequest, reply) => {
|
||||
fastify.get<IGetSchema>(
|
||||
"/get",
|
||||
{ schema: GetSchema },
|
||||
async (request, reply) => {
|
||||
const remoteUrl = request.query.url;
|
||||
const engine = request.query.engine;
|
||||
|
||||
@ -34,5 +37,6 @@ export default async function getRoute(fastify: FastifyInstance) {
|
||||
} else {
|
||||
return reply.view("/templates/get.ejs", { parsed: parsed });
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { FastifyRequest } from "fastify";
|
||||
import { FastifyRequest, FastifySchema } from "fastify";
|
||||
|
||||
export type GetRequest = FastifyRequest<{
|
||||
Querystring: {
|
||||
@ -8,6 +8,43 @@ export type GetRequest = FastifyRequest<{
|
||||
};
|
||||
}>;
|
||||
|
||||
export interface IGetQuery {
|
||||
url: string;
|
||||
format?: string;
|
||||
engine?: string;
|
||||
}
|
||||
|
||||
export interface IGetSchema {
|
||||
Querystring: IGetQuery;
|
||||
}
|
||||
|
||||
export const getQuerySchema = {
|
||||
type: "object",
|
||||
required: ["url"],
|
||||
properties: {
|
||||
url: {
|
||||
type: "string",
|
||||
description: "URL",
|
||||
},
|
||||
format: {
|
||||
type: "string",
|
||||
enum: ["text", "html", ""],
|
||||
default: "html",
|
||||
},
|
||||
engine: {
|
||||
type: "string",
|
||||
enum: ["readability", "google", ""],
|
||||
default: "readability",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const GetSchema: FastifySchema = {
|
||||
description: "Get page",
|
||||
querystring: getQuerySchema,
|
||||
produces: ["text/html"],
|
||||
};
|
||||
|
||||
export type EngineRequest = FastifyRequest<{
|
||||
Querystring: {
|
||||
url: string;
|
||||
|
Loading…
Reference in New Issue
Block a user