| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
use makeover_layout::Family; |
| 41 |
use quasi_router::{Accepted, Action, Field, Node}; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
fn version_suffixes() -> Vec<Accepted> { |
| 50 |
[ |
| 51 |
".zip", |
| 52 |
".dmg", |
| 53 |
".exe", |
| 54 |
".appimage", |
| 55 |
".deb", |
| 56 |
".tar.gz", |
| 57 |
".clap", |
| 58 |
".vst3", |
| 59 |
] |
| 60 |
.into_iter() |
| 61 |
.map(Accepted::suffix) |
| 62 |
.collect() |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
fn area(prompt: &str, hint: &str, fallback: &str, field: Field) -> String { |
| 81 |
use quasi_axum::Serves as _; |
| 82 |
|
| 83 |
|
| 84 |
let inner = quasi_webview::Webview::new().fragment(&Node::field(field)); |
| 85 |
format!( |
| 86 |
"<div class=\"file-upload-area\" data-upload-fallback=\"{}\">\ |
| 87 |
<div class=\"upload-text\">{}</div>\ |
| 88 |
<div class=\"upload-hint\">{}</div>{inner}</div>", |
| 89 |
crate::helpers::escape_html(fallback), |
| 90 |
crate::helpers::escape_html(prompt), |
| 91 |
crate::helpers::escape_html(hint), |
| 92 |
) |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
#[must_use] |
| 103 |
pub fn audio(item_id: &str) -> String { |
| 104 |
let field = Field::upload("audio", "Audio file", [Accepted::family(Family::Audio)]).changes( |
| 105 |
Action::post("/api/upload/presign") |
| 106 |
.with("item_id", item_id) |
| 107 |
.with("file_type", "audio") |
| 108 |
.awaiting() |
| 109 |
.by_host(), |
| 110 |
); |
| 111 |
|
| 112 |
area( |
| 113 |
"Drop audio file here or choose one to upload", |
| 114 |
"Supports MP3, WAV, FLAC, M4A up to 500 MB", |
| 115 |
"audio/mpeg", |
| 116 |
field, |
| 117 |
) |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
#[must_use] |
| 126 |
pub fn existing_version(version_id: &str) -> String { |
| 127 |
let field = Field::upload("version-file", "Version file", version_suffixes()).changes( |
| 128 |
Action::post(format!("/api/versions/{version_id}/upload/presign")) |
| 129 |
.awaiting() |
| 130 |
.by_host(), |
| 131 |
); |
| 132 |
|
| 133 |
area( |
| 134 |
"Drop file to upload for this version", |
| 135 |
"ZIP, DMG, EXE, AppImage, DEB, tar.gz, CLAP, VST3", |
| 136 |
"application/octet-stream", |
| 137 |
field, |
| 138 |
) |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
#[must_use] |
| 149 |
pub fn version_queue() -> String { |
| 150 |
use quasi_axum::Serves as _; |
| 151 |
|
| 152 |
let field = Field::upload("version-files", "Files", version_suffixes()).many(); |
| 153 |
quasi_webview::Webview::new().fragment(&Node::field(field)) |
| 154 |
} |
| 155 |
|
| 156 |
#[cfg(test)] |
| 157 |
mod tests { |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
#[test] |
| 163 |
fn an_audio_upload_says_what_it_takes_where_it_goes_and_that_it_waits() { |
| 164 |
let html = super::audio("11111111-1111-1111-1111-111111111111"); |
| 165 |
|
| 166 |
assert!(html.contains(r#"type="file""#), "{html}"); |
| 167 |
assert!(html.contains(r#"accept="audio/*""#), "{html}"); |
| 168 |
assert!(!html.contains(" multiple"), "{html}"); |
| 169 |
assert!( |
| 170 |
html.contains(r#"data-sends="/api/upload/presign""#), |
| 171 |
"{html}" |
| 172 |
); |
| 173 |
assert!(html.contains("data-awaiting="), "{html}"); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
#[test] |
| 180 |
fn no_transport_is_emitted_for_a_host_made_call() { |
| 181 |
let html = super::audio("11111111-1111-1111-1111-111111111111"); |
| 182 |
|
| 183 |
assert!(!html.contains("hx-post"), "{html}"); |
| 184 |
assert!(!html.contains("hx-trigger"), "{html}"); |
| 185 |
assert!(!html.contains("href="), "{html}"); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
#[test] |
| 193 |
fn the_payload_rides_with_the_destination() { |
| 194 |
let html = super::audio("11111111-1111-1111-1111-111111111111"); |
| 195 |
|
| 196 |
assert!(html.contains("data-vals="), "{html}"); |
| 197 |
assert!(html.contains("item_id"), "{html}"); |
| 198 |
assert!( |
| 199 |
html.contains("11111111-1111-1111-1111-111111111111"), |
| 200 |
"{html}" |
| 201 |
); |
| 202 |
assert!(html.contains("file_type"), "{html}"); |
| 203 |
assert!(!html.contains("hx-vals"), "{html}"); |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
#[test] |
| 209 |
fn both_version_surfaces_take_the_same_files() { |
| 210 |
let single = super::existing_version("22222222-2222-2222-2222-222222222222"); |
| 211 |
let queue = super::version_queue(); |
| 212 |
let accept = r#"accept=".zip,.dmg,.exe,.appimage,.deb,.tar.gz,.clap,.vst3""#; |
| 213 |
|
| 214 |
assert!(single.contains(accept), "{single}"); |
| 215 |
assert!(queue.contains(accept), "{queue}"); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
#[test] |
| 220 |
fn an_existing_version_is_addressed_by_id() { |
| 221 |
let html = super::existing_version("22222222-2222-2222-2222-222222222222"); |
| 222 |
|
| 223 |
assert!( |
| 224 |
html.contains( |
| 225 |
r#"data-sends="/api/versions/22222222-2222-2222-2222-222222222222/upload/presign""# |
| 226 |
), |
| 227 |
"{html}" |
| 228 |
); |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
#[test] |
| 235 |
fn the_queue_takes_many_files_and_sends_none_of_them() { |
| 236 |
let html = super::version_queue(); |
| 237 |
|
| 238 |
assert!(html.contains(" multiple"), "{html}"); |
| 239 |
assert!(!html.contains("data-sends"), "{html}"); |
| 240 |
assert!(!html.contains("data-awaiting"), "{html}"); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
#[test] |
| 248 |
fn the_drop_area_is_there_for_the_binder() { |
| 249 |
let html = super::audio("11111111-1111-1111-1111-111111111111"); |
| 250 |
|
| 251 |
assert!(html.contains(r#"class="file-upload-area""#), "{html}"); |
| 252 |
assert!(html.contains("Drop audio file here"), "{html}"); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
fn audio_item(audio_s3_key: Option<String>) -> crate::types::Item { |
| 258 |
crate::types::Item { |
| 259 |
id: "11111111-1111-1111-1111-111111111111".into(), |
| 260 |
title: "A recording".into(), |
| 261 |
price: "0".into(), |
| 262 |
price_cents: 0, |
| 263 |
item_type: "audio".into(), |
| 264 |
description: String::new(), |
| 265 |
thumbnail: String::new(), |
| 266 |
release_date: String::new(), |
| 267 |
sales_count: 0, |
| 268 |
tags: Vec::new(), |
| 269 |
content: crate::types::ItemContent::Audio { |
| 270 |
duration: None, |
| 271 |
duration_seconds: None, |
| 272 |
cover_url: None, |
| 273 |
episode_number: None, |
| 274 |
audio_s3_key, |
| 275 |
}, |
| 276 |
cover_image_url: None, |
| 277 |
is_free: true, |
| 278 |
can_access: true, |
| 279 |
enable_license_keys: false, |
| 280 |
default_max_activations: None, |
| 281 |
pwyw_enabled: false, |
| 282 |
pwyw_min_cents: None, |
| 283 |
publish_at: None, |
| 284 |
is_public: true, |
| 285 |
listed: true, |
| 286 |
bundle_item_count: 0, |
| 287 |
license_preset: None, |
| 288 |
custom_license_text: None, |
| 289 |
ai_tier: crate::db::AiTier::Handmade, |
| 290 |
ai_disclosure: None, |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
#[test] |
| 299 |
fn the_audio_call_site_is_wired_and_carries_where_it_goes_after() { |
| 300 |
use askama::Template as _; |
| 301 |
|
| 302 |
let html = crate::templates::ItemDetailsTabTemplate { |
| 303 |
item: audio_item(None), |
| 304 |
bundle_items: Vec::new(), |
| 305 |
bundleable_items: Vec::new(), |
| 306 |
sections: Vec::new(), |
| 307 |
} |
| 308 |
.render() |
| 309 |
.expect("render the details tab"); |
| 310 |
|
| 311 |
assert!( |
| 312 |
html.contains(r#"data-sends="/api/upload/presign""#), |
| 313 |
"{html}" |
| 314 |
); |
| 315 |
assert!( |
| 316 |
html.contains( |
| 317 |
r#"data-upload-goes="/dashboard/item/11111111-1111-1111-1111-111111111111?tab=files""# |
| 318 |
), |
| 319 |
"{html}" |
| 320 |
); |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
#[test] |
| 327 |
fn the_files_call_sites_keep_what_the_host_reads_them_by() { |
| 328 |
use askama::Template as _; |
| 329 |
|
| 330 |
let version = crate::types::Version { |
| 331 |
id: "22222222-2222-2222-2222-222222222222".into(), |
| 332 |
number: "1.0".into(), |
| 333 |
uploaded_date: "2026-08-20".into(), |
| 334 |
file_count: 0, |
| 335 |
size: "0 B".into(), |
| 336 |
downloads: 0, |
| 337 |
status: "draft".into(), |
| 338 |
is_current: true, |
| 339 |
has_file: false, |
| 340 |
file_name: None, |
| 341 |
label: None, |
| 342 |
}; |
| 343 |
|
| 344 |
let html = crate::templates::ItemFilesTabTemplate { |
| 345 |
item: audio_item(None), |
| 346 |
versions: vec![version], |
| 347 |
} |
| 348 |
.render() |
| 349 |
.expect("render the files tab"); |
| 350 |
|
| 351 |
assert!(html.contains(r#"id="version-files""#), "{html}"); |
| 352 |
assert!( |
| 353 |
html.contains(r#"id="existing-version-upload-22222222-2222-2222-2222-222222222222""#), |
| 354 |
"{html}" |
| 355 |
); |
| 356 |
assert!( |
| 357 |
html.contains( |
| 358 |
r#"data-sends="/api/versions/22222222-2222-2222-2222-222222222222/upload/presign""# |
| 359 |
), |
| 360 |
"{html}" |
| 361 |
); |
| 362 |
} |
| 363 |
} |
| 364 |
|