add: full links api
This commit is contained in:
parent
c2dbe2f114
commit
ffdb767518
12 changed files with 532 additions and 4 deletions
41
crates/core/src/model/links.rs
Normal file
41
crates/core/src/model/links.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Link {
|
||||
pub id: usize,
|
||||
pub created: usize,
|
||||
/// Links should be selected by their owner, not their link list ID.
|
||||
/// This is why we do not store link list ID.
|
||||
pub owner: usize,
|
||||
pub label: String,
|
||||
pub href: String,
|
||||
/// As link icons are optional, `upload_id` is allowed to be 0.
|
||||
pub upload_id: usize,
|
||||
/// Clicks are tracked for supporters only.
|
||||
///
|
||||
/// When a user clicks on a link through the UI, they'll be redirect to
|
||||
/// `/links/{id}`. If the link's owner is a supporter, the link's clicks will
|
||||
/// be incremented.
|
||||
///
|
||||
/// The page should just serve a simple HTML document with a meta tag to redirect.
|
||||
/// We only really care about knowing they clicked it, so an automatic redirect will do.
|
||||
pub clicks: usize,
|
||||
pub position: usize,
|
||||
}
|
||||
|
||||
impl Link {
|
||||
/// Create a new [`Link`].
|
||||
pub fn new(owner: usize, label: String, href: String, position: usize) -> Self {
|
||||
Self {
|
||||
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
|
||||
created: unix_epoch_timestamp(),
|
||||
owner,
|
||||
label,
|
||||
href,
|
||||
upload_id: 0,
|
||||
clicks: 0,
|
||||
position,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ pub mod channels;
|
|||
pub mod communities;
|
||||
pub mod communities_permissions;
|
||||
pub mod journals;
|
||||
pub mod links;
|
||||
pub mod moderation;
|
||||
pub mod oauth;
|
||||
pub mod permissions;
|
||||
|
|
|
@ -68,6 +68,8 @@ pub enum AppScope {
|
|||
UserReadJournals,
|
||||
/// Read the user's notes.
|
||||
UserReadNotes,
|
||||
/// Read the user's links.
|
||||
UserReadLinks,
|
||||
/// Create posts as the user.
|
||||
UserCreatePosts,
|
||||
/// Create messages as the user.
|
||||
|
@ -86,6 +88,8 @@ pub enum AppScope {
|
|||
UserCreateJournals,
|
||||
/// Create notes on behalf of the user.
|
||||
UserCreateNotes,
|
||||
/// Create links on behalf of the user.
|
||||
UserCreateLinks,
|
||||
/// Delete posts owned by the user.
|
||||
UserDeletePosts,
|
||||
/// Delete messages owned by the user.
|
||||
|
@ -120,6 +124,8 @@ pub enum AppScope {
|
|||
UserManageJournals,
|
||||
/// Manage the user's notes.
|
||||
UserManageNotes,
|
||||
/// Manage the user's links.
|
||||
UserManageLinks,
|
||||
/// Edit posts created by the user.
|
||||
UserEditPosts,
|
||||
/// Edit drafts created by the user.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue