Compare commits

..

No commits in common. "1fba91f77281ebd4d24f28b5d135c3a29654157d" and "9eac364e0173e68986e2299945f8506244d6fb45" have entirely different histories.

7 changed files with 190 additions and 133 deletions

View file

@ -113,14 +113,8 @@ export default apiRoute((app) => {
"json",
z
.object({
shortcode: CustomEmojiSchema.shape.shortcode
.max(config.validation.emojis.max_shortcode_characters)
.refine(
(s) =>
!config.validation.filters.emoji_shortcode.some(
(filter) => filter.test(s),
),
"Shortcode contains blocked words",
shortcode: CustomEmojiSchema.shape.shortcode.max(
config.validation.emojis.max_shortcode_characters,
),
element: z
.string()

View file

@ -45,14 +45,8 @@ export default apiRoute((app) =>
validator(
"json",
z.object({
shortcode: CustomEmojiSchema.shape.shortcode
.max(config.validation.emojis.max_shortcode_characters)
.refine(
(s) =>
!config.validation.filters.emoji_shortcode.some(
(filter) => filter.test(s),
),
"Shortcode contains blocked words",
shortcode: CustomEmojiSchema.shape.shortcode.max(
config.validation.emojis.max_shortcode_characters,
),
element: z
.string()

View file

@ -1,12 +1,6 @@
import { zodToJsonSchema } from "zod-to-json-schema";
await import("~/config.ts");
// This is an awkward way to avoid import cycles for some reason
await (async () => {
const { ConfigSchema } = await import("./schema.ts");
import { ConfigSchema } from "./schema.ts";
const jsonSchema = zodToJsonSchema(ConfigSchema, {});
console.write(`${JSON.stringify(jsonSchema, null, 4)}\n`);
})();

View file

@ -500,14 +500,9 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
);
const emojis = await Promise.all(
extensions?.["pub.versia:custom_emojis"]?.emojis
.filter(
(e) =>
!config.validation.filters.emoji_shortcode.some(
(filter) => filter.test(e.name),
),
)
.map((emoji) => Emoji.fetchFromRemote(emoji, instance)) ?? [],
extensions?.["pub.versia:custom_emojis"]?.emojis.map((emoji) =>
Emoji.fetchFromRemote(emoji, instance),
) ?? [],
);
const mentions = (

View file

@ -181,7 +181,9 @@ export class InboxProcessor {
try {
await new EntitySorter(this.body)
.on(VersiaEntities.Note, (n) => InboxProcessor.processNote(n))
.on(VersiaEntities.Note, async (n) => {
await Note.fromVersia(n);
})
.on(VersiaEntities.Follow, (f) =>
InboxProcessor.processFollowRequest(f),
)
@ -197,7 +199,9 @@ export class InboxProcessor {
.on(VersiaEntities.Delete, (d) =>
InboxProcessor.processDelete(d),
)
.on(VersiaEntities.User, (u) => InboxProcessor.processUser(u))
.on(VersiaEntities.User, async (u) => {
await User.fromVersia(u);
})
.on(VersiaEntities.Share, async (s) =>
InboxProcessor.processShare(s),
)
@ -209,66 +213,6 @@ export class InboxProcessor {
}
}
/**
* Handles Note entity processing
*
* @param {VersiaNote} note - The Note entity to process.
* @returns {Promise<void>}
*/
private static async processNote(note: VersiaEntities.Note): Promise<void> {
// If note has a blocked word
if (
Object.values(note.content?.data ?? {})
.flatMap((c) => c.content)
.some((content) =>
config.validation.filters.note_content.some((filter) =>
filter.test(content),
),
)
) {
// Drop silently
return;
}
await Note.fromVersia(note);
}
/**
* Handles User entity processing.
*
* @param {VersiaUser} user - The User entity to process.
* @returns {Promise<void>}
*/
private static async processUser(user: VersiaEntities.User): Promise<void> {
if (
config.validation.filters.username.some((filter) =>
filter.test(user.data.username),
) ||
(user.data.display_name &&
config.validation.filters.displayname.some((filter) =>
filter.test(user.data.display_name ?? ""),
))
) {
// Drop silently
return;
}
if (
Object.values(user.bio?.data ?? {})
.flatMap((c) => c.content)
.some((content) =>
config.validation.filters.bio.some((filter) =>
filter.test(content),
),
)
) {
// Drop silently
return;
}
await User.fromVersia(user);
}
/**
* Handles Follow entity processing.
*

View file

@ -57,14 +57,27 @@
"default": "versia"
}
},
"required": ["host", "username"],
"required": [
"host",
"port",
"username",
"password",
"database"
],
"additionalProperties": false
},
"description": "Additional read-only replicas",
"default": []
}
},
"required": ["username"],
"required": [
"host",
"port",
"username",
"password",
"database",
"replicas"
],
"additionalProperties": false,
"description": "PostgreSQL database configuration"
},
@ -93,6 +106,7 @@
"default": 0
}
},
"required": ["host", "port", "password", "database"],
"additionalProperties": false,
"description": "A Redis database used for managing queues."
},
@ -118,11 +132,12 @@
"default": 1
}
},
"required": ["host", "port", "password", "database"],
"additionalProperties": false,
"description": "A Redis database used for caching SQL queries. Optional."
}
},
"required": ["queue"],
"required": ["queue", "cache"],
"additionalProperties": false,
"description": "Redis configuration. Used for queues and caching."
},
@ -150,11 +165,12 @@
"$ref": "#/properties/postgres/properties/password"
}
},
"required": ["password"],
"required": ["host", "port", "password"],
"additionalProperties": false,
"description": "Sonic database configuration"
}
},
"required": ["enabled", "sonic"],
"additionalProperties": false,
"description": "Search and indexing configuration"
},
@ -175,6 +191,7 @@
"description": "Message to show to users when registration is disabled"
}
},
"required": ["allow", "require_approval", "message"],
"additionalProperties": false
},
"http": {
@ -233,12 +250,20 @@
"description": "This value must be a file path"
}
},
"required": ["key", "cert"],
"required": ["key", "cert", "passphrase", "ca"],
"additionalProperties": false,
"description": "TLS configuration. You should probably be using a reverse proxy instead of this"
}
},
"required": ["base_url"],
"required": [
"base_url",
"bind",
"bind_port",
"banned_ips",
"banned_user_agents",
"proxy_address",
"tls"
],
"additionalProperties": false
},
"frontend": {
@ -250,7 +275,7 @@
},
"path": {
"type": "string",
"default": "frontend"
"default": "/home/jessew/Dev/versia-server"
},
"routes": {
"type": "object",
@ -277,6 +302,13 @@
"default": "/oauth/reset"
}
},
"required": [
"home",
"login",
"consent",
"register",
"password_reset"
],
"additionalProperties": false
},
"settings": {
@ -285,7 +317,7 @@
"default": {}
}
},
"required": ["routes"],
"required": ["enabled", "path", "routes", "settings"],
"additionalProperties": false
},
"email": {
@ -319,10 +351,17 @@
"default": true
}
},
"required": ["server", "username"],
"required": [
"server",
"port",
"username",
"password",
"tls"
],
"additionalProperties": false
}
},
"required": ["send_emails", "smtp"],
"additionalProperties": false
},
"media": {
@ -354,10 +393,15 @@
"default": false
}
},
"required": [
"convert_images",
"convert_to",
"convert_vectors"
],
"additionalProperties": false
}
},
"required": ["conversion"],
"required": ["backend", "uploads_path", "conversion"],
"additionalProperties": false
},
"s3": {
@ -381,19 +425,14 @@
"public_url": {
"$ref": "#/properties/http/properties/base_url",
"description": "Public URL that uploaded media will be accessible at"
},
"path": {
"type": "string"
},
"path_style": {
"type": "boolean",
"default": true
}
},
"required": [
"endpoint",
"access_key",
"secret_access_key",
"region",
"bucket_name",
"public_url"
],
"additionalProperties": false
@ -479,6 +518,18 @@
"default": 20
}
},
"required": [
"max_displayname_characters",
"max_username_characters",
"max_bio_characters",
"max_avatar_bytes",
"max_header_bytes",
"disallowed_usernames",
"max_field_count",
"max_field_name_characters",
"max_field_value_characters",
"max_pinned_notes"
],
"additionalProperties": false
},
"notes": {
@ -519,6 +570,11 @@
"default": 16
}
},
"required": [
"max_characters",
"allowed_url_schemes",
"max_attachments"
],
"additionalProperties": false
},
"media": {
@ -1782,6 +1838,11 @@
]
}
},
"required": [
"max_bytes",
"max_description_characters",
"allowed_mime_types"
],
"additionalProperties": false
},
"emojis": {
@ -1803,6 +1864,11 @@
"default": 1000
}
},
"required": [
"max_bytes",
"max_shortcode_characters",
"max_description_characters"
],
"additionalProperties": false
},
"polls": {
@ -1829,6 +1895,12 @@
"default": 8640000
}
},
"required": [
"max_options",
"max_option_characters",
"min_duration_seconds",
"max_duration_seconds"
],
"additionalProperties": false
},
"emails": {
@ -1847,6 +1919,7 @@
"default": []
}
},
"required": ["disallow_tempmail", "disallowed_domains"],
"additionalProperties": false
},
"challenges": {
@ -1867,7 +1940,7 @@
"description": "You can use PATH:/path/to/file to load this value from a file"
}
},
"required": ["key"],
"required": ["difficulty", "expiration", "key"],
"additionalProperties": false,
"description": "CAPTCHA challenge configuration. Challenges are disabled if not provided."
},
@ -1910,6 +1983,13 @@
"default": []
}
},
"required": [
"note_content",
"emoji_shortcode",
"username",
"displayname",
"bio"
],
"additionalProperties": false,
"description": "Block content that matches these regular expressions"
}
@ -1921,6 +2001,7 @@
"emojis",
"polls",
"emails",
"challenges",
"filters"
],
"additionalProperties": false
@ -1935,14 +2016,13 @@
"type": "object",
"properties": {
"public": {
"$ref": "#/properties/postgres/properties/password",
"description": "You can use PATH:/path/to/file to load this value from a file"
"$ref": "#/properties/postgres/properties/password"
},
"private": {
"$ref": "#/properties/postgres/properties/password",
"description": "You can use PATH:/path/to/file to load this value from a file"
"$ref": "#/properties/postgres/properties/password"
}
},
"required": ["public", "private"],
"additionalProperties": false
},
"subject": {
@ -1950,11 +2030,12 @@
"description": "Subject field embedded in the push notification. Example: 'mailto:contact@example.com'"
}
},
"required": ["vapid_keys"],
"required": ["vapid_keys", "subject"],
"additionalProperties": false,
"description": "Web Push Notifications configuration. Leave out to disable."
}
},
"required": ["push"],
"additionalProperties": false
},
"defaults": {
@ -1981,6 +2062,13 @@
"description": "A style name from https://www.dicebear.com/styles"
}
},
"required": [
"visibility",
"language",
"avatar",
"header",
"placeholder_style"
],
"additionalProperties": false
},
"federation": {
@ -2067,6 +2155,17 @@
"default": []
}
},
"required": [
"reports",
"deletes",
"updates",
"media",
"follows",
"likes",
"reactions",
"banners",
"avatars"
],
"additionalProperties": false
},
"bridge": {
@ -2097,11 +2196,11 @@
"$ref": "#/properties/http/properties/proxy_address"
}
},
"required": ["software", "token", "url"],
"required": ["software", "allowed_ips", "token", "url"],
"additionalProperties": false
}
},
"required": ["discard"],
"required": ["blocked", "followers_only", "discard", "bridge"],
"additionalProperties": false
},
"queues": {
@ -2120,6 +2219,10 @@
"default": 31536000
}
},
"required": [
"remove_after_complete_seconds",
"remove_after_failure_seconds"
],
"additionalProperties": false
},
"propertyNames": {
@ -2161,6 +2264,7 @@
"$ref": "#/properties/http/properties/proxy_address"
}
},
"required": ["logo", "banner"],
"additionalProperties": false
},
"languages": {
@ -2385,7 +2489,7 @@
"description": "Longer version of the rule with additional information"
}
},
"required": ["text"],
"required": ["text", "hint"],
"additionalProperties": false
},
"default": []
@ -2394,18 +2498,28 @@
"type": "object",
"properties": {
"public": {
"$ref": "#/properties/postgres/properties/password",
"description": "You can use PATH:/path/to/file to load this value from a file"
"$ref": "#/properties/postgres/properties/password"
},
"private": {
"$ref": "#/properties/postgres/properties/password",
"description": "You can use PATH:/path/to/file to load this value from a file"
"$ref": "#/properties/postgres/properties/password"
}
},
"required": ["public", "private"],
"additionalProperties": false
}
},
"required": ["branding", "languages", "contact"],
"required": [
"name",
"description",
"extended_description_path",
"tos_path",
"privacy_policy_path",
"branding",
"languages",
"contact",
"rules",
"keys"
],
"additionalProperties": false
},
"permissions": {
@ -2684,6 +2798,7 @@
]
}
},
"required": ["anonymous", "default", "admin"],
"additionalProperties": false
},
"logging": {
@ -2715,6 +2830,7 @@
"type": "string"
}
},
"required": ["level", "log_file_path"],
"additionalProperties": false
}
]
@ -2770,7 +2886,15 @@
"type": "string"
}
},
"required": ["dsn"],
"required": [
"dsn",
"debug",
"sample_rate",
"traces_sample_rate",
"trace_propagation_targets",
"max_breadcrumbs",
"environment"
],
"additionalProperties": false
},
"log_file_path": {
@ -2778,7 +2902,7 @@
"default": "logs/versia.log"
}
},
"required": ["types"],
"required": ["types", "log_level", "sentry", "log_file_path"],
"additionalProperties": false
},
"debug": {
@ -2789,6 +2913,7 @@
"default": false
}
},
"required": ["federation"],
"additionalProperties": false
},
"plugins": {
@ -2816,6 +2941,7 @@
"default": []
}
},
"required": ["enabled", "disabled"],
"additionalProperties": false
},
"config": {
@ -2823,7 +2949,7 @@
"additionalProperties": {}
}
},
"required": ["overrides"],
"required": ["autoload", "overrides", "config"],
"additionalProperties": false
}
},
@ -2836,6 +2962,7 @@
"frontend",
"email",
"media",
"s3",
"validation",
"notifications",
"defaults",
@ -2844,6 +2971,7 @@
"instance",
"permissions",
"logging",
"debug",
"plugins"
],
"additionalProperties": false,

View file

@ -37,7 +37,7 @@
"format": "uri"
}
},
"required": ["name"],
"required": ["name", "email", "url"],
"additionalProperties": false
}
},
@ -75,10 +75,18 @@
"format": "uri"
}
},
"required": ["type", "url"],
"additionalProperties": false
}
},
"required": ["name", "version", "description"],
"required": [
"$schema",
"name",
"version",
"description",
"authors",
"repository"
],
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#"
}