This has an extensive setup for the https://github.com/quer/the-steam-awards

but this does work for now.

var list = []; // empty list

module.exports = function(steamClient, RequestCommunity, RequestStore, SessionID, options, callback){
    RequestStore.MakeNavCookie('1_4_4__118', 'https://store.steampowered.com/api/addtowishlist');

    var delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));

    var loop = async function (startIndex, endIndex) {
        if (startIndex < list.length) {
            let promises = [];
            for (let index = startIndex; index < Math.min(endIndex, list.length); index++) {
                promises.push(new Promise((resolve, reject) => {
                    RequestStore.post({
                        url: "https://store.steampowered.com/api/addtowishlist",
                        form: {
                            appid: list[index],
                            sessionid: SessionID
                        }
                    }, function (postErr, postHttpResponse, postBody) {
                        if (postErr) {
                            options.log("[AddGameToWishlist] Error adding: " + list[index] + " - " + postErr);
                            reject(postErr);
                        } else {
                            options.log("[AddGameToWishlist] Added: " + list[index]);
                            resolve();
                        }
                    });
                }));
            }
            await Promise.all(promises).catch(error => options.log("[AddGameToWishlist] Error in batch processing: " + error));
            await delay(150); // 0.5 second delay
            await loop(endIndex, endIndex + promises.length);
        } else {
            options.log("[AddGameToWishlist] Done with a Steam user");
            callback();
        }
    }

    if (list.length == 0) {
        RequestStore.get({
            url: "http://api.steampowered.com/ISteamApps/GetAppList/v2"
        }, function (getErr, getHttpResponse, getBody) {
            if (getErr) {
                options.log("[AddGameToWishlist] Error getting game list: " + getErr);
                callback();
                return;
            }
            let json = JSON.parse(getBody);
            json.applist.apps.forEach(function(a) {list.push(a.appid);});
            options.log("[AddGameToWishlist] Got game list");
            loop(0, 1); // process in batches of 10
        });
    }
}

example

Edit

Pub: 27 Jul 2024 00:16 UTC

Views: 201