Skip to content

Commit a9e1f26

Browse files
committed
fix: even more fixes!
1 parent 3a6d2c9 commit a9e1f26

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

jukebox/jukebox/managers/index_manager.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ Result<> IndexManager::loadIndex(std::filesystem::path path) {
8787
}
8888

8989
Result<> IndexManager::loadIndex(matjson::Value&& jsonObj) {
90-
GEODE_UNWRAP_INTO(IndexMetadata indexMeta,
91-
matjson::Serialize<IndexMetadata>::fromJson(jsonObj));
90+
GEODE_UNWRAP_INTO(auto indexMeta, jsonObj.as<IndexMetadata>());
9291
std::unique_ptr<IndexMetadata> index =
9392
std::make_unique<IndexMetadata>(std::move(indexMeta));
9493

@@ -138,18 +137,15 @@ Result<> IndexManager::loadIndex(matjson::Value&& jsonObj) {
138137
/*}*/
139138

140139
for (const auto& [key, hostedNong] : jsonObj["nongs"]["hosted"]) {
141-
Result<IndexSongMetadata> r =
142-
matjson::Serialize<IndexSongMetadata>::fromJson(hostedNong);
143-
if (r.isErr()) {
144-
event::SongError(
145-
false,
146-
fmt::format("Failed to parse index song: {}", r.unwrapErr()))
140+
GEODE_UNWRAP_OR_ELSE(r, err, hostedNong.as<IndexSongMetadata>()) {
141+
event::SongError(false,
142+
fmt::format("Failed to parse index song: {}", err))
147143
.post();
148144
continue;
149145
}
150146

151147
std::unique_ptr<IndexSongMetadata> song =
152-
std::make_unique<IndexSongMetadata>(r.unwrap());
148+
std::make_unique<IndexSongMetadata>(std::move(r));
153149

154150
song->uniqueID = key;
155151
song->parentID = index.get();
@@ -167,11 +163,10 @@ Result<> IndexManager::loadIndex(matjson::Value&& jsonObj) {
167163

168164
Nongs* nongs = opt.value();
169165

170-
if (geode::Result<> r = nongs->registerIndexSong(song.get());
171-
r.isErr()) {
166+
if (GEODE_UNWRAP_IF_ERR(err, nongs->registerIndexSong(song.get()))) {
172167
event::SongError(
173-
false, fmt::format("Failed to register index song: {}",
174-
r.unwrapErr()))
168+
false,
169+
fmt::format("Failed to register index song: {}", err))
175170
.post();
176171
}
177172
}
@@ -194,7 +189,14 @@ Result<> IndexManager::fetchIndexes() {
194189

195190
for (const IndexSource& index : indexes) {
196191
if (!index.m_enabled || index.m_url.size() < 3) {
197-
log::info("Skipping index {}, as it is disabled", index.m_url);
192+
if (!index.m_userAdded) {
193+
log::warn(
194+
"Skipping default index {} provided by Jukebox, as it is "
195+
"disabled",
196+
index.m_url);
197+
} else {
198+
log::info("Skipping index {}, as it is disabled", index.m_url);
199+
}
198200
continue;
199201
}
200202

@@ -256,7 +258,6 @@ void IndexManager::onIndexFetched(const std::string& url,
256258

257259
const std::filesystem::path filepath =
258260
this->baseIndexesPath() / fmt::format("{0:x}.json", hashValue);
259-
log::info("{}", filepath);
260261

261262
log::info("Fetched index: {}", url);
262263

@@ -266,11 +267,11 @@ void IndexManager::onIndexFetched(const std::string& url,
266267
out.write(str.data(), str.length());
267268
log::info("Cached index: {}", url);
268269
} else {
269-
log::info("Failed to cache index: {}", url);
270+
log::error("Failed to cache index: {}", url);
270271
}
271272

272273
this->loadIndex(std::move(json)).inspectErr([url](const std::string& err) {
273-
log::info("Failed to load index {}: {}", url, err);
274+
log::error("Failed to load index {}: {}", url, err);
274275
});
275276
}
276277

@@ -366,8 +367,9 @@ Result<> IndexManager::downloadSong(int gdSongID, const std::string& uniqueID) {
366367
// If not uniqueID not found in local songs, search in indexes
367368
if (!found) {
368369
if (!m_nongsForId.contains(gdSongID)) {
369-
return Err("Can't download nong for id {}. No local or index songs found.",
370-
gdSongID);
370+
return Err(
371+
"Can't download nong for id {}. No local or index songs found.",
372+
gdSongID);
371373
}
372374

373375
std::vector<IndexSongMetadata*> songs = m_nongsForId[gdSongID];
@@ -546,8 +548,7 @@ void IndexManager::onDownloadFinish(
546548
ListenerResult IndexManager::onDownloadStart(event::StartDownload* e) {
547549
Result<> res = this->downloadSong(e->gdSongID(), e->uniqueID());
548550
if (res.isErr()) {
549-
event::SongDownloadFailed(e->gdSongID(), e->uniqueID(),
550-
res.unwrapErr())
551+
event::SongDownloadFailed(e->gdSongID(), e->uniqueID(), res.unwrapErr())
551552
.post();
552553
}
553554
return ListenerResult::Propagate;

jukebox/jukebox/nong/index_serialize.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct matjson::Serialize<jukebox::index::IndexSource> {
205205
matjson::Value const& value) {
206206
GEODE_UNWRAP_INTO(std::string url, value["url"].asString());
207207
GEODE_UNWRAP_INTO(bool userAdded, value["userAdded"].asBool());
208-
GEODE_UNWRAP_INTO(bool enabled, value["userAdded"].asBool());
208+
GEODE_UNWRAP_INTO(bool enabled, value["enabled"].asBool());
209209

210210
return geode::Ok(jukebox::index::IndexSource{.m_url = std::move(url),
211211
.m_userAdded = userAdded,

jukebox/jukebox/ui/indexes_setting.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ struct matjson::Serialize<jukebox::Indexes> {
6666
jukebox::Indexes ret;
6767

6868
for (const matjson::Value& elem : value) {
69-
GEODE_UNWRAP_INTO(
70-
jukebox::IndexSource source,
71-
matjson::Serialize<jukebox::IndexSource>::fromJson(elem));
72-
ret.indexes.push_back(source);
69+
GEODE_UNWRAP_INTO(auto source, elem.as<jukebox::IndexSource>());
70+
ret.indexes.push_back(std::move(source));
7371
}
74-
return geode::Ok(ret);
72+
return geode::Ok(std::move(ret));
7573
}
7674
};

0 commit comments

Comments
 (0)