Skip to content

Commit

Permalink
cdb
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Sep 11, 2023
1 parent 96e6c80 commit c389846
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
6 changes: 6 additions & 0 deletions api/cdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions api/cdb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 17 additions & 10 deletions public/js/components/pages/cdb/Install.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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}'`,
Expand All @@ -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: {
Expand Down Expand Up @@ -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
});
});
});
Expand Down

0 comments on commit c389846

Please sign in to comment.