diff --git a/api/cdb/client.go b/api/cdb/client.go index 23f777aa..71ce30a6 100644 --- a/api/cdb/client.go +++ b/api/cdb/client.go @@ -90,6 +90,12 @@ func (c *CDBClient) SearchPackages(q *PackageQuery) ([]*Package, error) { if q.Order != "" { params.Add("order", string(q.Order)) } + if q.ProtocolVersion > 0 { + params.Add("protocol_version", fmt.Sprintf("%d", q.ProtocolVersion)) + } + if q.EngineVersion != "" { + params.Add("engine_version", q.EngineVersion) + } err := c.get("api/packages", &pkgs, params) return pkgs, err diff --git a/api/cdb/types.go b/api/cdb/types.go index bbcfc429..bf434275 100644 --- a/api/cdb/types.go +++ b/api/cdb/types.go @@ -25,13 +25,15 @@ const ( ) type PackageQuery struct { - Type []PackageType `json:"type"` - Query string `json:"query"` - Author string `json:"author"` - Limit int `json:"limit"` - Hide []ContentWarning `json:"hide"` - Sort PackageSortType `json:"sort"` - Order PackageSortOrderType `json:"order"` + Type []PackageType `json:"type"` + Query string `json:"query"` + Author string `json:"author"` + Limit int `json:"limit"` + Hide []ContentWarning `json:"hide"` + Sort PackageSortType `json:"sort"` + Order PackageSortOrderType `json:"order"` + ProtocolVersion int `json:"protocol_version"` + EngineVersion string `json:"engine_version"` } type Package struct { diff --git a/public/js/components/pages/cdb/Install.js b/public/js/components/pages/cdb/Install.js index b8289827..08cee839 100644 --- a/public/js/components/pages/cdb/Install.js +++ b/public/js/components/pages/cdb/Install.js @@ -1,10 +1,14 @@ import DefaultLayout from "../../layouts/DefaultLayout.js"; import { add } from "../../../service/mods.js"; import { get_dependencies, get_package } from "../../../service/cdb.js"; +import { search_packages } from "../../../api/cdb.js"; import { validate } from "../../../api/mods.js"; import { START, ADMINISTRATION, MODS, CDB, CDB_DETAIL } from "../../Breadcrumb.js"; import CDBPackageLink from "../../CDBPackageLink.js"; +// all cdb packages (mods, without details) +let packages = []; + export default { components: { "default-layout": DefaultLayout, @@ -20,6 +24,7 @@ export default { pkg: null, selected_deps: {}, // modname => {author,name} deps: [], + packages: packages, installed_mods: {}, // modname => true breadcrumb: [START, ADMINISTRATION, MODS, CDB, CDB_DETAIL(author, name), { name: `Install package '${author}/${name}'`, @@ -34,6 +39,8 @@ export default { validate() .then(r => r.installed.forEach(modname => this.installed_mods[modname] = true)) + .then(() => this.packages.length == 0 ? search_packages({ type: ["mod"] }) : this.packages) + .then(pkgs => { this.packages = pkgs; packages = pkgs; }) .then(this.resolve_deps(this.author, this.name)); }, methods: { @@ -67,18 +74,18 @@ export default { } // fetch all package infos and provide package choices - const pl = dep.packages.map(p => { - const parts = p.split("/"); - return get_package(parts[0], parts[1]); + const choices = []; + dep.packages.forEach(pkg => { + const parts = pkg.split("/"); + const detail = this.packages.find(pkg => pkg.author == parts[0] && pkg.name == parts[1]); + if (detail && detail.type == "mod") { + choices.push(pkg); + } }); - Promise.all(pl) - .then(package_choices => package_choices.filter(pc => pc.type == "mod")) - .then(package_choices => { - this.deps.push({ - name: dep.name, - choices: package_choices.map(p => `${p.author}/${p.name}`) - }); + this.deps.push({ + name: dep.name, + choices: choices }); }); });