WebAPI: Unify torrent category related keys#23788
WebAPI: Unify torrent category related keys#23788jagadam97 wants to merge 1 commit intoqbittorrent:masterfrom
Conversation
|
@thalieht will provide better code in future contributions. |
src/webui/api/synccontroller.cpp
Outdated
| const BitTorrent::CategoryOptions categoryOptions = session->categoryOptions(categoryName); | ||
| auto category = categoryOptions.toJSON().toVariantMap(); | ||
| QVariant downloadPathVal = category.value(u"download_path"_s); | ||
| // adjust it to be compatible with existing WebAPI | ||
| category[u"savePath"_s] = category.take(u"save_path"_s); | ||
| category.insert(u"name"_s, categoryName); | ||
| if ((downloadPathVal.typeId() == QMetaType::QString) && !downloadPathVal.toString().isEmpty()) | ||
| { | ||
| category[u"downloadPathEnabled"_s] = true; | ||
| category[u"downloadPath"_s] = downloadPathVal.toString(); | ||
| } | ||
| else | ||
| { | ||
| category[u"downloadPathEnabled"_s] = false; | ||
| } |
There was a problem hiding this comment.
Could you reorder and simplify it a bit?
| const BitTorrent::CategoryOptions categoryOptions = session->categoryOptions(categoryName); | |
| auto category = categoryOptions.toJSON().toVariantMap(); | |
| QVariant downloadPathVal = category.value(u"download_path"_s); | |
| // adjust it to be compatible with existing WebAPI | |
| category[u"savePath"_s] = category.take(u"save_path"_s); | |
| category.insert(u"name"_s, categoryName); | |
| if ((downloadPathVal.typeId() == QMetaType::QString) && !downloadPathVal.toString().isEmpty()) | |
| { | |
| category[u"downloadPathEnabled"_s] = true; | |
| category[u"downloadPath"_s] = downloadPathVal.toString(); | |
| } | |
| else | |
| { | |
| category[u"downloadPathEnabled"_s] = false; | |
| } | |
| const BitTorrent::CategoryOptions categoryOptions = session->categoryOptions(categoryName); | |
| auto category = categoryOptions.toJSON().toVariantMap(); | |
| // adjust it to be compatible with existing WebAPI | |
| category[u"savePath"_s] = category.take(u"save_path"_s); | |
| category.insert(u"name"_s, categoryName); | |
| // ADD SOME COMMENT FOR ADDING THIS CODE... | |
| const QString downloadPathVal = category.value(u"download_path"_s).toString(); | |
| if (!downloadPathVal.isEmpty()) | |
| { | |
| category[u"downloadPathEnabled"_s] = true; | |
| category[u"downloadPath"_s] = downloadPathVal; | |
| } | |
| else | |
| { | |
| category[u"downloadPathEnabled"_s] = false; | |
| } |
There was a problem hiding this comment.
my first approach was this but changed it at 1st rewrite thinking this might be one of the coding style discrepancy
src/webui/api/synccontroller.cpp
Outdated
| QJsonValue downloadPathVal = category.value(u"download_path"_s); | ||
| // adjust it to be compatible with existing WebAPI | ||
| category[u"savePath"_s] = category.take(u"save_path"_s); | ||
| if (downloadPathVal.isString() && !downloadPathVal.toString().isEmpty()) | ||
| { | ||
| category[u"downloadPathEnabled"_s] = true; | ||
| category[u"downloadPath"_s] = downloadPathVal.toString(); | ||
| } | ||
| else | ||
| { | ||
| category[u"downloadPathEnabled"_s] = false; | ||
| } | ||
|
|
There was a problem hiding this comment.
I doubt you need this code here. What happens if you don't add them?
There was a problem hiding this comment.
let me test it out and get back.
There was a problem hiding this comment.
I doubt you need this code here.
What made you doubt it?
There was a problem hiding this comment.
What happens if you don't add them?
It doesn't add the corresponding data in the snapshot.
There was a problem hiding this comment.
What made you doubt it?
It seems suspicious it require two instances of similar code.
Also, it is been some time I looked into this code section and I'm not familiar with it anymore.
There was a problem hiding this comment.
It seems suspicious it require two instances of similar code.
An initial snapshot is generated in one place, and the modified data is serialized in another.
Perhaps the shared code could be extracted into a separate function for reuse.
|
@qbittorrent/web-developers |
src/webui/api/synccontroller.cpp
Outdated
| category[u"downloadPathEnabled"_s] = true; | ||
| category[u"downloadPath"_s] = downloadPathVal.toString(); | ||
| } | ||
| else |
There was a problem hiding this comment.
Everyone always forgets about it (or doesn't know at all), but the sync algorithm requires that the source dictionaries contain all the keys unconditionally.
So else branch must add the same keys as if.
There was a problem hiding this comment.
I was having this dought but seeing the maindata api sending data seemlessly without maintaining the downloadPath in both branches i was convinced not to do the above.
made the change to explicity setting the all the keys.
I'm a bit out of touch with the details but I agree with the general idea. That is, match with the core option names. |
We have two options for such data structures that need to be serialized for different purposes (for example, to save them in files and transfer them via the WebAPI):
While the first option seems to be the best at first glance (which is why it was implemented initially), now I would most likely prefer the second one. |
ec6afed to
45b501c
Compare
45b501c to
56e6e8e
Compare
This PR introduces two new keys for maindata response namely downloadPath and downloadPathEnabled. in editCategory/createCategory we take these keys to set category download_path but while returning the in maindata response we are sending download_path and this fails for type strict application as this same key return false or path based on if the download_path is enabled or not. leaving the download_path as is as there might be applications which consume the download_path. (can remove if needed) closes qbittorrent#23780
56e6e8e to
094261e
Compare
I would still prefer that we use some kind of strict approach to serialization. The current version looks like a workaround.
I.e.:
|
This PR introduces two new keys for maindata response namely
downloadPath and downloadPathEnabled.
in editCategory/createCategory we take these keys to set category
download_path but while returning the in maindata response we are
sending download_path and this fails for type strict application as
this same key return false or path based on if the download_path is
enabled or not.
leaving the download_path as is as there might be applications which
consume the download_path. (can remove if needed)
closes #23780