| 1 |
|
| 2 |
|
| 3 |
use axum::{Json, extract::State, response::IntoResponse}; |
| 4 |
use serde::{Deserialize, Serialize}; |
| 5 |
use sqlx::PgPool; |
| 6 |
|
| 7 |
use crate::{ |
| 8 |
AppStorage, Scanning, |
| 9 |
auth::AuthUser, |
| 10 |
config::Config, |
| 11 |
db::{self, ItemId, ProjectId}, |
| 12 |
error::{AppError, Result, ResultExt}, |
| 13 |
storage::{self, CACHE_CONTROL_IMMUTABLE, FileType, S3Client}, |
| 14 |
}; |
| 15 |
|
| 16 |
use super::{CommitTarget, PresignUploadResponse, commit_upload}; |
| 17 |
|
| 18 |
|
| 19 |
#[derive(Debug, Deserialize)] |
| 20 |
pub(super) struct ProjectImagePresignRequest { |
| 21 |
pub project_id: ProjectId, |
| 22 |
pub file_name: String, |
| 23 |
pub content_type: String, |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
#[derive(Debug, Deserialize)] |
| 28 |
pub(super) struct ProjectImageConfirmRequest { |
| 29 |
pub project_id: ProjectId, |
| 30 |
pub s3_key: String, |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
#[derive(Debug, Serialize)] |
| 35 |
pub(super) struct ProjectImageConfirmResponse { |
| 36 |
pub success: bool, |
| 37 |
pub image_url: String, |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
#[derive(Debug, Deserialize)] |
| 42 |
pub(super) struct ItemImagePresignRequest { |
| 43 |
pub item_id: ItemId, |
| 44 |
pub file_name: String, |
| 45 |
pub content_type: String, |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
#[derive(Debug, Deserialize)] |
| 50 |
pub(super) struct ItemImageConfirmRequest { |
| 51 |
pub item_id: ItemId, |
| 52 |
pub s3_key: String, |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
#[tracing::instrument(skip_all, name = "storage::project_image_presign", fields(user_id = %user.id))] |
| 61 |
pub(super) async fn project_image_presign( |
| 62 |
State(db): State<PgPool>, |
| 63 |
State(storage): State<AppStorage>, |
| 64 |
AuthUser(user): AuthUser, |
| 65 |
Json(req): Json<ProjectImagePresignRequest>, |
| 66 |
) -> Result<impl IntoResponse> { |
| 67 |
user.check_not_suspended()?; |
| 68 |
let s3 = storage.require_s3()?; |
| 69 |
|
| 70 |
let file_type = FileType::Cover; |
| 71 |
S3Client::validate_content_type(file_type, &req.content_type)?; |
| 72 |
S3Client::validate_extension(file_type, &req.file_name)?; |
| 73 |
|
| 74 |
|
| 75 |
let project = db::projects::get_project_by_id(&db, req.project_id) |
| 76 |
.await? |
| 77 |
.ok_or(AppError::NotFound)?; |
| 78 |
|
| 79 |
if project.user_id != user.id { |
| 80 |
return Err(AppError::Forbidden); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
db::creator_tiers::check_presign_allowed(&db, user.id, file_type).await?; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
let s3_key = S3Client::generate_staging_key(&req.file_name); |
| 89 |
|
| 90 |
|
| 91 |
db::pending_uploads::record_pending_upload(&db, user.id, &s3_key, "main").await?; |
| 92 |
|
| 93 |
let expires_in = 3600; |
| 94 |
let upload_url = s3 |
| 95 |
.presign_upload( |
| 96 |
&s3_key, |
| 97 |
&req.content_type, |
| 98 |
Some(expires_in), |
| 99 |
Some(CACHE_CONTROL_IMMUTABLE), |
| 100 |
None, |
| 101 |
) |
| 102 |
.await |
| 103 |
.context("presign upload for project image")?; |
| 104 |
|
| 105 |
Ok(Json(PresignUploadResponse { |
| 106 |
upload_url, |
| 107 |
s3_key: s3_key.into_string(), |
| 108 |
expires_in, |
| 109 |
cache_control: Some(CACHE_CONTROL_IMMUTABLE.to_string()), |
| 110 |
max_file_bytes: None, |
| 111 |
})) |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
#[tracing::instrument(skip_all, name = "storage::project_image_confirm", fields(user_id = %user.id))] |
| 120 |
pub(super) async fn project_image_confirm( |
| 121 |
State(db): State<PgPool>, |
| 122 |
State(storage): State<AppStorage>, |
| 123 |
State(config): State<Config>, |
| 124 |
State(scanning): State<Scanning>, |
| 125 |
AuthUser(user): AuthUser, |
| 126 |
Json(req): Json<ProjectImageConfirmRequest>, |
| 127 |
) -> Result<impl IntoResponse> { |
| 128 |
user.check_not_suspended()?; |
| 129 |
let s3 = storage.require_s3()?; |
| 130 |
|
| 131 |
|
| 132 |
let project = db::projects::get_project_by_id(&db, req.project_id) |
| 133 |
.await? |
| 134 |
.ok_or(AppError::NotFound)?; |
| 135 |
|
| 136 |
if project.user_id != user.id { |
| 137 |
return Err(AppError::Forbidden); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
if !db::pending_uploads::is_owned(&db, user.id, &req.s3_key, "main").await? { |
| 146 |
return Err(AppError::BadRequest("Invalid upload key".to_string())); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
let file_size_bytes = s3.object_size(&req.s3_key).await?.ok_or_else(|| { |
| 152 |
AppError::BadRequest("Upload not found. Please try uploading again.".to_string()) |
| 153 |
})?; |
| 154 |
if file_size_bytes as u64 > FileType::Cover.max_size() { |
| 155 |
super::enqueue_s3_orphan( |
| 156 |
&db, |
| 157 |
&req.s3_key, |
| 158 |
crate::storage::S3Bucket::Main, |
| 159 |
"image_upload_rejected", |
| 160 |
) |
| 161 |
.await; |
| 162 |
return Err(AppError::BadRequest(format!( |
| 163 |
"File exceeds maximum size of {} MB", |
| 164 |
FileType::Cover.max_size() / (1024 * 1024) |
| 165 |
))); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
if let Some(ref cur_url) = project.cover_image_url |
| 172 |
&& let Some(cur_key) = storage::extract_s3_key_from_url( |
| 173 |
cur_url, |
| 174 |
&config.cdn_base_url, |
| 175 |
Some(s3.bucket()), |
| 176 |
config.storage.as_ref().map(|c| c.endpoint.as_str()), |
| 177 |
) |
| 178 |
&& cur_key == req.s3_key |
| 179 |
{ |
| 180 |
|
| 181 |
|
| 182 |
if let Err(e) = |
| 183 |
db::pending_uploads::remove_pending_upload(&db, user.id, &req.s3_key, "main").await |
| 184 |
{ |
| 185 |
tracing::warn!(error = ?e, key = %req.s3_key, "remove_pending_upload failed on idempotent re-confirm"); |
| 186 |
} |
| 187 |
return Ok(Json(ProjectImageConfirmResponse { |
| 188 |
success: true, |
| 189 |
image_url: cur_url.clone(), |
| 190 |
})); |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
let max_storage = match db::creator_tiers::check_upload_allowed( |
| 195 |
&db, |
| 196 |
user.id, |
| 197 |
FileType::Cover, |
| 198 |
file_size_bytes, |
| 199 |
) |
| 200 |
.await |
| 201 |
{ |
| 202 |
Ok(max) => max, |
| 203 |
Err(e) => { |
| 204 |
super::enqueue_s3_orphan( |
| 205 |
&db, |
| 206 |
&req.s3_key, |
| 207 |
crate::storage::S3Bucket::Main, |
| 208 |
"image_upload_rejected", |
| 209 |
) |
| 210 |
.await; |
| 211 |
return Err(e); |
| 212 |
} |
| 213 |
}; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
let mut replace_old_size: Option<i64> = None; |
| 221 |
let old_key_to_delete: Option<String> = if let Some(ref old_url) = project.cover_image_url |
| 222 |
&& let Some(old_key) = storage::extract_s3_key_from_url( |
| 223 |
old_url, |
| 224 |
&config.cdn_base_url, |
| 225 |
Some(s3.bucket()), |
| 226 |
config.storage.as_ref().map(|c| c.endpoint.as_str()), |
| 227 |
) { |
| 228 |
match s3.object_size(&old_key).await { |
| 229 |
Ok(Some(old_size)) if old_size > 0 => { |
| 230 |
replace_old_size = Some(old_size); |
| 231 |
Some(old_key) |
| 232 |
} |
| 233 |
Ok(Some(_) | None) => { |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
Some(old_key) |
| 238 |
} |
| 239 |
Err(e) => { |
| 240 |
|
| 241 |
|
| 242 |
super::enqueue_s3_orphan( |
| 243 |
&db, |
| 244 |
&req.s3_key, |
| 245 |
crate::storage::S3Bucket::Main, |
| 246 |
"image_upload_rejected", |
| 247 |
) |
| 248 |
.await; |
| 249 |
tracing::warn!(key = %old_key, error = ?e, "S3 probe failed during project image replace"); |
| 250 |
return Err(AppError::ServiceUnavailable( |
| 251 |
"Could not verify previous image. Please try again.".to_string(), |
| 252 |
)); |
| 253 |
} |
| 254 |
} |
| 255 |
} else { |
| 256 |
None |
| 257 |
}; |
| 258 |
|
| 259 |
let image_url = storage::build_project_image_url(&config.cdn_base_url, &req.s3_key); |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
let committed: Result<bool> = async { |
| 267 |
let mut tx = db.begin().await?; |
| 268 |
db::creator_tiers::try_apply_storage_on( |
| 269 |
&mut tx, |
| 270 |
user.id, |
| 271 |
replace_old_size, |
| 272 |
file_size_bytes, |
| 273 |
max_storage, |
| 274 |
) |
| 275 |
.await?; |
| 276 |
let ok = db::projects::update_project_cover_cas( |
| 277 |
&mut *tx, |
| 278 |
req.project_id, |
| 279 |
user.id, |
| 280 |
project.cover_image_url.as_deref(), |
| 281 |
&image_url, |
| 282 |
&req.s3_key, |
| 283 |
file_size_bytes, |
| 284 |
) |
| 285 |
.await?; |
| 286 |
if !ok { |
| 287 |
return Ok(false); |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
if let Some(old_key) = old_key_to_delete.as_deref() { |
| 294 |
db::pending_s3_deletions::enqueue_deletions( |
| 295 |
&mut *tx, |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
&crate::storage::both_bucket_delete(old_key), |
| 302 |
"project_image_replace", |
| 303 |
) |
| 304 |
.await?; |
| 305 |
} |
| 306 |
tx.commit().await?; |
| 307 |
Ok(true) |
| 308 |
} |
| 309 |
.await; |
| 310 |
|
| 311 |
match committed { |
| 312 |
Err(e) => { |
| 313 |
|
| 314 |
super::enqueue_s3_orphan( |
| 315 |
&db, |
| 316 |
&req.s3_key, |
| 317 |
crate::storage::S3Bucket::Main, |
| 318 |
"project_image_update_failed", |
| 319 |
) |
| 320 |
.await; |
| 321 |
return Err(e); |
| 322 |
} |
| 323 |
Ok(false) => { |
| 324 |
super::enqueue_s3_orphan( |
| 325 |
&db, |
| 326 |
&req.s3_key, |
| 327 |
crate::storage::S3Bucket::Main, |
| 328 |
"project_image_update_failed", |
| 329 |
) |
| 330 |
.await; |
| 331 |
return Err(AppError::BadRequest( |
| 332 |
"Project was modified concurrently. Please try uploading again.".to_string(), |
| 333 |
)); |
| 334 |
} |
| 335 |
Ok(true) => {} |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
db::pending_uploads::remove_pending_upload(&db, user.id, &req.s3_key, "main").await?; |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
commit_upload( |
| 346 |
&db, |
| 347 |
scanning.scanner.as_ref(), |
| 348 |
CommitTarget::ProjectImage(req.project_id), |
| 349 |
&req.s3_key, |
| 350 |
FileType::Cover, |
| 351 |
user.id, |
| 352 |
file_size_bytes, |
| 353 |
) |
| 354 |
.await?; |
| 355 |
|
| 356 |
db::projects::bump_cache_generation(&db, req.project_id).await?; |
| 357 |
|
| 358 |
tracing::info!( |
| 359 |
"Project image confirmed: project={}, key={}, size={}", |
| 360 |
req.project_id, |
| 361 |
req.s3_key, |
| 362 |
file_size_bytes |
| 363 |
); |
| 364 |
|
| 365 |
Ok(Json(ProjectImageConfirmResponse { |
| 366 |
success: true, |
| 367 |
image_url, |
| 368 |
})) |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
#[tracing::instrument(skip_all, name = "storage::item_image_presign", fields(user_id = %user.id))] |
| 377 |
pub(super) async fn item_image_presign( |
| 378 |
State(db): State<PgPool>, |
| 379 |
State(storage): State<AppStorage>, |
| 380 |
AuthUser(user): AuthUser, |
| 381 |
Json(req): Json<ItemImagePresignRequest>, |
| 382 |
) -> Result<impl IntoResponse> { |
| 383 |
user.check_not_suspended()?; |
| 384 |
let s3 = storage.require_s3()?; |
| 385 |
|
| 386 |
let file_type = FileType::Cover; |
| 387 |
S3Client::validate_content_type(file_type, &req.content_type)?; |
| 388 |
S3Client::validate_extension(file_type, &req.file_name)?; |
| 389 |
|
| 390 |
|
| 391 |
let owner = db::items::get_item_owner(&db, req.item_id) |
| 392 |
.await? |
| 393 |
.ok_or(AppError::NotFound)?; |
| 394 |
|
| 395 |
if owner != user.id { |
| 396 |
return Err(AppError::Forbidden); |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
db::creator_tiers::check_presign_allowed(&db, user.id, file_type).await?; |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
let s3_key = S3Client::generate_staging_key(&req.file_name); |
| 405 |
|
| 406 |
|
| 407 |
db::pending_uploads::record_pending_upload(&db, user.id, &s3_key, "main").await?; |
| 408 |
|
| 409 |
let expires_in = 3600; |
| 410 |
let upload_url = s3 |
| 411 |
.presign_upload( |
| 412 |
&s3_key, |
| 413 |
&req.content_type, |
| 414 |
Some(expires_in), |
| 415 |
Some(CACHE_CONTROL_IMMUTABLE), |
| 416 |
None, |
| 417 |
) |
| 418 |
.await |
| 419 |
.context("presign upload for item image")?; |
| 420 |
|
| 421 |
Ok(Json(PresignUploadResponse { |
| 422 |
upload_url, |
| 423 |
s3_key: s3_key.into_string(), |
| 424 |
expires_in, |
| 425 |
cache_control: Some(CACHE_CONTROL_IMMUTABLE.to_string()), |
| 426 |
max_file_bytes: None, |
| 427 |
})) |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
#[tracing::instrument(skip_all, name = "storage::item_image_confirm", fields(user_id = %user.id))] |
| 436 |
pub(super) async fn item_image_confirm( |
| 437 |
State(db): State<PgPool>, |
| 438 |
State(storage): State<AppStorage>, |
| 439 |
State(config): State<Config>, |
| 440 |
State(scanning): State<Scanning>, |
| 441 |
AuthUser(user): AuthUser, |
| 442 |
Json(req): Json<ItemImageConfirmRequest>, |
| 443 |
) -> Result<impl IntoResponse> { |
| 444 |
user.check_not_suspended()?; |
| 445 |
let s3 = storage.require_s3()?; |
| 446 |
|
| 447 |
|
| 448 |
let owner = db::items::get_item_owner(&db, req.item_id) |
| 449 |
.await? |
| 450 |
.ok_or(AppError::NotFound)?; |
| 451 |
|
| 452 |
if owner != user.id { |
| 453 |
return Err(AppError::Forbidden); |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
if !db::pending_uploads::is_owned(&db, user.id, &req.s3_key, "main").await? { |
| 462 |
return Err(AppError::BadRequest("Invalid upload key".to_string())); |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
let file_size_bytes = s3.object_size(&req.s3_key).await?.ok_or_else(|| { |
| 468 |
AppError::BadRequest("Upload not found. Please try uploading again.".to_string()) |
| 469 |
})?; |
| 470 |
if file_size_bytes as u64 > FileType::Cover.max_size() { |
| 471 |
super::enqueue_s3_orphan( |
| 472 |
&db, |
| 473 |
&req.s3_key, |
| 474 |
crate::storage::S3Bucket::Main, |
| 475 |
"image_upload_rejected", |
| 476 |
) |
| 477 |
.await; |
| 478 |
return Err(AppError::BadRequest(format!( |
| 479 |
"File exceeds maximum size of {} MB", |
| 480 |
FileType::Cover.max_size() / (1024 * 1024) |
| 481 |
))); |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
let existing_item = db::items::get_item_by_id(&db, req.item_id).await?; |
| 489 |
if let Some(ref item) = existing_item |
| 490 |
&& item.cover_s3_key.as_deref() == Some(&req.s3_key) |
| 491 |
{ |
| 492 |
|
| 493 |
|
| 494 |
if let Err(e) = |
| 495 |
db::pending_uploads::remove_pending_upload(&db, user.id, &req.s3_key, "main").await |
| 496 |
{ |
| 497 |
tracing::warn!(error = ?e, key = %req.s3_key, "remove_pending_upload failed on idempotent re-confirm"); |
| 498 |
} |
| 499 |
return Ok(Json(super::images::ProjectImageConfirmResponse { |
| 500 |
success: true, |
| 501 |
image_url: item.cover_image_url.clone().unwrap_or_default(), |
| 502 |
})); |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
let max_storage = match db::creator_tiers::check_upload_allowed( |
| 507 |
&db, |
| 508 |
user.id, |
| 509 |
FileType::Cover, |
| 510 |
file_size_bytes, |
| 511 |
) |
| 512 |
.await |
| 513 |
{ |
| 514 |
Ok(max) => max, |
| 515 |
Err(e) => { |
| 516 |
super::enqueue_s3_orphan( |
| 517 |
&db, |
| 518 |
&req.s3_key, |
| 519 |
crate::storage::S3Bucket::Main, |
| 520 |
"image_upload_rejected", |
| 521 |
) |
| 522 |
.await; |
| 523 |
return Err(e); |
| 524 |
} |
| 525 |
}; |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
let expected_old_key: Option<String> = |
| 532 |
existing_item.as_ref().and_then(|i| i.cover_s3_key.clone()); |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
let (replace_old_size, old_key_to_delete): (Option<i64>, Option<String>) = |
| 538 |
match existing_item.as_ref().and_then(|i| { |
| 539 |
Some(( |
| 540 |
i.cover_s3_key.clone()?, |
| 541 |
i.cover_file_size_bytes.unwrap_or(0), |
| 542 |
)) |
| 543 |
}) { |
| 544 |
Some((key, size)) if size > 0 => (Some(size), Some(key)), |
| 545 |
_ => (None, None), |
| 546 |
}; |
| 547 |
|
| 548 |
let image_url = storage::build_project_image_url(&config.cdn_base_url, &req.s3_key); |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
let committed: Result<bool> = async { |
| 556 |
let mut tx = db.begin().await?; |
| 557 |
db::creator_tiers::try_apply_storage_on( |
| 558 |
&mut tx, |
| 559 |
user.id, |
| 560 |
replace_old_size, |
| 561 |
file_size_bytes, |
| 562 |
max_storage, |
| 563 |
) |
| 564 |
.await?; |
| 565 |
let ok = db::items::update_item_cover( |
| 566 |
&mut *tx, |
| 567 |
req.item_id, |
| 568 |
user.id, |
| 569 |
expected_old_key.as_deref(), |
| 570 |
&image_url, |
| 571 |
&req.s3_key, |
| 572 |
file_size_bytes, |
| 573 |
) |
| 574 |
.await?; |
| 575 |
if !ok { |
| 576 |
return Ok(false); |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
if let Some(old_key) = old_key_to_delete.as_deref() { |
| 582 |
db::pending_s3_deletions::enqueue_deletions( |
| 583 |
&mut *tx, |
| 584 |
|
| 585 |
|
| 586 |
&crate::storage::both_bucket_delete(old_key), |
| 587 |
"item_image_replace", |
| 588 |
) |
| 589 |
.await?; |
| 590 |
} |
| 591 |
tx.commit().await?; |
| 592 |
Ok(true) |
| 593 |
} |
| 594 |
.await; |
| 595 |
|
| 596 |
match committed { |
| 597 |
Err(e) => { |
| 598 |
super::enqueue_s3_orphan( |
| 599 |
&db, |
| 600 |
&req.s3_key, |
| 601 |
crate::storage::S3Bucket::Main, |
| 602 |
"item_image_update_failed", |
| 603 |
) |
| 604 |
.await; |
| 605 |
return Err(e); |
| 606 |
} |
| 607 |
Ok(false) => { |
| 608 |
super::enqueue_s3_orphan( |
| 609 |
&db, |
| 610 |
&req.s3_key, |
| 611 |
crate::storage::S3Bucket::Main, |
| 612 |
"item_image_update_failed", |
| 613 |
) |
| 614 |
.await; |
| 615 |
return Err(AppError::BadRequest( |
| 616 |
"Item was modified concurrently. Please try uploading again.".to_string(), |
| 617 |
)); |
| 618 |
} |
| 619 |
Ok(true) => {} |
| 620 |
} |
| 621 |
|
| 622 |
db::pending_uploads::remove_pending_upload(&db, user.id, &req.s3_key, "main").await?; |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
commit_upload( |
| 629 |
&db, |
| 630 |
scanning.scanner.as_ref(), |
| 631 |
CommitTarget::ItemImage(req.item_id), |
| 632 |
&req.s3_key, |
| 633 |
FileType::Cover, |
| 634 |
user.id, |
| 635 |
file_size_bytes, |
| 636 |
) |
| 637 |
.await?; |
| 638 |
|
| 639 |
|
| 640 |
if let Some(item) = db::items::get_item_by_id(&db, req.item_id).await? |
| 641 |
&& let Err(e) = db::projects::bump_cache_generation(&db, item.project_id).await |
| 642 |
{ |
| 643 |
tracing::warn!(project_id = %item.project_id, error = ?e, "failed to bump cache generation after image upload"); |
| 644 |
} |
| 645 |
|
| 646 |
tracing::info!( |
| 647 |
"Item image confirmed: item={}, key={}, size={}", |
| 648 |
req.item_id, |
| 649 |
req.s3_key, |
| 650 |
file_size_bytes |
| 651 |
); |
| 652 |
|
| 653 |
Ok(Json(ProjectImageConfirmResponse { |
| 654 |
success: true, |
| 655 |
image_url, |
| 656 |
})) |
| 657 |
} |
| 658 |
|