Files
outline/server/routes/api/urls/schema.ts
Apoorv Mishra 90ed6a5366 Fixes hover preview going out of window bounds (#6776)
* fix: hover preview out of bounds

* fix: pop

* fix: check for both element and data

* fix: show loading indicator

* fix: width
2024-04-13 06:01:40 -07:00

56 lines
1.4 KiB
TypeScript

import isNil from "lodash/isNil";
import isUUID from "validator/lib/isUUID";
import { z } from "zod";
import { UrlHelper } from "@shared/utils/UrlHelper";
import { isUrl } from "@shared/utils/urls";
import { ValidateURL } from "@server/validation";
import { BaseSchema } from "../schema";
export const UrlsUnfurlSchema = BaseSchema.extend({
body: z
.object({
url: z
.string()
.url()
.refine(
(val) => {
try {
const url = new URL(val);
if (url.protocol === "mention:") {
return ValidateURL.isValidMentionUrl(val);
}
return isUrl(val);
} catch (err) {
return false;
}
},
{ message: ValidateURL.message }
),
documentId: z
.string()
.optional()
.refine(
(val) =>
val ? isUUID(val) || UrlHelper.SLUG_URL_REGEX.test(val) : true,
{
message: "must be uuid or url slug",
}
),
})
.refine(
(val) =>
!(ValidateURL.isValidMentionUrl(val.url) && isNil(val.documentId)),
{ message: "documentId required" }
),
});
export type UrlsUnfurlReq = z.infer<typeof UrlsUnfurlSchema>;
export const UrlsCheckCnameSchema = BaseSchema.extend({
body: z.object({
hostname: z.string(),
}),
});
export type UrlsCheckCnameReq = z.infer<typeof UrlsCheckCnameSchema>;