Nekrocuck

This commit is contained in:
sneedmaster
2025-09-28 12:59:09 +02:00
commit a2d093954d
402 changed files with 13763 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
use actix_web::{post, web::Data, HttpRequest, HttpResponse};
use serde::Deserialize;
use crate::{
ctx::Ctx, db::models::NewsPost, error::NekrochanError, markup::markup, qsform::QsForm,
web::tcx::account_from_auth,
};
#[derive(Deserialize)]
pub struct CreateNewsForm {
title: String,
content: String,
}
#[post("/staff/actions/create-news")]
pub async fn create_news(
ctx: Data<Ctx>,
req: HttpRequest,
QsForm(form): QsForm<CreateNewsForm>,
) -> Result<HttpResponse, NekrochanError> {
let account = account_from_auth(&ctx, &req).await?;
if !(account.perms().owner() || account.perms().news()) {
return Err(NekrochanError::InsufficientPermissionError);
}
let title = form.title.trim().to_owned();
let content = form.content.trim().to_owned();
if title.is_empty() || title.len() > 100 {
return Err(NekrochanError::NewsTitleFormatError);
}
if content.is_empty() || content.len() > 10000 {
return Err(NekrochanError::NewsContentFormatError);
}
let content_nomarkup = content;
let (content, _) = markup(&ctx, &account.perms(), None, None, &content_nomarkup).await?;
NewsPost::create(&ctx, title, content, content_nomarkup, account.username).await?;
let res = HttpResponse::SeeOther()
.append_header(("Location", "/staff/news"))
.finish();
Ok(res)
}