diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-04 01:11:50 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-04 01:11:50 +0100 |
| commit | fd93334a21907f959018e1b1f5df747a98d186c8 (patch) | |
| tree | 259e595a570b42a5ea082f596e1cb97e5011cfba /src/commands/qr.rs | |
| parent | http: add connect and request timeouts (diff) | |
| download | senator-sperma-fd93334a21907f959018e1b1f5df747a98d186c8.tar.gz senator-sperma-fd93334a21907f959018e1b1f5df747a98d186c8.zip | |
processes: add timeouts and keep decoding off the runtime
Diffstat (limited to 'src/commands/qr.rs')
| -rw-r--r-- | src/commands/qr.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/commands/qr.rs b/src/commands/qr.rs index 26232ee..c0b8af0 100644 --- a/src/commands/qr.rs +++ b/src/commands/qr.rs | |||
| @@ -61,10 +61,14 @@ pub async fn dekodowanie( | |||
| 61 | .await? | 61 | .await? |
| 62 | .bytes() | 62 | .bytes() |
| 63 | .await?; | 63 | .await?; |
| 64 | let img = image::load_from_memory(&img_data)?; | 64 | // Decoding is CPU-heavy: keep it off the async runtime. |
| 65 | let gray = img.to_luma8(); | 65 | let img_data = img_data.to_vec(); |
| 66 | 66 | let decoded = tokio::task::spawn_blocking(move || { | |
| 67 | let decoded = decode_qr_simple(&gray); | 67 | let img = image::load_from_memory(&img_data).ok()?; |
| 68 | let gray = img.to_luma8(); | ||
| 69 | decode_qr_simple(&gray) | ||
| 70 | }) | ||
| 71 | .await?; | ||
| 68 | match decoded { | 72 | match decoded { |
| 69 | Some(text) => { | 73 | Some(text) => { |
| 70 | ctx.say(lang::fmt_qr_decoded(&text)).await?; | 74 | ctx.say(lang::fmt_qr_decoded(&text)).await?; |
