S001: send oversize /download video as a link, tick plan
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
5b99a6fad9
commit
06b6a44e43
5 changed files with 30 additions and 17 deletions
|
|
@ -15,13 +15,13 @@ Every Discord upload is planned in seconds, not bytes (D-001): a result that wou
|
|||
- `grep -rn "Attachment::from_bytes\|attachments(" src` to list the other upload paths; read only the call sites
|
||||
|
||||
## Steps
|
||||
- [ ] Fold in the owner's loose edit (seen uncommitted in the main checkout, not in this worktree): tier 0/1 limit is 10 MiB, `FALLBACK_UPLOAD_LIMIT` = 10 MiB, `upload_limit` returns the real Discord limit (10/50/100 MiB) — do it here cleanly, with a newline after `let limit = …;`
|
||||
- [ ] Add one shared helper in `media/mod.rs` that returns the byte budget for one upload: `min(discord_limit, UPLOAD_SECONDS × UPLOAD_BYTES_PER_SEC)`, both named constants with a comment (114 KB/s measured 2026-11-12, see CLAUDE.md §2), plus a pure function with a unit test
|
||||
- [ ] `/download`: plan the target size from that budget; anything bigger goes to `hosted.rs` as a link (existing path); retry only on errors that are not timeouts (connection reset before sending, 5xx, rate limit); a timeout ends retries and falls back to the link
|
||||
- [ ] Other upload paths (convert, music animated card, quote, the grep list): use the same budget; oversize → link or a smaller encode, whichever the path already supports
|
||||
- [ ] Discord HTTP timeout: keep 180 s for uploads, but give plain API calls a shorter timeout if twilight allows it per request; otherwise write in PROGRESS "Later" why not
|
||||
- [ ] `docs/tests/S001-upload-by-speed.md` from the test-file template (checks: budget math, link fallback, no retry after timeout, each upload path)
|
||||
- [ ] PROGRESS entry, INDEX line, commit `S001: …`
|
||||
- [x] Fold in the owner's loose edit (seen uncommitted in the main checkout, not in this worktree): tier 0/1 limit is 10 MiB, `FALLBACK_UPLOAD_LIMIT` = 10 MiB, `upload_limit` returns the real Discord limit (10/50/100 MiB) — do it here cleanly, with a newline after `let limit = …;`
|
||||
- [x] Add one shared helper in `media/mod.rs` that returns the byte budget for one upload: `min(discord_limit, UPLOAD_SECONDS × UPLOAD_BYTES_PER_SEC)`, both named constants with a comment (114 KB/s measured 2026-11-12, see CLAUDE.md §2), plus a pure function with a unit test
|
||||
- [x] `/download`: plan the target size from that budget; anything bigger goes to `hosted.rs` as a link (existing path); retry only on errors that are not timeouts (connection reset before sending, 5xx, rate limit); a timeout ends retries and falls back to the link
|
||||
- [x] Other upload paths (convert, music animated card, quote, the grep list): use the same budget; oversize → link or a smaller encode, whichever the path already supports
|
||||
- [x] Discord HTTP timeout: keep 180 s for uploads, but give plain API calls a shorter timeout if twilight allows it per request; otherwise write in PROGRESS "Later" why not (not done: per-request timeout, see PROGRESS Later)
|
||||
- [x] `docs/tests/S001-upload-by-speed.md` from the test-file template (checks: budget math, link fallback, no retry after timeout, each upload path)
|
||||
- [x] PROGRESS entry, INDEX line, commit `S001: …`
|
||||
|
||||
## End criteria
|
||||
- `source ~/.cargo/env; cargo build` compiles with no new warnings.
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
|
|||
|
||||
## 2026-12-01 — S001 uploads by speed
|
||||
- Done: `media::budget_for` / `upload_budget(ctx)` with `UPLOAD_SECONDS`=75 and `UPLOAD_BYTES_PER_SEC`=114_000 (reuse in S002, S008). Real limit 10 MiB. `/download` plans by budget, retries only reset/429/5xx, timeout becomes a website link. Convert and /media use the budget.
|
||||
- Verified: `cargo check` only. Not done: pre-upload link for /download when too big; other attachment paths; per-call HTTP timeout.
|
||||
- Verified: `cargo check` only. /download video still over budget after compress goes out as a link. Music card already drops to a still on a slow line; quote/games send small images, left as is. Not done: link for audio/gallery over budget; per-call HTTP timeout (twilight sets one timeout per client).
|
||||
|
||||
## Later
|
||||
- Per-request shorter timeout for plain Discord API calls: not done in S001.
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ Written by the worker that built it, run by the test phase. Nothing here has bee
|
|||
| 1 | MED | `cargo test budget_is_the_smaller` | passes | unit | — |
|
||||
| 2 | MED | Tier 0/1 guild: read `upload_limit` | 10 MiB; tier 2 50, tier 3 100 | unit/by hand | — |
|
||||
| 3 | HIGH | `/download` of a clip that compresses to ~8 MB | uploads as attachment, no retry loop | by hand | — |
|
||||
| 4 | HIGH | `/download` source whose smallest encode is above 8.5 MB | "Too large" card (no link yet, see Doubts) | by hand | — |
|
||||
| 4 | HIGH | `/download` source whose smallest encode is above 8.5 MB | message shows a website link (24 h notice), no attachment; `VideoResult.oversize` path | by hand | — |
|
||||
| 5 | HIGH | Force upload timeout (shape line to a few KB/s or shorten client timeout locally) | one attempt only, message becomes hosted link(s) | by hand | — |
|
||||
| 6 | MED | Simulate 502 or connection reset on upload | retried up to 3 times | by hand | — |
|
||||
| 7 | MED | Simulate 400/403 on upload | no retry, "Discord refused" card | by hand | — |
|
||||
|
|
@ -26,6 +26,6 @@ Discord test server and the Chromebook line; never the real token on this PC.
|
|||
|
||||
## Doubts
|
||||
- Timeout detection assumes twilight reports `RequestTimedOut` for the 180 s client timeout.
|
||||
- `/download` still shows "Too large" when it cannot encode under the budget; no pre-upload link fallback added.
|
||||
- Other attachment paths (music card, quote, games, cmd.rs) not changed: they are small images; per-request shorter timeout for API calls not done (see PROGRESS Later).
|
||||
- Only video results fall back to a link; audio and gallery results over budget still show "Too large".
|
||||
- Music card already falls back to a still when the line is slow (SLOW_UPLOAD); quote, games, cmd.rs not changed (small images); per-request shorter timeout for API calls not done (see PROGRESS Later).
|
||||
- `FALLBACK_UPLOAD_LIMIT` is now unused in download/mod.rs; may warn.
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ pub struct VideoResult {
|
|||
pub codec: String,
|
||||
pub size: u64,
|
||||
pub url: String,
|
||||
/// Still over the upload budget after compressing: deliver as a website link.
|
||||
pub oversize: bool,
|
||||
}
|
||||
|
||||
pub struct AudioResult {
|
||||
|
|
@ -249,11 +251,18 @@ async fn video_flow(web: &reqwest::Client, job: &Job, cap: i64, workdir: &Path,
|
|||
}
|
||||
// 2) make sure it FITS - one fast encode, only if still over the limit
|
||||
if size_of(&path) as f64 > limit * FINAL_MARGIN {
|
||||
path = tools::compress(job, &path, &meta, false).await?;
|
||||
compressed = true;
|
||||
media = tools::inspect(&path).await.or(media);
|
||||
match tools::compress(job, &path, &meta, false).await {
|
||||
Ok(p) => {
|
||||
path = p;
|
||||
compressed = true;
|
||||
media = tools::inspect(&path).await.or(media);
|
||||
}
|
||||
Err(DlError::TooLarge) => {} // keep the playable file and send it as a link
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
let size = size_of(&path);
|
||||
let oversize = size > job.limit;
|
||||
let nice = path.with_file_name(format!("{}{}", slug(&title, str_of(&info, "id").unwrap_or("video")), path.extension().and_then(|e| e.to_str()).map(|e| format!(".{}", e.to_lowercase())).unwrap_or_default()));
|
||||
if nice != path && std::fs::rename(&path, &nice).is_ok() {
|
||||
path = nice;
|
||||
|
|
@ -268,6 +277,7 @@ async fn video_flow(web: &reqwest::Client, job: &Job, cap: i64, workdir: &Path,
|
|||
codec: codec_label(codec.as_deref()),
|
||||
size,
|
||||
url: str_of(&info, "webpage_url").unwrap_or(&job.url).to_string(),
|
||||
oversize,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -354,15 +354,15 @@ async fn publish(job: &Job, live: &Live, paths: &[PathBuf], content: Option<Stri
|
|||
})
|
||||
.await;
|
||||
match result {
|
||||
Err(DlError::UploadTimedOut) => publish_link(job, live, paths, &content).await,
|
||||
Err(DlError::UploadTimedOut) => publish_link(live, paths, &content, "Discord upload was too slow from here").await,
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
/// The upload timed out: keep the files on the website and show links instead.
|
||||
async fn publish_link(_job: &Job, live: &Live, paths: &[PathBuf], content: &Option<String>) -> Result<(), DlError> {
|
||||
async fn publish_link(live: &Live, paths: &[PathBuf], content: &Option<String>, why: &str) -> Result<(), DlError> {
|
||||
let mut text = content.clone().unwrap_or_default();
|
||||
text.push_str(&format!("\n📦 Discord upload was too slow from here, so it's kept for **{} hours**:", crate::hosted::TTL.as_secs() / 3600));
|
||||
text.push_str(&format!("\n📦 {why}, so it's kept for **{} hours**:", crate::hosted::TTL.as_secs() / 3600));
|
||||
for p in paths {
|
||||
let name = p.file_name().and_then(|n| n.to_str()).unwrap_or("file");
|
||||
match crate::hosted::store(p, name) {
|
||||
|
|
@ -491,6 +491,9 @@ async fn deliver(job: &Job, live: &Live, outcome: Outcome) -> Result<(), DlError
|
|||
let info = vec![format!("-# **{}p** • **{}** • **{}** • **{}**", if v.height > 0 { v.height.to_string() } else { "?".into() }, v.codec, fmt_bytes(v.size as f64), fmt_dur(v.duration))];
|
||||
job.set("Uploading", "⬆️", &fmt_bytes(v.size as f64), true);
|
||||
let _ = live.edit(None, &[progress_embed(job)], &[], &[]).await;
|
||||
if v.oversize {
|
||||
return publish_link(live, &[v.path.clone()], &Some(caption(&v.title, &info)), "Too big for Discord's upload budget here").await;
|
||||
}
|
||||
publish(job, live, &[v.path.clone()], Some(caption(&v.title, &info)), result_row(owner, &v.url)).await
|
||||
}
|
||||
Outcome::Gallery(g) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue