mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
Update prettier styling
This commit is contained in:
@ -62,7 +62,9 @@ export function isPasswordValid(password: string, breakdown?: boolean, strict?:
|
||||
return errors;
|
||||
}
|
||||
|
||||
type CtxOrReq = { req: NextApiRequest; ctx?: never } | { ctx: { req: NextApiRequest }; req?: never };
|
||||
type CtxOrReq =
|
||||
| { req: NextApiRequest; ctx?: never }
|
||||
| { ctx: { req: NextApiRequest }; req?: never };
|
||||
|
||||
export const ensureSession = async (ctxOrReq: CtxOrReq) => {
|
||||
const session = await getSession(ctxOrReq);
|
||||
|
||||
@ -12,7 +12,11 @@ export const getSafeRedirectUrl = (url = "") => {
|
||||
const urlParsed = new URL(url);
|
||||
|
||||
// Avoid open redirection security vulnerability
|
||||
if (!["CONSOLE_URL", "WEBAPP_URL", "WEBSITE_URL"].some((u) => new URL(u).origin === urlParsed.origin)) {
|
||||
if (
|
||||
!["CONSOLE_URL", "WEBAPP_URL", "WEBSITE_URL"].some(
|
||||
(u) => new URL(u).origin === urlParsed.origin
|
||||
)
|
||||
) {
|
||||
url = `${"WEBAPP_URL"}/`;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,11 @@ import { getUserFromToken } from "@documenso/lib/server";
|
||||
import prisma from "@documenso/prisma";
|
||||
import { Document as PrismaDocument } from "@prisma/client";
|
||||
|
||||
export const getDocument = async (documentId: number, req: any, res: any): Promise<PrismaDocument> => {
|
||||
export const getDocument = async (
|
||||
documentId: number,
|
||||
req: any,
|
||||
res: any
|
||||
): Promise<PrismaDocument> => {
|
||||
const user = await getUserFromToken(req, res);
|
||||
if (!user) return Promise.reject("Invalid user or token.");
|
||||
if (!documentId) Promise.reject("No documentId");
|
||||
|
||||
@ -1,24 +1,27 @@
|
||||
import type { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
type Handlers = {
|
||||
[method in "GET" | "POST" | "PATCH" | "PUT" | "DELETE"]?: Promise<{ default: NextApiHandler }>;
|
||||
[method in "GET" | "POST" | "PATCH" | "PUT" | "DELETE"]?: Promise<{
|
||||
default: NextApiHandler;
|
||||
}>;
|
||||
};
|
||||
|
||||
/** Allows us to split big API handlers by method */
|
||||
export const defaultHandler = (handlers: Handlers) => async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const handler = (await handlers[req.method as keyof typeof handlers])?.default;
|
||||
// auto catch unsupported methods.
|
||||
if (!handler) {
|
||||
return res
|
||||
.status(405)
|
||||
.json({ message: `Method Not Allowed (Allow: ${Object.keys(handlers).join(",")})` });
|
||||
}
|
||||
export const defaultHandler =
|
||||
(handlers: Handlers) => async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const handler = (await handlers[req.method as keyof typeof handlers])?.default;
|
||||
// auto catch unsupported methods.
|
||||
if (!handler) {
|
||||
return res.status(405).json({
|
||||
message: `Method Not Allowed (Allow: ${Object.keys(handlers).join(",")})`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await handler(req, res);
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({ message: "Something went wrong" });
|
||||
}
|
||||
};
|
||||
try {
|
||||
await handler(req, res);
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({ message: "Something went wrong" });
|
||||
}
|
||||
};
|
||||
|
||||
@ -5,7 +5,13 @@ export class HttpError<TCode extends number = number> extends Error {
|
||||
public readonly url: string | undefined;
|
||||
public readonly method: string | undefined;
|
||||
|
||||
constructor(opts: { url?: string; method?: string; message?: string; statusCode: TCode; cause?: Error }) {
|
||||
constructor(opts: {
|
||||
url?: string;
|
||||
method?: string;
|
||||
message?: string;
|
||||
statusCode: TCode;
|
||||
cause?: Error;
|
||||
}) {
|
||||
super(opts.message ?? `HTTP Error ${opts.statusCode} `);
|
||||
|
||||
Object.setPrototypeOf(this, HttpError.prototype);
|
||||
|
||||
Reference in New Issue
Block a user