Cthulhu is no longer a fork. Now it is a screen reader written in Golang.
This commit is contained in:
1 parent
a998fe67de
commit
069fc674dc
708 files changed
+112482
-532
No files matched your search
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"slices"
|
||||
|
||||
"git.stormux.org/storm/cthulhu/internal/tentacle"
|
||||
)
|
||||
|
||||
func change_tentacle_repositories(repositories []tentacle.Repository, request tentacle.ManagementRequest, repository *tentacle.Repository) ([]tentacle.Repository, error) {
|
||||
if request.Entry != nil || request.ID != "" {
|
||||
return nil, errors.New("unexpected tentacle entry in repository request")
|
||||
}
|
||||
origin, err := tentacle.RepositoryURL(request.URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
next := tentacle.CloneRepositories(repositories)
|
||||
index := slices.IndexFunc(next, func(value tentacle.Repository) bool { return value.URL == origin })
|
||||
switch request.Action {
|
||||
case "repository-add", "repository-refresh":
|
||||
if repository == nil || repository.URL != origin {
|
||||
return nil, errors.New("validated repository metadata is required")
|
||||
}
|
||||
candidate := tentacle.CloneRepositories([]tentacle.Repository{*repository})[0]
|
||||
if request.Action == "repository-add" {
|
||||
if index >= 0 {
|
||||
return nil, errors.New("repository already added")
|
||||
}
|
||||
next = append(next, candidate)
|
||||
} else {
|
||||
if index < 0 {
|
||||
return nil, errors.New("repository does not exist")
|
||||
}
|
||||
if next[index].ID != repository.ID {
|
||||
return nil, errors.New("repository identity changed; the previous catalog was retained")
|
||||
}
|
||||
next[index] = candidate
|
||||
}
|
||||
case "repository-remove":
|
||||
if index < 0 {
|
||||
return nil, errors.New("repository does not exist")
|
||||
}
|
||||
next = slices.Delete(next, index, index+1)
|
||||
default:
|
||||
return nil, errors.New("unknown repository operation")
|
||||
}
|
||||
return next, tentacle.ValidateRepositories(next)
|
||||
}
|
||||
Reference in new issue
Block a user