mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
19 lines
553 B
TypeScript
19 lines
553 B
TypeScript
import { addAttributeOptions } from "sequelize-typescript";
|
|
import { containsUrl } from "@shared/utils/urls";
|
|
|
|
/**
|
|
* A decorator that validates that a string does not include something that
|
|
* looks like a URL.
|
|
*/
|
|
export default function NotContainsUrl(target: object, propertyName: string) {
|
|
return addAttributeOptions(target, propertyName, {
|
|
validate: {
|
|
notContainsUrl(value: unknown) {
|
|
if (typeof value === "string" && containsUrl(value)) {
|
|
throw new Error("Must not contain a URL");
|
|
}
|
|
},
|
|
},
|
|
});
|
|
}
|