mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 08:40:11 +00:00
feat(api): allow unauthed requests to /systems/:id/settings
This commit is contained in:
parent
0406c32f6b
commit
0610701252
14 changed files with 334 additions and 70 deletions
|
|
@ -33,3 +33,17 @@ macro_rules! fake_enum_impls {
|
|||
}
|
||||
|
||||
pub(crate) use fake_enum_impls;
|
||||
|
||||
macro_rules! privacy_lookup {
|
||||
($v:expr, $vprivacy:expr, $lookup_level:expr) => {
|
||||
if matches!($vprivacy, crate::PrivacyLevel::Public)
|
||||
|| matches!($lookup_level, crate::PrivacyLevel::Private)
|
||||
{
|
||||
Some($v)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use privacy_lookup;
|
||||
|
|
|
|||
|
|
@ -9,3 +9,25 @@ macro_rules! model {
|
|||
|
||||
model!(system);
|
||||
model!(system_config);
|
||||
|
||||
#[derive(serde::Serialize, Debug, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PrivacyLevel {
|
||||
Public,
|
||||
Private,
|
||||
}
|
||||
|
||||
// this sucks, put it somewhere else
|
||||
use sqlx::{postgres::PgTypeInfo, Database, Decode, Postgres, Type};
|
||||
use std::error::Error;
|
||||
_util::fake_enum_impls!(PrivacyLevel);
|
||||
|
||||
impl From<i32> for PrivacyLevel {
|
||||
fn from(value: i32) -> Self {
|
||||
match value {
|
||||
1 => PrivacyLevel::Public,
|
||||
2 => PrivacyLevel::Private,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +1,13 @@
|
|||
use std::error::Error;
|
||||
|
||||
use pk_macros::pk_model;
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
use sqlx::{postgres::PgTypeInfo, Database, Decode, Postgres, Type};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::_util::fake_enum_impls;
|
||||
use crate::PrivacyLevel;
|
||||
|
||||
// todo: fix this
|
||||
pub type SystemId = i32;
|
||||
|
||||
// todo: move this
|
||||
#[derive(serde::Serialize, Debug, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PrivacyLevel {
|
||||
Public,
|
||||
Private,
|
||||
}
|
||||
|
||||
fake_enum_impls!(PrivacyLevel);
|
||||
|
||||
impl From<i32> for PrivacyLevel {
|
||||
fn from(value: i32) -> Self {
|
||||
match value {
|
||||
1 => PrivacyLevel::Public,
|
||||
2 => PrivacyLevel::Private,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[pk_model]
|
||||
struct System {
|
||||
id: SystemId,
|
||||
|
|
@ -40,21 +17,25 @@ struct System {
|
|||
#[json = "uuid"]
|
||||
uuid: Uuid,
|
||||
#[json = "name"]
|
||||
#[privacy = name_privacy]
|
||||
name: Option<String>,
|
||||
#[json = "description"]
|
||||
#[privacy = description_privacy]
|
||||
description: Option<String>,
|
||||
#[json = "tag"]
|
||||
tag: Option<String>,
|
||||
#[json = "pronouns"]
|
||||
#[privacy = pronoun_privacy]
|
||||
pronouns: Option<String>,
|
||||
#[json = "avatar_url"]
|
||||
#[privacy = avatar_privacy]
|
||||
avatar_url: Option<String>,
|
||||
#[json = "banner_image"]
|
||||
#[json = "banner"]
|
||||
#[privacy = banner_privacy]
|
||||
banner_image: Option<String>,
|
||||
#[json = "color"]
|
||||
color: Option<String>,
|
||||
token: Option<String>,
|
||||
#[json = "webhook_url"]
|
||||
webhook_url: Option<String>,
|
||||
webhook_token: Option<String>,
|
||||
#[json = "created"]
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub const DEFAULT_GROUP_LIMIT: i32 = 250;
|
|||
|
||||
#[derive(serde::Serialize, Debug, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum HidPadFormat {
|
||||
pub enum HidPadFormat {
|
||||
#[serde(rename = "off")]
|
||||
None,
|
||||
Left,
|
||||
|
|
@ -31,7 +31,7 @@ impl From<i32> for HidPadFormat {
|
|||
|
||||
#[derive(serde::Serialize, Debug, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum ProxySwitchAction {
|
||||
pub enum ProxySwitchAction {
|
||||
Off,
|
||||
New,
|
||||
Add,
|
||||
|
|
@ -83,7 +83,8 @@ struct SystemConfig {
|
|||
#[json = "proxy_switch"]
|
||||
proxy_switch: ProxySwitchAction,
|
||||
#[json = "name_format"]
|
||||
name_format: String,
|
||||
#[default = "{name} {tag}".to_string()]
|
||||
name_format: Option<String>,
|
||||
#[json = "description_templates"]
|
||||
description_templates: Vec<String>,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue