diff --git a/models/event.ts b/models/event.ts index f60d2b4..be904aa 100644 --- a/models/event.ts +++ b/models/event.ts @@ -93,7 +93,17 @@ export function VALIDATE_EVENT(event: EVENT) { } break; case 'essay': - if (event.data?.essay?.length <= 0) { + if (event.data?.title?.length <= 0) { + errors.push({ + cause: 'essay_title_missing', + message: 'An essay must have a title.' + }); + } else if (event.data?.title?.length > 2 ** 7) { + errors.push({ + cause: 'essay_title_length_limit_exceeded', + message: 'An essay title cannot be longer than 128 characters.' + }); + } else if (event.data?.essay?.length <= 0) { errors.push({ cause: 'essay_missing', message: 'An essay cannot be empty.' diff --git a/public/api/users/index.ts b/public/api/users/index.ts index 0af20b5..6ac6b9c 100644 --- a/public/api/users/index.ts +++ b/public/api/users/index.ts @@ -19,6 +19,9 @@ const DEFAULT_USER_PERMISSIONS: string[] = [ 'topics.blurbs.write', 'topics.chat.write', 'topics.chat.read', + 'topics.essays.create', + 'topics.essays.read', + 'topics.essays.write', 'topics.posts.create', 'topics.posts.write', 'topics.posts.read', diff --git a/public/base.css b/public/base.css index e65ea4c..7e49cce 100644 --- a/public/base.css +++ b/public/base.css @@ -313,6 +313,9 @@ body[data-perms*="topics.blurbs.write"] [data-requires-permission="topics.blurbs body[data-perms*="topics.chat.create"] [data-requires-permission="topics.chat.create"], body[data-perms*="topics.chat.read"] [data-requires-permission="topics.chat.read"], body[data-perms*="topics.chat.write"] [data-requires-permission="topics.chat.write"], +body[data-perms*="topics.essays.create"] [data-requires-permission="topics.essays.create"], +body[data-perms*="topics.essays.read"] [data-requires-permission="topics.essays.read"], +body[data-perms*="topics.essays.write"] [data-requires-permission="topics.essays.write"], body[data-perms*="topics.posts.create"] [data-requires-permission="topics.posts.create"], body[data-perms*="topics.posts.read"] [data-requires-permission="topics.posts.read"], body[data-perms*="topics.posts.write"] [data-requires-permission="topics.posts.write"], diff --git a/public/index.html b/public/index.html index 57ea98a..a55c9f2 100644 --- a/public/index.html +++ b/public/index.html @@ -24,6 +24,8 @@ + + diff --git a/public/tabs/chat/emojis/en.js b/public/js/emojis/en.js similarity index 100% rename from public/tabs/chat/emojis/en.js rename to public/js/emojis/en.js diff --git a/public/js/external/md_to_html.js b/public/js/external/md_to_html.js new file mode 100644 index 0000000..c3b7911 --- /dev/null +++ b/public/js/external/md_to_html.js @@ -0,0 +1,86 @@ +// see: https://andyburke.dev/andyburke/serverus/src/branch/dev/handlers/markdown.ts + +/* MARKDOWN TO HTML */ + +/* order of these transforms matters, so we list them here in an array and build type from it after. */ +const MD_TRANSFORM_NAMES = [ + "characters", + "headings", + "horizontal_rules", + "list_items", + "bold", + "italic", + "strikethrough", + "code", + "images", + "links", + "breaks", +]; +const MD_TRANSFORMS = { + characters: [ + [/&/g, "&"], + [//g, ">"], + [/"/g, """], + [/'/g, "'"], + ], + + headings: [ + [/^#\s(.+)$/gm, "
$1"],
+ [/```([^`]+)```/gm, "$1"],
+ ],
+
+ images: [[/!\[([^\]]+)\]\(([^\)]+)\)/g, '