ui : make resuming a paused download work

Re-posting the tag of a paused download hit the router's "already
exists" check, because a paused download parks its entry as DOWNLOADED
until the next reload: a download entry that is not running is now
replaced and resumed. The UI keeps the paused row when the request still
fails, instead of dropping it and looking finished.

Assisted-by: pi
This commit is contained in:
Aleksander Grygier
2026-10-02 11:59:25 +02:00
parent 38c2c9cbc2
commit ae433124b3
2 changed files with 26 additions and 3 deletions
+16 -2
View File
@@ -2158,9 +2158,23 @@ void server_models_routes::init_routes() {
throw std::invalid_argument("model validation failed, unable to download");
}
// reject if model already exists
// reject if model already exists, but a paused download parks its entry as
// DOWNLOADED until the next reload: re-posting that tag is how a resume is
// asked for, so a download that is not running is replaced instead
if (models.has_model(name)) {
throw std::invalid_argument("model '" + name + "' already exists");
auto existing = models.get_meta(name);
// the entry can disappear here: get_meta() triggers the reload that
// erases a finished download, which is the resume case as well
const bool resumable = existing.has_value() && !existing->is_running() &&
(existing->status == SERVER_MODEL_STATUS_DOWNLOADED ||
existing->status == SERVER_MODEL_STATUS_DOWNLOADING);
if (existing.has_value() && !resumable) {
throw std::invalid_argument("model '" + name + "' already exists");
}
SRV_INF("resuming download for model '%s'\n", name.c_str());
}
// then, proceed with the actual download