Skip to main content

max / makenotwork

5.7 KB · 145 lines History Blame Raw
1 //! Project and git repository models.
2
3 use chrono::{DateTime, Utc};
4 use serde::Serialize;
5 use sqlx::FromRow;
6
7 use super::super::id_types::{GitRepoId, ProjectId, ProjectSectionId, UserId};
8 use super::super::validated_types::Slug;
9
10 /// A creator's project (collection of items).
11 #[derive(Debug, Clone, FromRow, Serialize)]
12 pub struct DbProject {
13 /// Database primary key.
14 pub id: ProjectId,
15 /// Owning user's ID.
16 pub user_id: UserId,
17 /// URL-safe slug unique per user.
18 pub slug: Slug,
19 /// Display title.
20 pub title: String,
21 /// Optional longer description.
22 pub description: Option<String>,
23 /// Category type (e.g. software, music, blog).
24 pub project_type: super::super::ProjectType,
25 /// URL to the project's cover image.
26 pub cover_image_url: Option<String>,
27 /// Malware scan status for the cover image (`cover_s3_key`/`cover_image_url`),
28 /// which renders straight from the CDN. `String` (not `FileScanStatus`) so a
29 /// forward-compat DB value can't fail the row decode; the render gate treats
30 /// anything other than `"clean"` as hidden. Default `'pending'`.
31 pub cover_scan_status: String,
32 /// Whether this project is publicly visible.
33 pub is_public: bool,
34 /// When the project was created.
35 pub created_at: DateTime<Utc>,
36 /// When the project was last modified.
37 pub updated_at: DateTime<Utc>,
38 /// Generation counter for ETag-based HTTP caching. Bumped on any project-visible write.
39 pub cache_generation: i64,
40 /// Linked MT community ID (None if not yet provisioned or MT unavailable).
41 pub mt_community_id: Option<uuid::Uuid>,
42 /// Platform features enabled for this project (e.g. audio, blog, downloads).
43 pub features: Vec<String>,
44 /// Pricing model: free, buy_once, pwyw, or subscription.
45 pub pricing_model: super::super::PricingKind,
46 /// Price in cents (for buy_once); 0 for free projects.
47 pub price_cents: i32,
48 /// Minimum price in cents when PWYW is enabled (floor).
49 pub pwyw_min_cents: Option<i32>,
50 /// Whether this project requires license verification (phone-home) on content access.
51 pub license_verification_enabled: bool,
52 /// AI content tier: handmade, assisted, or generated.
53 pub ai_tier: super::super::AiTier,
54 /// Required disclosure text when ai_tier is assisted.
55 pub ai_disclosure: Option<String>,
56 /// Chosen built-in theme id for this project's public pages (and its items,
57 /// which inherit it). `None` = the platform default. See `crate::theming`.
58 pub theme_id: Option<String>,
59 /// Creator-authored project-page HTML (original source, pre-sanitization).
60 /// Empty string = default rendering. Item pages inherit this project's CSS
61 /// but have no HTML of their own. Served from `u.makenot.work`.
62 pub custom_html: String,
63 /// Creator-authored project-page CSS (original source, pre-sanitization).
64 /// Re-scoped onto this project's item pages at render time.
65 pub custom_css: String,
66 /// When the custom page was last saved (cache-key + moderation review).
67 pub custom_pages_updated_at: Option<DateTime<Utc>>,
68 }
69
70 /// A git repository tracked on disk, optionally linked to a project.
71 #[derive(Debug, Clone, FromRow, Serialize)]
72 pub struct DbGitRepo {
73 /// Database primary key.
74 pub id: GitRepoId,
75 /// Owning user's ID.
76 pub user_id: UserId,
77 /// Bare repository name (no path separators).
78 pub name: String,
79 /// Linked project (many repos can link to one project).
80 pub project_id: Option<ProjectId>,
81 /// When the repo was registered.
82 pub created_at: DateTime<Utc>,
83 /// Visibility: public, unlisted, or private.
84 pub visibility: super::super::Visibility,
85 /// Short description of the repository (editable via settings).
86 pub description: String,
87 /// What this repository is for. `Source` is every repository a creator
88 /// makes; `Annotations` is the one per-account repo holding only
89 /// refs/notes/*, private permanently.
90 pub kind: super::super::GitRepoKind,
91 }
92
93 /// A project row with an aggregated public item count (avoids N+1 queries).
94 #[derive(Debug, Clone, FromRow)]
95 #[allow(dead_code)] // Fields populated by sqlx query, read during type conversion
96 pub struct DbProjectWithItemCount {
97 /// Database primary key.
98 pub id: ProjectId,
99 /// Owning user's ID.
100 pub user_id: UserId,
101 /// URL-safe slug unique per user.
102 pub slug: Slug,
103 /// Display title.
104 pub title: String,
105 /// Optional longer description.
106 pub description: Option<String>,
107 /// Category type.
108 pub project_type: super::super::ProjectType,
109 /// URL to the project's cover image.
110 pub cover_image_url: Option<String>,
111 /// Malware scan status for the cover image; the render gate hides anything
112 /// other than `"clean"`. Selected explicitly by
113 /// `get_public_projects_with_item_counts`.
114 pub cover_scan_status: String,
115 /// Whether this project is publicly visible.
116 pub is_public: bool,
117 /// When the project was created.
118 pub created_at: DateTime<Utc>,
119 /// When the project was last modified.
120 pub updated_at: DateTime<Utc>,
121 /// Number of public items in this project.
122 pub item_count: i64,
123 }
124
125 /// A tabbed content section within a project.
126 #[derive(Debug, Clone, FromRow, Serialize)]
127 pub struct DbProjectSection {
128 /// Database primary key.
129 pub id: ProjectSectionId,
130 /// Parent project ID.
131 pub project_id: ProjectId,
132 /// Section tab title.
133 pub title: String,
134 /// URL-safe slug (unique per project).
135 pub slug: String,
136 /// Markdown body content.
137 pub body: String,
138 /// Display order among sibling sections.
139 pub sort_order: i32,
140 /// When this section was created.
141 pub created_at: DateTime<Utc>,
142 /// When this section was last modified.
143 pub updated_at: DateTime<Utc>,
144 }
145