doc: all available pages schema
This commit is contained in:
parent
20755f2b89
commit
b0bbcd0bba
@ -4,3 +4,21 @@ export interface IHandlerOutput {
|
||||
title: string;
|
||||
lang: string;
|
||||
}
|
||||
|
||||
export const handlerSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
content: {
|
||||
type: "string",
|
||||
},
|
||||
textContent: {
|
||||
type: "string",
|
||||
},
|
||||
title: {
|
||||
type: "string",
|
||||
},
|
||||
lang: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
import { engineList } from "../handlers/main";
|
||||
import { indexSchema } from "../types/requests";
|
||||
|
||||
export default async function indexRoute(fastify: FastifyInstance) {
|
||||
fastify.get("/", async (_, reply) => {
|
||||
fastify.get("/", { schema: indexSchema }, async (_, reply) => {
|
||||
return reply.view("/templates/index.ejs", { engineList });
|
||||
});
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
import { EngineRequest } from "../types/requests";
|
||||
import { EngineRequest, IParseSchema, parseSchema } from "../types/requests";
|
||||
import { FastifyInstance } from "fastify";
|
||||
import handlePage from "../handlers/main";
|
||||
import { generateRequestUrl } from "../utils";
|
||||
|
||||
export default async function parseRoute(fastify: FastifyInstance) {
|
||||
fastify.get("/parse", async (request: EngineRequest) => {
|
||||
const parsed = await handlePage(
|
||||
fastify.get<IParseSchema>(
|
||||
"/parse",
|
||||
{ schema: parseSchema },
|
||||
async (request: EngineRequest) => {
|
||||
return await handlePage(
|
||||
request.query.url,
|
||||
generateRequestUrl(
|
||||
request.protocol,
|
||||
@ -14,7 +17,6 @@ export default async function parseRoute(fastify: FastifyInstance) {
|
||||
),
|
||||
request.query.engine
|
||||
);
|
||||
|
||||
return parsed;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
|
||||
import { GetRequest } from "../types/requests";
|
||||
import { GetRequest, IParseSchema, rawHtmlSchema } from "../types/requests";
|
||||
import handlePage from "../handlers/main";
|
||||
import { generateRequestUrl } from "../utils";
|
||||
|
||||
export default async function rawHtml(fastify: FastifyInstance) {
|
||||
fastify.get("/raw-html", async (request: GetRequest) => {
|
||||
fastify.get<IParseSchema>(
|
||||
"/raw-html",
|
||||
{ schema: rawHtmlSchema },
|
||||
async (request: GetRequest) => {
|
||||
return (
|
||||
await handlePage(
|
||||
request.query.url,
|
||||
@ -16,5 +19,6 @@ export default async function rawHtml(fastify: FastifyInstance) {
|
||||
)
|
||||
)
|
||||
).content;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { FastifyRequest, FastifySchema } from "fastify";
|
||||
import { handlerSchema } from "../handlers/handler.interface";
|
||||
import { engineList } from "../handlers/main";
|
||||
|
||||
export type GetRequest = FastifyRequest<{
|
||||
Querystring: {
|
||||
@ -14,10 +16,23 @@ export interface IGetQuery {
|
||||
engine?: string;
|
||||
}
|
||||
|
||||
export interface IParseQuery {
|
||||
url: string;
|
||||
engine?: string;
|
||||
}
|
||||
|
||||
export interface IGetSchema {
|
||||
Querystring: IGetQuery;
|
||||
}
|
||||
|
||||
export interface IParseSchema {
|
||||
Querystring: IParseQuery;
|
||||
}
|
||||
|
||||
export const indexSchema = {
|
||||
produces: ["text/html"],
|
||||
};
|
||||
|
||||
export const getQuerySchema = {
|
||||
type: "object",
|
||||
required: ["url"],
|
||||
@ -33,8 +48,22 @@ export const getQuerySchema = {
|
||||
},
|
||||
engine: {
|
||||
type: "string",
|
||||
enum: ["readability", "google", ""],
|
||||
default: "readability",
|
||||
enum: [...engineList, ""],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const parseQuerySchema = {
|
||||
type: "object",
|
||||
required: ["url"],
|
||||
properties: {
|
||||
url: {
|
||||
type: "string",
|
||||
description: "URL",
|
||||
},
|
||||
engine: {
|
||||
type: "string",
|
||||
enum: [...engineList, ""],
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -42,6 +71,21 @@ export const getQuerySchema = {
|
||||
export const GetSchema: FastifySchema = {
|
||||
description: "Get page",
|
||||
querystring: getQuerySchema,
|
||||
produces: ["text/html", "text/plain"],
|
||||
};
|
||||
|
||||
export const parseSchema: FastifySchema = {
|
||||
description: "Parse page",
|
||||
querystring: parseQuerySchema,
|
||||
response: {
|
||||
"2xx": handlerSchema,
|
||||
},
|
||||
produces: ["text/json"],
|
||||
};
|
||||
|
||||
export const rawHtmlSchema: FastifySchema = {
|
||||
description: "Get raw HTML",
|
||||
querystring: parseQuerySchema,
|
||||
produces: ["text/html"],
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user