steamworks-js-workshop.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --- a/src/api/workshop.rs 2026-09-18 16:42:37.406700437 +0000
  2. +++ b/src/api/workshop.rs 2026-09-18 16:42:37.406700437 +0000
  3. @@ -108,6 +108,13 @@
  4. pub total: BigInt,
  5. }
  6. + #[napi(object)]
  7. + pub struct UserItemVote {
  8. + pub voted_up: bool,
  9. + pub voted_down: bool,
  10. + pub vote_skipped: bool,
  11. + }
  12. +
  13. #[derive(Debug)]
  14. #[napi]
  15. pub enum UpdateStatus {
  16. @@ -319,6 +326,52 @@
  17. Err(e) => Err(Error::from_reason(e.to_string())),
  18. }
  19. }
  20. +
  21. + /// Sets the current user's vote (up or down) on a workshop item.
  22. + ///
  23. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#SetUserItemVote}
  24. + #[napi]
  25. + pub async fn vote_item(item_id: BigInt, vote_up: bool) -> Result<(), Error> {
  26. + let client = crate::client::get_client();
  27. + let (tx, rx) = oneshot::channel();
  28. +
  29. + client
  30. + .ugc()
  31. + .vote_up_item(PublishedFileId(item_id.get_u64().1), vote_up, |result| {
  32. + tx.send(result).unwrap();
  33. + });
  34. +
  35. + let result = rx.await.unwrap();
  36. + match result {
  37. + Ok(()) => Ok(()),
  38. + Err(e) => Err(Error::from_reason(e.to_string())),
  39. + }
  40. + }
  41. +
  42. + /// Gets the current user's existing vote (if any) on a workshop item.
  43. + ///
  44. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#GetUserItemVote}
  45. + #[napi]
  46. + pub async fn get_user_vote(item_id: BigInt) -> Result<UserItemVote, Error> {
  47. + let client = crate::client::get_client();
  48. + let (tx, rx) = oneshot::channel();
  49. +
  50. + client
  51. + .ugc()
  52. + .user_item_vote(PublishedFileId(item_id.get_u64().1), |result| {
  53. + tx.send(result).unwrap();
  54. + });
  55. +
  56. + let result = rx.await.unwrap();
  57. + match result {
  58. + Ok(v) => Ok(UserItemVote {
  59. + voted_up: v.voted_up,
  60. + voted_down: v.voted_down,
  61. + vote_skipped: v.vote_skipped,
  62. + }),
  63. + Err(e) => Err(Error::from_reason(e.to_string())),
  64. + }
  65. + }
  66. /// Gets the current state of a workshop item on this client. States can be combined.
  67. ///