new functions

This commit is contained in:
Mateusz Gruszczyński
2026-07-29 09:49:37 +02:00
parent bbcd1fe987
commit 904f59146b
23 changed files with 469 additions and 53 deletions
+38 -2
View File
@@ -20,11 +20,16 @@ pub struct PadInfo {
protected: bool,
allow_public_task_updates: bool,
public_page_unprotected: bool,
public_page_enabled: bool,
private: bool,
created_at: String,
updated_at: String,
can_delete_files: bool,
global_color: Option<String>,
note_color: Option<String>,
authorship_mode: String,
colors_enabled: bool,
can_save_editor_settings: bool,
}
pub async fn create_pad(
@@ -78,12 +83,19 @@ pub async fn pad_info(
)
.await?;
let (global_color, note_color) = editor_colors(&state, &headers, "pad", &slug).await?;
let (authorship_mode, colors_enabled) = editor_settings(&state, "pad", &slug).await?;
let can_save_editor_settings = crate::auth::resource_permission(&state, "pad", &slug, bearer_token(&headers)).await.ok().flatten().as_deref() == Some("rw");
if pad.is_private == 0 && !db::pad_public_page_disabled(&state.db, pad.id).await? && !db::pad_public_page_enabled(&state.db, pad.id).await? {
db::publish_pad(&state.db, pad.id).await?;
}
Ok(Json(PadInfo {
slug: pad.slug,
title: pad.title,
protected: pad.password_hash.is_some(),
allow_public_task_updates: db::pad_public_task_updates(&state.db, pad.id).await?,
public_page_unprotected: db::pad_public_page_unprotected(&state.db, pad.id).await?,
public_page_enabled: db::pad_public_page_enabled(&state.db, pad.id).await?,
private: pad.is_private != 0,
created_at: db::normalize_timestamp(&pad.created_at),
updated_at: db::normalize_timestamp(&pad.updated_at),
can_delete_files: crate::auth::is_resource_owner(
@@ -96,9 +108,19 @@ pub async fn pad_info(
.unwrap_or(false),
global_color,
note_color,
authorship_mode,
colors_enabled,
can_save_editor_settings,
}))
}
pub async fn set_pad_editor_settings(
State(state): State<SharedState>, headers: HeaderMap, Path(slug): Path<String>,
Json(payload): Json<EditorSettingsRequest>,
) -> Result<Json<serde_json::Value>, ApiError> {
save_editor_settings(&state, &headers, "pad", &slug, "pad", &slug, payload).await
}
pub async fn pad_editor_color(
State(state): State<SharedState>,
headers: HeaderMap,
@@ -181,11 +203,18 @@ pub async fn publish_pad_page(
.await?
};
require_write(level)?;
let enabled = payload.enabled.unwrap_or(true);
if !enabled {
db::unpublish_pad(&state.db, pad.id).await?;
db::set_pad_public_page_disabled(&state.db, pad.id, true).await?;
return Ok(Json(PublishResponse { url: None, enabled: false }));
}
db::set_pad_public_page_disabled(&state.db, pad.id, false).await?;
let token = db::publish_pad(&state.db, pad.id).await?;
db::set_pad_public_task_updates(&state.db, pad.id, payload.allow_task_updates).await?;
db::set_pad_public_page_unprotected(&state.db, pad.id, payload.unprotect_page).await?;
Ok(Json(PublishResponse {
url: format!("/s/{token}"),
url: Some(format!("/s/{token}")), enabled: true,
}))
}
@@ -219,11 +248,18 @@ pub async fn publish_note_page(
.await?
};
require_write(level)?;
let enabled = payload.enabled.unwrap_or(true);
if !enabled {
db::unpublish_note(&state.db, note.id).await?;
db::set_note_public_page_disabled(&state.db, note.id, true).await?;
return Ok(Json(PublishResponse { url: None, enabled: false }));
}
db::set_note_public_page_disabled(&state.db, note.id, false).await?;
let token = db::publish_note(&state.db, note.id).await?;
db::set_note_public_task_updates(&state.db, note.id, payload.allow_task_updates).await?;
db::set_note_public_page_unprotected(&state.db, note.id, payload.unprotect_page).await?;
Ok(Json(PublishResponse {
url: format!("/s/{token}"),
url: Some(format!("/s/{token}")), enabled: true,
}))
}