Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add full sharedfiles support #306

Merged
merged 23 commits into from
Jun 24, 2023

Conversation

3urobeat
Copy link
Contributor

@3urobeat 3urobeat commented May 13, 2023

This PR adds support for posting comments, deleting comments, upvoting, downvoting, adding to favorites, removing from favorites, subscribing to comments and unsubscribing from comments on sharedfiles (screenshots, artworks, guides).
I've also included a currently disabled favorite & unfavorite function which is missing an appid parameter, for reasons explained below.

It is sadly not possible to "easily" fetch all available information using the "normal" xml way as Steam does not provide any &xml=1 page for sharedfiles but we can scrape the DOM (see below!). I have therefore not added a class including an getSteamSharedfile() function.
The favorite & unfavorite requests also demand an appid header because all sharedfiles are associated to an app, which we can't figure out easily from just the sid.
While not being perfect, I think any sharedfiles support is better than none. At least commenting & voting works, which I think are the most interesting features.

An idea which I'd like feedback on:
I could try to scrape the DOM for information about the sharedfile. This would allow for an CSteamSharedfile class, including an getSteamSharedfile() function. It might be worth a try but I can't speak for any consistency or future proofness.
What I was able to scrape with a simple test:

  • Owner. Would need a lib to convert profile link to SteamID object (I don't want to advertise my own lib, but I made this lib exactly for this job). Having this ID would also get rid of all userID parameters needed for posting comments, deleting comments, subscribing to comments and unsubscribing from comments!!
  • Upvote count
  • appID. Would enable us to post favorite & unfavorite requests!
  • file size
  • post date
  • image res (if artwork/screenshot)
  • unique visitors count
  • favorites

I hope I didn't miss anything. Thanks for reading!

Edit: Oh and I hope it is ok that I opened the PR against master and not v4. If you'd rather have the changes in v4 then let me know and I'll make any necessary changes and open another PR.

Edit 2: Updated as I have now added full support using a scraper, see below.

@3urobeat
Copy link
Contributor Author

Update: I have a nearly fully working scraper now. I'll add more details tomorrow and share a CSteamSharedfile implementation.

@3urobeat 3urobeat changed the title Add (basic) sharedfiles support Add full sharedfiles support May 14, 2023
@3urobeat
Copy link
Contributor Author

3urobeat commented May 14, 2023

Ooo, I've got something exciting to share!
I now have a fully working sharedfiles implementation, featuring a scraper, CSteamSharedfile class, type enum and methods that can be accessed both raw and from an CSteamSharedfile object.

The scraper is able to get these values only by providing an id:

  • type (Screenshot, Guide or Artwork, see ESharedfileType enum)
  • appID the file is associated to
  • owner represented as SteamID object (needs the resolver lib to convert profile link to steamID64. There is no other owner information provided in the DOM, I checked)
  • fileSize (currently as unprocessed String)
  • postDate converted to Unix timestamp
  • resolution if screenshot/artwork
  • uniqueVisitorsCount
  • favoritesCount
  • upvoteCount

Two things are missing:

  • Guides don't have upvotes but ratings. I need to scrape that as well.
  • IntelliSense does not work (for me). I'm not sure how these *.d.ts files are generated which contain IntelliSense information for all other functions this lib has, I'd need your help there. I have provided JsDoc for everything I added.

I'd also volunteer to write a Wiki page for this feature so you don't have to do that.
Thanks for reading (again)!

@3urobeat
Copy link
Contributor Author

3urobeat commented May 14, 2023

If you quickly want to test it:

community.getSteamSharedfile("2966606880", (err, sharedfile) => {
    console.log(sharedfile);

    sharedfile.comment("Hi!", (err) => console.log(err));
    sharedfile.voteUp((err) => console.log(err));
    sharedfile.favorite((err) => console.log(err));
});

community is your existing SteamCommunity object.
This will get all information about this screenshot, print it to the console, comment "Hi!", like it and add it to favorites.
Each call will log null to the console on success (because I didn't care to check for !err in that simple test).

I haven't tested the methods with limited accounts yet.

If anyone else wants to try out these changes:

  • Clone my feature/steam-sharedfiles branch
  • Open a terminal in that folder and run npm pack to get a npm package
  • Open your project where you already have SteamCommunity set up to log in, install the package npm i <local-path-to-the-package-from-npm-pack>
  • You can now use the new methods

Copy link
Owner

@DoctorMcKay DoctorMcKay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I've left a few comments.

// Find owner profile link, convert to steamID64 using SteamIdResolver lib and create a SteamID object
let ownerHref = $(".friendBlockLinkOverlay").attr()["href"];

SteamIdResolver.customUrlToSteamID64(ownerHref, (err, steamID64) => { // This request takes <1 sec
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to avoid adding additional dependencies if not absolutely required. Vanity URL resolving already exists here; you could move this to helpers.js and use it here as well.

Copy link
Contributor Author

@3urobeat 3urobeat May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense. I have improved the function from getInventoryHistory() to both accept full URLs and only the vanity. This makes it easier to use without needing to parse the input before calling it. It should not change the functionality but I wasn't able to test it as getInventoryHistory() always returns Malformed page: no trade found for me.

I would have preferred to use the lib as it made the integration easier but I get your point. The helper should have the same functionality now.

* Downvotes this sharedfile
* @param {function} callback - Takes only an Error object/null as the first argument
*/
CSteamSharedfile.prototype.voteDown = function(callback) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer to leave voteDown and voteUp out of the library. I want to try to maintain at least a tenuous good relationship with Valve, and the potential for abuse here seems too great. I also can't really think of a valid use-case for bot voting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I removed both functions

* @param {String} cid - ID of the comment to delete
* @param {function} callback - Takes only an Error object/null as the first argument
*/
SteamCommunity.prototype.deleteSharedfileComment = function(userID, sid, cid, callback) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sid is kinda already known to be short for SteamID, could we call this parameter sharedFileId or fileId instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, makes sense. I changed all sid occurrences to sharedFileId.

@3urobeat 3urobeat requested a review from DoctorMcKay May 15, 2023 20:52
@3urobeat
Copy link
Contributor Author

I have added support for determining if the user logged in has voted on a sharedfile and for reading the amount of ratings from guides, as they use a different rating system than screenshots & artworks.

@3urobeat
Copy link
Contributor Author

3urobeat commented Jun 15, 2023

Merged changes from v3.44.4 & v3.45.0 into this branch and resolved conflicts.

Would be cool if you could re-review as I made the changes requested.

@DoctorMcKay DoctorMcKay merged commit 4ca0fc8 into DoctorMcKay:master Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants