Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 72 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions book/src/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,17 @@ the flash tells you the stored name — nothing that references the
original changes. The gallery sorts newest-first, so the renamed upload
is the first tile.

**Import ZIP** brings in many images at once: send one `.zip` (up to
64 MB, 2000 files, 128 MB of images once unpacked) and every SVG, PNG,
JPEG or WebP in it goes through the same treatment as a single upload.
Folders are ignored — the library is flat, so `logos/sepe.svg` is stored
as `sepe.svg` — and so is anything that is not an image. Sending the
same archive again adds nothing: a file whose name and content are
already in the library is counted as already there. A file with a name
that exists but different content keeps both, as above. The page then
says how many were imported, how many were already there, and names the
ones that could not be imported, with the reason.

When editing a spec you can open a **modal picker** (search, browse, drag
and drop, or upload inline without leaving the form) to select a logo or
cover. A "Choose image" button auto-uploads on file select for a one-click
Expand Down
3 changes: 3 additions & 0 deletions crates/ruscker-admin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ libc = "0.2"
# Both already compile transitively (tower-http → async-compression).
flate2 = "1.1"
brotli = "8.0"
# Reading a .zip of images in the media library (batch import). Deflate
# only, through the flate2 already in the tree: no extra codecs.
zip = { version = "9.8", default-features = false, features = ["deflate-flate2"] }

# Errors / logging
anyhow = { workspace = true }
Expand Down
11 changes: 11 additions & 0 deletions crates/ruscker-admin/assets/i18n/en/landing.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,17 @@ admin-images-delete-confirm-inuse = This image is IN USE. Deleting it resets the
admin-images-search = Search images…
admin-images-type-all = All types
admin-images-no-match = No images match your search.
admin-images-import-zip = Import ZIP
admin-images-import-busy = Importing…
admin-images-import-hint = One .zip with many images (up to 64 MB). Folders are ignored; what is already in the library is not duplicated.
admin-images-import-summary = Import finished: { $imported } imported · { $already } already in the library · { $failed } not imported
admin-images-import-not-zip = The file sent is not a valid .zip.
admin-images-import-empty = The .zip has no images in it (SVG, PNG, JPEG or WebP).
admin-images-import-too-many = The .zip has too many files (2000 at most). Split it.
admin-images-import-too-large = The .zip is too large (up to 64 MB sent and 128 MB of unpacked images). Split it.
admin-images-import-skip-large = larger than 10 MB
admin-images-import-skip-unreadable = could not be read (damaged or password-protected)
admin-images-import-skip-save = could not be saved

# Admin credentials
admin-creds-title = Credential Management
Expand Down
11 changes: 11 additions & 0 deletions crates/ruscker-admin/assets/i18n/es/landing.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,17 @@ admin-images-delete-confirm-inuse = Esta imagen está EN USO. Al eliminarla, los
admin-images-search = Buscar imágenes…
admin-images-type-all = Todos los tipos
admin-images-no-match = Ninguna imagen coincide con la búsqueda.
admin-images-import-zip = Importar ZIP
admin-images-import-busy = Importando…
admin-images-import-hint = Un .zip con varias imágenes (hasta 64 MB). Las carpetas se ignoran; lo que ya está en la biblioteca no se duplica.
admin-images-import-summary = Importación terminada: { $imported } importadas · { $already } ya estaban en la biblioteca · { $failed } no importadas
admin-images-import-not-zip = El archivo enviado no es un .zip válido.
admin-images-import-empty = El .zip no contiene imágenes (SVG, PNG, JPEG o WebP).
admin-images-import-too-many = El .zip tiene demasiados archivos (máximo 2000). Divídalo.
admin-images-import-too-large = El .zip es demasiado grande (hasta 64 MB enviados y 128 MB de imágenes descomprimidas). Divídalo.
admin-images-import-skip-large = mayor que 10 MB
admin-images-import-skip-unreadable = no se pudo leer (dañado o con contraseña)
admin-images-import-skip-save = error al guardar

# Admin credentials
admin-creds-title = Gestión de Credenciales
Expand Down
11 changes: 11 additions & 0 deletions crates/ruscker-admin/assets/i18n/fr/landing.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,17 @@ admin-images-delete-confirm-inuse = Cette image est UTILISÉE. La supprimer rét
admin-images-search = Rechercher des images…
admin-images-type-all = Tous les types
admin-images-no-match = Aucune image ne correspond à la recherche.
admin-images-import-zip = Importer un ZIP
admin-images-import-busy = Importation…
admin-images-import-hint = Un .zip contenant plusieurs images (64 Mo au plus). Les dossiers sont ignorés ; ce qui est déjà dans la bibliothèque n’est pas dupliqué.
admin-images-import-summary = Importation terminée : { $imported } importées · { $already } déjà dans la bibliothèque · { $failed } non importées
admin-images-import-not-zip = Le fichier envoyé n’est pas un .zip valide.
admin-images-import-empty = Le .zip ne contient aucune image (SVG, PNG, JPEG ou WebP).
admin-images-import-too-many = Le .zip contient trop de fichiers (2000 au plus). Divisez-le.
admin-images-import-too-large = Le .zip est trop volumineux (64 Mo envoyés et 128 Mo d’images décompressées au plus). Divisez-le.
admin-images-import-skip-large = plus de 10 Mo
admin-images-import-skip-unreadable = illisible (endommagé ou protégé par mot de passe)
admin-images-import-skip-save = erreur d’enregistrement

# Admin credentials
admin-creds-title = Gestion des Identifiants
Expand Down
11 changes: 11 additions & 0 deletions crates/ruscker-admin/assets/i18n/pt/landing.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ admin-images-delete-confirm-inuse = Esta imagem está EM USO. Se deletar, os app
admin-images-search = Buscar imagens…
admin-images-type-all = Todos os tipos
admin-images-no-match = Nenhuma imagem corresponde à busca.
admin-images-import-zip = Importar ZIP
admin-images-import-busy = Importando…
admin-images-import-hint = Um .zip com várias imagens (até 64 MB). As pastas são ignoradas; o que já está na biblioteca não é duplicado.
admin-images-import-summary = Importação concluída: { $imported } importadas · { $already } já estavam na biblioteca · { $failed } não importadas
admin-images-import-not-zip = O arquivo enviado não é um .zip válido.
admin-images-import-empty = O .zip não contém imagens (SVG, PNG, JPEG ou WebP).
admin-images-import-too-many = O .zip tem arquivos demais (máximo de 2000). Divida em partes.
admin-images-import-too-large = O .zip é grande demais (até 64 MB enviados e 128 MB de imagens descompactadas). Divida em partes.
admin-images-import-skip-large = maior que 10 MB
admin-images-import-skip-unreadable = não foi possível ler (arquivo danificado ou com senha)
admin-images-import-skip-save = erro ao salvar

# Admin credentials
admin-creds-title = Gestão de Credenciais
Expand Down
27 changes: 27 additions & 0 deletions crates/ruscker-admin/src/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,33 @@ pub async fn process_upload_async(
.await?
}

/// At most one batch import at a time: an archive and everything unpacked
/// from it sit in memory while it is processed (up to
/// `media_zip::MAX_ZIP_BYTES` + `MAX_TOTAL_BYTES`), so two Editors
/// importing together wait in line instead of doubling that.
static ZIP_IMPORT_SLOT: LazyLock<Arc<Semaphore>> = LazyLock::new(|| Arc::new(Semaphore::new(1)));

/// Take the batch-import turn. Held by the route for the whole import and
/// released when dropped.
pub async fn zip_import_turn() -> Result<tokio::sync::OwnedSemaphorePermit> {
ZIP_IMPORT_SLOT
.clone()
.acquire_owned()
.await
.map_err(|_| anyhow!("batch import unavailable"))
}

/// Unpack a `.zip` of images under the same budget of blocking image jobs
/// as uploads and thumbnails: inflating is CPU work like decoding is.
pub async fn extract_zip_async(
zip_bytes: axum::body::Bytes,
) -> Result<std::result::Result<crate::media_zip::Extracted, crate::media_zip::ZipRefusal>> {
run_blocking_image_job(IMAGE_JOB_SLOTS.clone(), move || {
crate::media_zip::extract_images(&zip_bytes, MAX_UPLOAD_BYTES)
})
.await
}

/// Async migration-import entry point using the same resource budget.
pub async fn process_for_import_async(
raw_filename: String,
Expand Down
1 change: 1 addition & 0 deletions crates/ruscker-admin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod jobs;
pub mod leader;
pub mod logbuf;
pub mod markdown;
pub mod media_zip;
pub mod metrics_cache;
pub mod mfa;
pub mod oidc;
Expand Down
Loading