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