Refactor and regroup urlHelpers utils (#6462)
* fix: refactor urlHelpers * fix: move to /plugins/slack/shared * fix: remove .babelrc * fix: remove Outline class * fix: Slack -> SlackUtils * fix: UrlHelper class
This commit is contained in:
@@ -4,7 +4,7 @@ import isEmpty from "lodash/isEmpty";
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import { z } from "zod";
|
||||
import { DocumentPermission, StatusFilter } from "@shared/types";
|
||||
import { SHARE_URL_SLUG_REGEX } from "@shared/utils/urlHelpers";
|
||||
import { UrlHelper } from "@shared/utils/UrlHelper";
|
||||
import { BaseSchema } from "@server/routes/api/schema";
|
||||
|
||||
const DocumentsSortParamsSchema = z.object({
|
||||
@@ -115,7 +115,7 @@ export const DocumentsInfoSchema = BaseSchema.extend({
|
||||
/** Share Id, if available */
|
||||
shareId: z
|
||||
.string()
|
||||
.refine((val) => isUUID(val) || SHARE_URL_SLUG_REGEX.test(val))
|
||||
.refine((val) => isUUID(val) || UrlHelper.SHARE_URL_SLUG_REGEX.test(val))
|
||||
.optional(),
|
||||
|
||||
/** Version of the API to be used */
|
||||
@@ -173,7 +173,7 @@ export const DocumentsSearchSchema = BaseSchema.extend({
|
||||
/** Filter results for the team derived from shareId */
|
||||
shareId: z
|
||||
.string()
|
||||
.refine((val) => isUUID(val) || SHARE_URL_SLUG_REGEX.test(val))
|
||||
.refine((val) => isUUID(val) || UrlHelper.SHARE_URL_SLUG_REGEX.test(val))
|
||||
.optional(),
|
||||
|
||||
/** Min words to be shown in the results snippets */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import { z } from "zod";
|
||||
import { SLUG_URL_REGEX } from "@shared/utils/urlHelpers";
|
||||
import { UrlHelper } from "@shared/utils/UrlHelper";
|
||||
import { BaseSchema } from "../schema";
|
||||
|
||||
export const PinsCreateSchema = BaseSchema.extend({
|
||||
@@ -9,7 +9,7 @@ export const PinsCreateSchema = BaseSchema.extend({
|
||||
.string({
|
||||
required_error: "required",
|
||||
})
|
||||
.refine((val) => isUUID(val) || SLUG_URL_REGEX.test(val), {
|
||||
.refine((val) => isUUID(val) || UrlHelper.SLUG_URL_REGEX.test(val), {
|
||||
message: "must be uuid or url slug",
|
||||
}),
|
||||
collectionId: z.string().uuid().nullish(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import { z } from "zod";
|
||||
import { SHARE_URL_SLUG_REGEX, SLUG_URL_REGEX } from "@shared/utils/urlHelpers";
|
||||
import { UrlHelper } from "@shared/utils/UrlHelper";
|
||||
import { Share } from "@server/models";
|
||||
import { BaseSchema } from "../schema";
|
||||
|
||||
@@ -13,7 +13,8 @@ export const SharesInfoSchema = BaseSchema.extend({
|
||||
.string()
|
||||
.optional()
|
||||
.refine(
|
||||
(val) => (val ? isUUID(val) || SLUG_URL_REGEX.test(val) : true),
|
||||
(val) =>
|
||||
val ? isUUID(val) || UrlHelper.SLUG_URL_REGEX.test(val) : true,
|
||||
{
|
||||
message: "must be uuid or url slug",
|
||||
}
|
||||
@@ -52,7 +53,7 @@ export const SharesUpdateSchema = BaseSchema.extend({
|
||||
published: z.boolean().optional(),
|
||||
urlId: z
|
||||
.string()
|
||||
.regex(SHARE_URL_SLUG_REGEX, {
|
||||
.regex(UrlHelper.SHARE_URL_SLUG_REGEX, {
|
||||
message: "must contain only alphanumeric and dashes",
|
||||
})
|
||||
.nullish(),
|
||||
@@ -65,13 +66,13 @@ export const SharesCreateSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
documentId: z
|
||||
.string()
|
||||
.refine((val) => isUUID(val) || SLUG_URL_REGEX.test(val), {
|
||||
.refine((val) => isUUID(val) || UrlHelper.SLUG_URL_REGEX.test(val), {
|
||||
message: "must be uuid or url slug",
|
||||
}),
|
||||
published: z.boolean().default(false),
|
||||
urlId: z
|
||||
.string()
|
||||
.regex(SHARE_URL_SLUG_REGEX, {
|
||||
.regex(UrlHelper.SHARE_URL_SLUG_REGEX, {
|
||||
message: "must contain only alphanumeric and dashes",
|
||||
})
|
||||
.optional(),
|
||||
|
||||
Reference in New Issue
Block a user