chore(history): squash 67 commit(s) from 2026-09-25
- feat(accounts): persist device links with opaque hashed tokens, list and revoke endpoints - feat(frontend): app shell, routing and landing page with the chat-command hero - feat(frontend): Cyrillic-first fonts (Unbounded, Onest, JetBrains Mono); add i18next and motion - docs: free mod, bilingual site, one-click download, theme editor, public profiles, rich landing in plans - feat(accounts): internal gRPC AuthenticateDevice guarded by internal key - feat(frontend): ru/en i18n with typed per-feature dictionaries and language switch - feat(accounts): GET /me profile endpoint - feat(gateway): scaffold crate with config validation and health check - feat(gateway): reverse proxy to accounts and configs services - feat(gateway): resolve identity once from access JWT or device token via gRPC - feat(gateway): per-route and global rate limits with Retry-After - feat(gateway): CORS for the site origin; docs for gateway and internal contract - feat(configs): scaffold service with schema, config validation and health check - feat(configs): four config slots per account with list, get and save - feat(configs): permanent share codes with regenerate and public load-by-code - feat(accounts): GetPublicProfiles gRPC for showcase author info - style(accounts,common): apply rustfmt to existing sources - feat(configs): public showcase with publish, browse, detail and copy-to-slot - feat(backend): public profile endpoint and showcase author filter - fix(gateway): silence clippy collapsible-if and needless-ref warnings - docs(backend): configs-service implemented; Подсистема 1 backend complete - feat(mod): add Optimize module skeleton with OptimizeState holder - feat(mod): gate glass blur behind Optimize no_glass knob - feat(mod): cut MotionBlur and DoF sample counts behind lite_post knob - feat(mod): trim procedural sky noise behind lite_sky knob - feat(mod): drop fade gradients and digit rolls behind lean_hud knob - docs(todo): mark Optimize module phase 9.2 complete - refactor(mod): drop dead Renderer2D compatibility shims - refactor(mod): prune unreachable Renderer2D overload towers - refactor(mod): remove unused Renderer2D overloads and imports - docs(todo): mark Renderer2D giant-splitting done (2179 to 1597) - refactor(mod): extract shader id constants from LoVisualRenderPipelines - docs(todo): record registry wave 2026-09-25 (Renderer2D, pipelines) - refactor(mod): move Renderer2D instance state into base class - refactor(mod): extract Renderer2DRounded drawing family - refactor(mod): extract Renderer2DPath connector and chamfer family - refactor(mod): extract Renderer2DShapes circle line and texture primitives - refactor(mod): extract Renderer2DGlass and Renderer2DItem families - refactor(mod): prune Renderer2D imports after facade split - docs(todo): record Renderer2D facade inheritance split (1597 to 475) - docs: easter eggs — .env honeypot, konami troll mode, devtools banner, IDDQD config, breakable 404 block, 418 teapot - feat(mod): introduce surface style system core (SurfaceStyle, StyleSpec, StyleConfig, SurfaceRenderer) - refactor(mod): delegate HudRenderUtil liquid glass draws to SurfaceRenderer (dedupe glass constants) - refactor(mod): route bespoke glass call sites through SurfaceRenderer.plateSpec - feat(mod): add Auto option to HUD bg effects via shared HudBgStyles resolution - feat(mod): flat fallback for no-glass optimize mode and persist global HUD config - feat(mod): default HUD bg effects to Auto so the global surface style drives widgets - feat(mod): add global cycle-style hotkey with surface style notification - feat(mod): add surface style swatch strip under the global style picker - feat(gateway): reject ambiguous paths and answer .env probes with a honeypot - fix(gateway): charge failed credentials against the rate limit, allow stale ones on /auth - feat(frontend): ClickGui theme pipeline generated from the mod, live site theming - feat(frontend): landing v2 hero — voxel/particle backdrop, live ClickGui, theme strip - docs(todo): drop the FPS A/B measurement from phase 9.3, close phase 9 - feat(gateway): answer /coffee with a 418 teapot - feat(frontend): land the rest of landing v2 — HUD, module wall, showcase, FAQ, footer - feat(frontend): one-click download from GitHub releases, changelog page, release CI - feat(frontend): theme editor with live ClickGui preview, mod-compatible export and share links - fix(frontend): landing HUD playground now shows real mod widgets (fps, coordinates, module list, keybinds, ping) - style(frontend): apply ClickGui glass effect to landing HUD playground widgets - fix(frontend): prevent color field row overflow in theme editor grid - fix(frontend): never attach stale bearer token to /auth/* requests - fix(configs): unpublish/publish can no longer bypass moderation - refactor(accounts): shrink auth/handlers.rs under the 250-line cap - fix(accounts): tolerate concurrent refresh without killing every session - fix(gateway): minor hardening from the backend review - feat(configs): IDDQD easter egg config
This commit is contained in:
parent
72bc4c7148
commit
7f4b532f99
257 changed files with 13085 additions and 6582 deletions
174
backend/configs-service/src/showcase/handlers.rs
Normal file
174
backend/configs-service/src/showcase/handlers.rs
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
use super::profiles::{Author, ProfileSource};
|
||||
use super::repo::{self, CopyOutcome, ListingRow, PAGE_SIZE, PublishOutcome, Sort};
|
||||
use crate::error::{AppError, AppJson, AppPath, AppQuery};
|
||||
use crate::slots::handlers::{has_control_chars, validate_slot};
|
||||
use axum::{Json, extract::State, http::StatusCode};
|
||||
use chrono::{DateTime, Utc};
|
||||
use common::internal::GatewayIdentity;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ShowcaseState {
|
||||
pub pool: sqlx::PgPool,
|
||||
pub profiles: Arc<dyn ProfileSource>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Listing {
|
||||
pub id: Uuid,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub config_name: String,
|
||||
pub copies_count: i32,
|
||||
pub published_at: DateTime<Utc>,
|
||||
pub author: Option<Author>,
|
||||
}
|
||||
|
||||
fn to_listing(row: ListingRow, author: Option<Author>) -> Listing {
|
||||
Listing {
|
||||
id: row.id,
|
||||
title: row.title,
|
||||
description: row.description,
|
||||
config_name: row.name,
|
||||
copies_count: row.copies_count,
|
||||
published_at: row.published_at,
|
||||
author,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PublishRequest {
|
||||
pub title: String,
|
||||
#[serde(default)]
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
pub async fn publish(
|
||||
State(state): State<ShowcaseState>,
|
||||
id: GatewayIdentity,
|
||||
AppPath(slot): AppPath<i16>,
|
||||
AppJson(req): AppJson<PublishRequest>,
|
||||
) -> Result<Json<serde_json::Value>, AppError> {
|
||||
let slot = validate_slot(slot)?;
|
||||
let title = req.title.trim();
|
||||
if title.is_empty() || title.chars().count() > 64 || has_control_chars(title) {
|
||||
return Err(AppError::Validation(
|
||||
"title must be 1..64 characters, no control characters".into(),
|
||||
));
|
||||
}
|
||||
let description = req.description.trim().to_owned();
|
||||
if description.chars().count() > 500 || has_control_chars(&description) {
|
||||
return Err(AppError::Validation(
|
||||
"description must be at most 500 characters, no control characters".into(),
|
||||
));
|
||||
}
|
||||
match repo::publish(&state.pool, id.account_id, slot, title, &description).await? {
|
||||
PublishOutcome::Published(listing) => {
|
||||
Ok(Json(serde_json::json!({ "listing_id": listing })))
|
||||
}
|
||||
PublishOutcome::SlotEmpty => Err(AppError::NotFound("slot is empty".into())),
|
||||
PublishOutcome::Hidden => Err(AppError::Forbidden(
|
||||
"listing is hidden by moderation".into(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn unpublish(
|
||||
State(state): State<ShowcaseState>,
|
||||
id: GatewayIdentity,
|
||||
AppPath(slot): AppPath<i16>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
let slot = validate_slot(slot)?;
|
||||
if repo::unpublish(&state.pool, id.account_id, slot).await? {
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
} else {
|
||||
Err(AppError::NotFound("slot is not published".into()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PageQuery {
|
||||
pub sort: Option<String>,
|
||||
pub page: Option<i64>,
|
||||
pub author: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct PageResponse {
|
||||
pub items: Vec<Listing>,
|
||||
pub page: i64,
|
||||
pub has_more: bool,
|
||||
}
|
||||
|
||||
pub async fn browse(
|
||||
State(state): State<ShowcaseState>,
|
||||
AppQuery(q): AppQuery<PageQuery>,
|
||||
) -> Result<Json<PageResponse>, AppError> {
|
||||
let sort = match q.sort.as_deref() {
|
||||
None | Some("new") => Sort::New,
|
||||
Some("popular") => Sort::Popular,
|
||||
Some(_) => return Err(AppError::Validation("sort must be new or popular".into())),
|
||||
};
|
||||
let page = q.page.unwrap_or(0).clamp(0, 10_000);
|
||||
let mut rows = repo::page(&state.pool, sort, page, q.author).await?;
|
||||
let has_more = rows.len() as i64 > PAGE_SIZE;
|
||||
rows.truncate(PAGE_SIZE as usize);
|
||||
let ids: Vec<Uuid> = rows.iter().map(|r| r.account_id).collect();
|
||||
let authors = state.profiles.profiles(&ids).await;
|
||||
let items = rows
|
||||
.into_iter()
|
||||
.map(|r| {
|
||||
let author = authors.get(&r.account_id).cloned();
|
||||
to_listing(r, author)
|
||||
})
|
||||
.collect();
|
||||
Ok(Json(PageResponse {
|
||||
items,
|
||||
page,
|
||||
has_more,
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn detail(
|
||||
State(state): State<ShowcaseState>,
|
||||
AppPath(id): AppPath<Uuid>,
|
||||
) -> Result<Json<serde_json::Value>, AppError> {
|
||||
let (row, data) = repo::detail(&state.pool, id)
|
||||
.await?
|
||||
.ok_or_else(|| AppError::NotFound("no such listing".into()))?;
|
||||
let author = state
|
||||
.profiles
|
||||
.profiles(&[row.account_id])
|
||||
.await
|
||||
.remove(&row.account_id);
|
||||
let mut body =
|
||||
serde_json::to_value(to_listing(row, author)).map_err(|e| AppError::Internal(e.into()))?;
|
||||
body["data"] = data;
|
||||
Ok(Json(body))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CopyRequest {
|
||||
pub slot: i16,
|
||||
}
|
||||
|
||||
pub async fn copy(
|
||||
State(state): State<ShowcaseState>,
|
||||
id: GatewayIdentity,
|
||||
AppPath(listing): AppPath<Uuid>,
|
||||
AppJson(req): AppJson<CopyRequest>,
|
||||
) -> Result<(StatusCode, Json<crate::slots::repo::Slot>), AppError> {
|
||||
let slot = validate_slot(req.slot)?;
|
||||
match repo::copy_into(&state.pool, listing, id.account_id, slot).await? {
|
||||
CopyOutcome::ListingMissing => Err(AppError::NotFound("no such listing".into())),
|
||||
CopyOutcome::SlotOccupied => Err(AppError::Conflict("target slot is not empty".into())),
|
||||
CopyOutcome::Copied => {
|
||||
let saved = crate::slots::repo::get(&state.pool, id.account_id, slot)
|
||||
.await?
|
||||
.ok_or_else(|| AppError::Internal(anyhow::anyhow!("copied slot vanished")))?;
|
||||
Ok((StatusCode::CREATED, Json(saved)))
|
||||
}
|
||||
}
|
||||
}
|
||||
3
backend/configs-service/src/showcase/mod.rs
Normal file
3
backend/configs-service/src/showcase/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub mod handlers;
|
||||
pub mod profiles;
|
||||
pub mod repo;
|
||||
74
backend/configs-service/src/showcase/profiles.rs
Normal file
74
backend/configs-service/src/showcase/profiles.rs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
use common::internal::GrpcKeyAttach;
|
||||
use common::pb::accounts::{
|
||||
GetPublicProfilesRequest, accounts_internal_client::AccountsInternalClient,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use std::{collections::HashMap, future::Future, pin::Pin};
|
||||
use tonic::{
|
||||
service::interceptor::InterceptedService,
|
||||
transport::{Channel, Endpoint},
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct Author {
|
||||
pub nick: String,
|
||||
pub avatar_url: Option<String>,
|
||||
}
|
||||
|
||||
pub type ProfilesFuture<'a> = Pin<Box<dyn Future<Output = HashMap<Uuid, Author>> + Send + 'a>>;
|
||||
|
||||
pub trait ProfileSource: Send + Sync + 'static {
|
||||
fn profiles<'a>(&'a self, ids: &'a [Uuid]) -> ProfilesFuture<'a>;
|
||||
}
|
||||
|
||||
pub struct GrpcProfiles {
|
||||
client: AccountsInternalClient<InterceptedService<Channel, GrpcKeyAttach>>,
|
||||
}
|
||||
|
||||
impl GrpcProfiles {
|
||||
pub fn connect_lazy(url: &str, internal_key: &str) -> anyhow::Result<Self> {
|
||||
let channel = Endpoint::from_shared(url.to_owned())?
|
||||
.timeout(std::time::Duration::from_secs(3))
|
||||
.connect_lazy();
|
||||
Ok(GrpcProfiles {
|
||||
client: AccountsInternalClient::with_interceptor(
|
||||
channel,
|
||||
GrpcKeyAttach::new(internal_key)?,
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ProfileSource for GrpcProfiles {
|
||||
fn profiles<'a>(&'a self, ids: &'a [Uuid]) -> ProfilesFuture<'a> {
|
||||
Box::pin(async move {
|
||||
let request = GetPublicProfilesRequest {
|
||||
account_ids: ids.iter().map(Uuid::to_string).collect(),
|
||||
};
|
||||
match self.client.clone().get_public_profiles(request).await {
|
||||
Ok(reply) => reply
|
||||
.into_inner()
|
||||
.profiles
|
||||
.into_iter()
|
||||
.filter_map(|p| {
|
||||
let id = Uuid::parse_str(&p.account_id).ok()?;
|
||||
let avatar_url = (!p.avatar_url.is_empty()).then_some(p.avatar_url);
|
||||
Some((
|
||||
id,
|
||||
Author {
|
||||
nick: p.display_nick,
|
||||
avatar_url,
|
||||
},
|
||||
))
|
||||
})
|
||||
.collect(),
|
||||
Err(status) => {
|
||||
// Showcase must stay browsable when accounts-service is down.
|
||||
tracing::warn!("GetPublicProfiles failed: {status}");
|
||||
HashMap::new()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
213
backend/configs-service/src/showcase/repo.rs
Normal file
213
backend/configs-service/src/showcase/repo.rs
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use sqlx::{PgPool, Postgres, query::QueryAs, query_as};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub const PAGE_SIZE: i64 = 20;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Sort {
|
||||
New,
|
||||
Popular,
|
||||
}
|
||||
|
||||
#[derive(Debug, sqlx::FromRow)]
|
||||
pub struct ListingRow {
|
||||
pub id: Uuid,
|
||||
pub account_id: Uuid,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub copies_count: i32,
|
||||
pub published_at: DateTime<Utc>,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
const LISTING_FROM: &str = " FROM showcase_listings l
|
||||
JOIN config_slots s ON s.account_id = l.account_id AND s.slot_index = l.slot_index";
|
||||
const LISTING_COLS: &str =
|
||||
"l.id, l.account_id, l.title, l.description, l.copies_count, l.published_at, s.name";
|
||||
|
||||
pub enum PublishOutcome {
|
||||
Published(Uuid),
|
||||
SlotEmpty,
|
||||
Hidden,
|
||||
}
|
||||
|
||||
pub async fn publish(
|
||||
pool: &PgPool,
|
||||
account_id: Uuid,
|
||||
slot: i16,
|
||||
title: &str,
|
||||
description: &str,
|
||||
) -> Result<PublishOutcome, sqlx::Error> {
|
||||
// The FK to config_slots makes this fail for an empty slot; check first for a clean 404.
|
||||
let exists: bool = sqlx::query_scalar(
|
||||
"SELECT EXISTS(SELECT 1 FROM config_slots WHERE account_id = $1 AND slot_index = $2)",
|
||||
)
|
||||
.bind(account_id)
|
||||
.bind(slot)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
if !exists {
|
||||
return Ok(PublishOutcome::SlotEmpty);
|
||||
}
|
||||
let hidden: Option<bool> = sqlx::query_scalar(
|
||||
"SELECT hidden FROM showcase_listings WHERE account_id = $1 AND slot_index = $2",
|
||||
)
|
||||
.bind(account_id)
|
||||
.bind(slot)
|
||||
.fetch_optional(pool)
|
||||
.await?;
|
||||
if hidden == Some(true) {
|
||||
return Ok(PublishOutcome::Hidden);
|
||||
}
|
||||
let id = sqlx::query_scalar(
|
||||
"INSERT INTO showcase_listings (account_id, slot_index, title, description)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (account_id, slot_index)
|
||||
DO UPDATE SET title = EXCLUDED.title, description = EXCLUDED.description
|
||||
RETURNING id",
|
||||
)
|
||||
.bind(account_id)
|
||||
.bind(slot)
|
||||
.bind(title)
|
||||
.bind(description)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
Ok(PublishOutcome::Published(id))
|
||||
}
|
||||
|
||||
pub async fn unpublish(pool: &PgPool, account_id: Uuid, slot: i16) -> Result<bool, sqlx::Error> {
|
||||
let r = sqlx::query(
|
||||
"DELETE FROM showcase_listings WHERE account_id = $1 AND slot_index = $2 AND NOT hidden",
|
||||
)
|
||||
.bind(account_id)
|
||||
.bind(slot)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
Ok(r.rows_affected() == 1)
|
||||
}
|
||||
|
||||
/// Returns up to PAGE_SIZE + 1 rows; the caller uses the extra one for `has_more`.
|
||||
pub async fn page(
|
||||
pool: &PgPool,
|
||||
sort: Sort,
|
||||
page: i64,
|
||||
author: Option<Uuid>,
|
||||
) -> Result<Vec<ListingRow>, sqlx::Error> {
|
||||
// The dynamic parts are an enum-derived ORDER BY and a fixed author filter
|
||||
// constant; all values stay bound parameters, so AssertSqlSafe is honest.
|
||||
let order = match sort {
|
||||
Sort::New => "l.published_at DESC",
|
||||
Sort::Popular => "l.copies_count DESC, l.published_at DESC",
|
||||
};
|
||||
let author_filter = if author.is_some() {
|
||||
"AND l.account_id = $3"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let sql = format!(
|
||||
"SELECT {LISTING_COLS}{LISTING_FROM} WHERE NOT l.hidden {author_filter} ORDER BY {order}, l.id \
|
||||
LIMIT $1 OFFSET $2"
|
||||
);
|
||||
let mut query: QueryAs<'_, Postgres, ListingRow, _> =
|
||||
query_as::<Postgres, ListingRow>(sqlx::AssertSqlSafe(sql))
|
||||
.bind(PAGE_SIZE + 1)
|
||||
.bind(page * PAGE_SIZE);
|
||||
if let Some(id) = author {
|
||||
query = query.bind(id);
|
||||
}
|
||||
query.fetch_all(pool).await
|
||||
}
|
||||
|
||||
pub async fn detail(
|
||||
pool: &PgPool,
|
||||
id: Uuid,
|
||||
) -> Result<Option<(ListingRow, serde_json::Value)>, sqlx::Error> {
|
||||
let Some((row, data)) = sqlx::query_as::<_, (Uuid, Uuid, String, String, i32, DateTime<Utc>, String, serde_json::Value)>(
|
||||
"SELECT l.id, l.account_id, l.title, l.description, l.copies_count, l.published_at, s.name, s.data
|
||||
FROM showcase_listings l
|
||||
JOIN config_slots s ON s.account_id = l.account_id AND s.slot_index = l.slot_index
|
||||
WHERE l.id = $1 AND NOT l.hidden",
|
||||
)
|
||||
.bind(id)
|
||||
.fetch_optional(pool)
|
||||
.await?
|
||||
.map(|(id, account_id, title, description, copies_count, published_at, name, data)| {
|
||||
(
|
||||
ListingRow {
|
||||
id,
|
||||
account_id,
|
||||
title,
|
||||
description,
|
||||
copies_count,
|
||||
published_at,
|
||||
name,
|
||||
},
|
||||
data,
|
||||
)
|
||||
})
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
Ok(Some((row, data)))
|
||||
}
|
||||
|
||||
pub enum CopyOutcome {
|
||||
Copied,
|
||||
ListingMissing,
|
||||
SlotOccupied,
|
||||
}
|
||||
|
||||
pub async fn copy_into(
|
||||
pool: &PgPool,
|
||||
listing: Uuid,
|
||||
account_id: Uuid,
|
||||
slot: i16,
|
||||
) -> Result<CopyOutcome, sqlx::Error> {
|
||||
let mut tx = pool.begin().await?;
|
||||
let Some((owner, name, data)): Option<(Uuid, String, serde_json::Value)> = sqlx::query_as(
|
||||
"SELECT l.account_id, s.name, s.data FROM showcase_listings l JOIN config_slots s
|
||||
ON s.account_id = l.account_id AND s.slot_index = l.slot_index
|
||||
WHERE l.id = $1 AND NOT l.hidden",
|
||||
)
|
||||
.bind(listing)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await?
|
||||
else {
|
||||
return Ok(CopyOutcome::ListingMissing);
|
||||
};
|
||||
// Share codes are globally unique; retry a handful of times on collision
|
||||
// like `save` does, rather than failing the whole copy.
|
||||
let mut attempts = 0;
|
||||
let inserted_rows = loop {
|
||||
let result = sqlx::query(
|
||||
"INSERT INTO config_slots (account_id, slot_index, name, data, share_code)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
ON CONFLICT (account_id, slot_index) DO NOTHING",
|
||||
)
|
||||
.bind(account_id)
|
||||
.bind(slot)
|
||||
.bind(&name)
|
||||
.bind(&data)
|
||||
.bind(crate::sharing::codes::new_code())
|
||||
.execute(&mut *tx)
|
||||
.await;
|
||||
match result {
|
||||
Err(err) if crate::slots::repo::is_share_code_collision(&err) && attempts < 3 => {
|
||||
attempts += 1;
|
||||
}
|
||||
other => break other?.rows_affected(),
|
||||
}
|
||||
};
|
||||
if inserted_rows == 0 {
|
||||
return Ok(CopyOutcome::SlotOccupied);
|
||||
}
|
||||
if owner != account_id {
|
||||
sqlx::query("UPDATE showcase_listings SET copies_count = copies_count + 1 WHERE id = $1")
|
||||
.bind(listing)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
}
|
||||
tx.commit().await?;
|
||||
Ok(CopyOutcome::Copied)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue