Commit Graph

70 Commits

Author SHA1 Message Date
CalamitousFelicitousness 8291365955 refactor(model): simplify probe cache handling
json_helpers does its own error handling and file locking, so the
try/except wrappers, threading locks and isfile checks were dead
weight; probe cache file paths are now defined in paths.py.
2026-07-11 20:26:12 +01:00
CalamitousFelicitousness c54c0535c0 fix(civitai): accept civitai.red urls in header peek
The .red mirror rewrites downloadUrl to its own host; normalize to
civitai.com so the ssrf guard, cache hash and fetch host agree.
2026-07-11 20:26:12 +01:00
CalamitousFelicitousness 055388aa70 feat(civitai): attach model probe analysis to header peeks
peek-header now returns the full probe (architecture fingerprint,
dtypes, quant scheme) alongside the metadata block, and caches the
response persistently by civitai file id; file content per id is
immutable, so cached probes skip the ranged fetch entirely.
2026-07-11 06:40:07 +01:00
CalamitousFelicitousness e0ed573d66 feat(civitai): add ranged safetensors header peek endpoint
The API carries no field distinguishing dual-transformer expert files;
conversion tools embed it in the header __metadata__. peek-header
range-fetches the JSON header and returns the metadata block without
downloading the file. Restricted to civitai.com urls.
2026-07-11 06:40:07 +01:00
Vladimir Mandic 8ce3313f9a improve log viewer
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-07-10 13:14:27 +02:00
CalamitousFelicitousness d087c3e687 feat(civitai): route text encoder files to te_dir
Versions bundle companion files typed by the file, not the model;
'Text Encoder' had no TYPE_MAP entry so companions landed in the
checkpoint folder where the loader never scans.
2026-07-10 02:17:33 +01:00
CalamitousFelicitousness 24683dc608 feat(civitai): parse gguf quantType in file metadata
GGUF variants are distinguished by quantType, not fp; the model
endpoint carries it in file metadata.
2026-07-10 02:09:14 +01:00
CalamitousFelicitousness e615b6e22b feat(civitai): sweep abandoned download partials at startup
Interrupted downloads leave url-hash .tmp resume files that nothing
cleans up; the queue that knows about them is in-memory only.

- iter_type_roots lists every folder downloads resolve into
- partials older than 7 days by mtime are deleted when the download
  manager starts; active partials always have a fresh mtime
2026-07-10 01:54:27 +01:00
CalamitousFelicitousness ef6030b871 feat(civitai): expose file variant metadata and scan results
Multi-variant versions serve one canonical filename per file; the
precision, size class, format, and scan status that distinguish them
were dropped at the model layer.

- CivitFile gains metadata (format, size, fp), pickle and virus scan
  results, and scannedAt
2026-07-10 01:54:27 +01:00
CalamitousFelicitousness 9b18aad1c1 feat(civitai): record search filters in history entries
History entries stored only the query or tag term, so restoring a
search dropped every filter, and filter-only browsing was never
recorded at all.

- SearchHistory.add takes an optional params dict stored on the entry
- get_search records non-default filters: type, sort, period, base
  models, nsfw, username, favorites
- filter-only searches are recorded as 'filter' entries labeled with
  the filter values
2026-07-10 00:50:01 +01:00
CalamitousFelicitousness 9f9a350e53 fix(civitai): restart download when server ignores range request
A 200 reply to a resumed download carries the full file, not the
remainder; appending it to the partial produced a corrupt file that
passed the size check and only failed at hash verification. Truncate
the temp file and restart from byte 0 when a Range request comes back
as 200 instead of 206.
2026-07-10 00:05:37 +01:00
CalamitousFelicitousness a274f57aab fix(civitai): tolerate null availability, expose early access fields
The /model-versions endpoint now serializes availability as null, which
failed str validation and turned every version lookup into a 404. Coerce
null to the default like the creator username validator already does.

Pass through earlyAccessEndsAt and earlyAccessConfig so clients can see
that a download requires a Buzz purchase before requesting the file.
2026-07-09 23:49:37 +01:00
CalamitousFelicitousness 4bdda6d91a feat(civitai): route DiT checkpoint downloads to the UNET folder
CivitAI has no model type for a standalone transformer, so DiT finetunes
are published as 'Checkpoint' like full models and all landed in
Stable-diffusion, where the single-file transformer loader never looks.
Route Checkpoint downloads to UNET unless the base model is a known full
checkpoint (SD1.x/2.x, SDXL and its Pony/Illustrious/NoobAI derivatives,
SVD, Kolors, Stable Cascade). Downloads with no base_model, or a
civitai_save_type_folders override, keep the previous behavior.
2026-07-03 21:07:46 +01:00
CalamitousFelicitousness 3c0ca8f483 fix(civitai): validate downloads by content-length and content-type
An absolute 1024-byte floor rejected valid complete downloads, since
some safetensors are legitimately tiny (a lone projector-diff tensor is
~160 bytes). Verify completeness against the declared Content-Length
instead, accepting any size, and keep the floor only as a fallback when
it is missing. Reject text/* responses up front so an HTML error or
login page served with HTTP 200 is never saved as a model file.
2026-07-03 21:07:46 +01:00
CalamitousFelicitousness 0eb7d7032b feat(civitai): filter search results by nsfw level
The nsfw boolean leaks Mature+ content (nsfw=false returned levels up to
XXX) and /models rejects server-side level filtering, so filter search
results on each model's aggregate nsfwLevel: nsfw off keeps SFW (None +
Soft), nsfw on keeps everything.
2026-06-28 02:43:03 +01:00
CalamitousFelicitousness 236d96ef06 fix(civitai): tolerate null creator username in search results
Civitai returns a null username for deleted or anonymous creators. The
field default only applies when the key is absent, so an explicit null
failed str validation and rejected the entire CivitSearchResponse,
dropping every model on that page.

Coerce null or empty usernames to the default in a pre-validator so one
bad creator no longer empties the whole search result.
2026-06-28 02:39:06 +01:00
CalamitousFelicitousness af11b119ea feat(civitai): use /enums for option discovery, parse new model fields
Replace base-model and model-type discovery that scraped ZodError
responses with the documented GET /api/v1/enums endpoint. The /images
baseModels probe (unreliable since /models stopped validating it) is now
a fallback only; sort and period still come from the /models 400 response
since /enums does not carry them.

Add the model fields the API returns but CivitModel was dropping:
supportsGeneration, mode, poi, minor, sfwOnly, userId, cosmetic. The
poi/minor/sfwOnly flags serialize as null on some endpoints, so coerce
null to False to keep parsing resilient.
2026-06-28 01:25:40 +01:00
Vladimir Mandic 4b2f38ab7f complete refactor javascript to typescript and reorg frontend files and folders
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-05-20 18:08:10 +02:00
Vladimir Mandic f67562b912 - all guidance values set to -1 to enable using model defaults
- log default values used if not overriden by user
- rename inconsistent guidance variables:

p.cfg_scale
p.image_cfg_scale -> p.cfg_image
p.diffusers_guidance_rescale -> p.cfg_rescale
p.pag_scale -> p.cfg_true
p.pag_adaptive -> p.cfg_adaptive

Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-05-16 11:06:23 +02:00
Vladimir Mandic feeafc6286 strict ruff without exclude
Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-05-11 08:36:49 +02:00
Vladimir Mandic c8d6fd5cf8 Revert "much stricter ruff linting"
This reverts commit 310dbf1574.
2026-05-11 08:13:57 +02:00
Vladimir Mandic 310dbf1574 much stricter ruff linting
Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-05-11 07:15:37 +02:00
CalamitousFelicitousness c32e90d08b fix(civitai): backfill gate and end-to-end thumb propagation
Gate finds the on-disk preview via resolve_preview_file and a
non-empty UserComment check so previews lacking embedded params enter
the worker. embed_preview_parameters writes via temp + os.replace,
converts RGBA to RGB before JPEG save, removes unreadable sources, and
invalidates any co-located .thumb.jpg. get_exif decodes EXIF
UserComment so regenerated thumbs propagate the source's params. For
.mp4 and .webm previews, embed targets the .thumb.jpg frame extracted
by save_video_frame instead of the unembeddable video file.
backfill_preview_parameters and resolve_preview_file share
find_ui_preview_file, which mirrors find_preview's iteration order so
backfill embeds into the file the modernUI actually surfaces (handles
LoRAs with multiple coexisting variants like .jpg + .jpeg).
civitai_meta_to_parameters drops generator-specific noise keys (comfy,
comfyui, workflow, extraMetadata) and applies a 512-char cap on
pass-through values to keep the embedded chunk compact.
2026-05-10 06:12:13 +01:00
CalamitousFelicitousness ba1080fea2 feat(civitai): backfill preview meta on rescan
When download_civit_preview short-circuits at 304 (file exists), the
rescan path now falls back to backfill_preview_parameters: checks
whether the file already carries an embedded parameters chunk and, if
not, embeds img.meta in place. Existing libraries get retroactive
metadata via the existing "Search metadata" rescan, no model
re-download required.
2026-05-10 03:30:10 +01:00
CalamitousFelicitousness 4c2022dfdf feat(civitai): embed preview meta into downloaded images
Civitai's CDN strips PNG tEXt/EXIF chunks during delivery, leaving the
modernUI Preview metadata tab empty for downloaded networks. Format the
version API's images[].meta into sdnext's standard parameters channel
(PNG tEXt / JPEG-WEBP EXIF UserComment) so read_info_from_image picks
it up through the existing path. Embedding is wrapped in try/except
and never blocks the download.
2026-05-10 03:20:03 +01:00
awsr 09f5fc6e03 Update concurrent.futures imports
Python 3.14 adds `concurrent.interpreters` and we don't need to import that here.
2026-04-23 16:49:31 -07:00
Vladimir Mandic f1304b3ba0 Merge pull request #4762 from awsr/hashcache
Update hash cache
2026-04-15 09:42:35 +02:00
Vladimir Mandic c7521f4da4 Merge pull request #4756 from vladmandic/feat/civitai-base-models
feat(civitai): enrich base-model discovery with github constants
2026-04-15 09:34:04 +02:00
CalamitousFelicitousness ac78d904b3 refactor(civitai): split base-model helpers into basemodels_civitai
Addresses #4756 review: keeps client_civitai focused on the HTTP client
surface. Behavior unchanged.
2026-04-14 23:26:01 +01:00
CalamitousFelicitousness 5d9b8d2e34 feat(civitai): enrich base-model discovery with github constants
CivitAI removed enum validation from /api/v1/models?baseModels=X (now
returns 200 with empty items on unknown values), which left the
base-model filter dropdown empty. Fix in two parts.

1. Point the base_models discovery probe at /images instead of /models.
   /images still returns a ZodError with the full enum list (82 names
   at time of writing). The existing parser handles the shape unchanged.

2. Also fetch civitai/civitai's base-model.constants.ts from GitHub and
   merge per-name metadata (group, ecosystem, engine, family, hidden)
   into a new base_models_info field on the response. The live probe
   remains authoritative for which names exist; GitHub provides the
   metadata and doubles as a fallback name list if the probe comes back
   empty.

Backward compatible: the existing base_models list keeps the same
shape. Clients that want grouped dropdowns, hidden-flag filtering, or
image/video separation can consume base_models_info instead.

The GitHub fetch has a separate 6h cache since these constants change
much less often than the probes it sits alongside.
2026-04-14 23:26:01 +01:00
awsr 03486deca6 Support upcoming site frontend split
API endpoints are supposed to remain the same, so those don't need updating.
2026-04-14 12:46:12 -07:00
awsr 1647be96de Minor function renaming
Cache no longer requires initialization.
2026-04-13 23:44:05 -07:00
awsr e4aaed9eee Improve init & data handling. Improve typing.
Minor usage change. Instead of setting the hash info directly, call `add_hash` to ensure proper data structure.
2026-04-13 23:44:05 -07:00
CalamitousFelicitousness a9a33b2bfa fix(civitai): probe /images for baseModels enum discovery
Civitai stopped validating baseModels on /api/v1/models (returns 200 with
empty items on unknown values), which left API clients without a way to
discover the values. Right now /images still does, I will get a separate
PR to put something more robust in place.
2026-04-13 22:46:52 +01:00
vladmandic 15c8b2b0c4 fixes from check-api
Signed-off-by: vladmandic <mandic00@live.com>
2026-04-12 18:54:22 +02:00
awsr ff247d8fd2 Merge branch 'dev' into RUF013 2026-03-24 07:12:51 -07:00
awsr 53598d40ab RUF013 update 2026-03-23 22:59:32 -07:00
vladmandic afe3786f5f add unet/dir to networks
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-22 11:09:45 +01:00
vladmandic 760b0121bc update register_api
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-20 08:07:05 +01:00
CalamitousFelicitousness 202862fb64 feat(civitai): wire subfolder resolution and sidecar metadata into download
Add base_model, model_id, version_id params to download_civit_model.
Call resolve_save_path when subfolder sorting is enabled. Pass model_id
and version_id to DownloadManager.enqueue so _fetch_sidecar downloads
metadata JSON and preview images alongside the model file. Extract
version_id from the download URL as fallback when not provided.
2026-03-20 04:33:20 +00:00
CalamitousFelicitousness 91d21eefb6 feat(civitai): allow tag-only and sort-only browsing
Relax the empty-query guard so search works with tag, sort, or period
alone. Skip exact-match name filtering when no keyword is provided so
browse results return the full API response.
2026-03-20 04:33:12 +00:00
vladmandic 4e1c1a6844 add secrets manager
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-17 13:56:55 +01:00
vladmandic ea1abfe2ce merge: modules/civitai 2026-03-17 11:07:51 +01:00
vladmandic 09e41b65d3 rename video_helper
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-13 12:22:53 +01:00
vladmandic 756b4599be merge: modules/caption
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-13 12:22:46 +01:00
vladmandic 3586ae90bc merge: modules/civitai/__init__.py 2026-03-12 14:16:50 +01:00
Vladimir Mandic f78f0eb4a5 refactor imports 2026-02-19 15:28:24 +01:00
Vladimir Mandic d65a2d1ebc ruff lint 2026-02-19 11:13:44 +01:00
Vladimir Mandic e5c494f999 cleanup logger 2026-02-19 11:09:13 +01:00
Vladimir Mandic a3074baf8b unified logger 2026-02-19 09:46:42 +01:00