|
| 1 | +# SteamDownloaderAPI |
| 2 | + |
| 3 | +[](https://goreportcard.com/report/github.com/SyNdicateFoundation/SteamDownloaderAPI) |
| 4 | +[](https://github.com/SyNdicateFoundation/SteamDownloaderAPI/actions/workflows/go.yml) |
| 5 | + |
| 6 | +A powerful Go-based reverse proxy for the Steam Workshop that dynamically injects download buttons into workshop and collection pages, allowing you to download items directly using a backend `steamcmd` instance. |
| 7 | + |
| 8 | +*** |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +This project acts as a middleman between you and the Steam Community website. When you browse a Steam Workshop page through this proxy, it intelligently modifies the page on-the-fly to add "Download" buttons next to the standard "Subscribe" buttons. Clicking these new buttons triggers a backend process that uses `steamcmd` to download the workshop files to your server. |
| 13 | + |
| 14 | +This is perfect for server administrators, content curators, or anyone who needs to obtain workshop files without subscribing to them through the Steam client. |
| 15 | + |
| 16 | +*** |
| 17 | + |
| 18 | +## Features |
| 19 | + |
| 20 | +- **Reverse Proxy for Steam Workshop**: Forwards requests to `steamcommunity.com` seamlessly. |
| 21 | +- **Dynamic Content Injection**: Injects "Download" and "Download Collection" buttons directly into the HTML using `goquery`. |
| 22 | +- **URL Rewriting**: All asset URLs (CSS, JS, images) are rewritten to be served through the proxy, ensuring pages render correctly. |
| 23 | +- **`steamcmd` Integration**: Leverages a `steamcmd` wrapper to handle the actual download logic. |
| 24 | +- **Configurable Startup**: Use command-line flags to easily configure server settings. |
| 25 | + |
| 26 | +*** |
| 27 | + |
| 28 | +## How It Works |
| 29 | + |
| 30 | +1. The user navigates to a proxied Steam Workshop URL (e.g., `http://localhost:8080/workshop/filedetails/?id=123456789`). |
| 31 | +2. The `SteamProxyHandler` receives the request and forwards it to the official Steam servers. |
| 32 | +3. Before sending the response back to the user, the `ModifyResponse` function intercepts it. |
| 33 | +4. The HTML body is parsed. The proxy finds all "Subscribe" buttons and injects new `<a>` tags next to them, pointing to the downloader API endpoints. |
| 34 | +5. All other URLs within the page (`href`, `src`, `srcset`) are rewritten to be relative, ensuring all subsequent requests for assets also go through the proxy. |
| 35 | +6. The modified, uncompressed HTML is sent to the user's browser. |
| 36 | +7. When the user clicks a "Download" button, a request is sent to an API endpoint like `/api/workshop/:app_id/:workshop_id`. |
| 37 | +8. The API handler calls the `steamcmd` wrapper, which executes the necessary commands (`workshop_download_item`) to download the files to the server. |
| 38 | + |
| 39 | +*** |
| 40 | + |
| 41 | +## API Endpoints |
| 42 | + |
| 43 | +- `GET /api/workshop/:app_id/:workshop_id` |
| 44 | + - Triggers a download for a single workshop item. |
| 45 | + - **`app_id`**: The ID of the game (e.g., `4000` for Garry's Mod). |
| 46 | + - **`workshop_id`**: The ID of the workshop file. |
| 47 | + |
| 48 | +- `GET /api/collection/:app_id/:collection_id` |
| 49 | + - Triggers a download for all items within a collection. |
| 50 | + - **`app_id`**: The ID of the game. |
| 51 | + - **`collection_id`**: The ID of the workshop collection. |
| 52 | + |
| 53 | +*** |
| 54 | + |
| 55 | +## Setup and Installation |
| 56 | + |
| 57 | +### Prerequisites |
| 58 | + |
| 59 | +- [Go](https://golang.org/doc/install) (version 1.18 or newer) |
| 60 | +- A working installation of [`steamcmd`](https://developer.valvesoftware.com/wiki/SteamCMD) on the server where this API will run (or let the app install it for you). |
| 61 | + |
| 62 | +### Steps |
| 63 | + |
| 64 | +1. **Clone the repository:** |
| 65 | + ```sh |
| 66 | + git clone https://github.com/SyNdicateFoundation/SteamDownloaderAPI.git |
| 67 | + cd SteamDownloaderAPI |
| 68 | + ``` |
| 69 | + |
| 70 | +2. **Install dependencies:** |
| 71 | + ```sh |
| 72 | + go mod tidy |
| 73 | + ``` |
| 74 | + |
| 75 | +3. **Build the application:** |
| 76 | + ```sh |
| 77 | + go build -o steamdownloaderapi ./cmd/main.go |
| 78 | + ``` |
| 79 | + |
| 80 | +*** |
| 81 | + |
| 82 | +## Configuration & Usage |
| 83 | + |
| 84 | +The application is configured at startup using command-line flags. |
| 85 | + |
| 86 | +### Available Flags |
| 87 | + |
| 88 | +- `-listenhost`: The hostname or IP address for the server to listen on. (Default: `0.0.0.0`) |
| 89 | +- `-listenport`: The port for the server to listen on. (Default: `8080`) |
| 90 | +- `-steamcmdpath`: The directory path for `steamcmd`. (Default: `steamcmd`) |
| 91 | +- `-installsteamcmd`: If `true`, the application will install or update `steamcmd` on startup. (Default: `true`) |
| 92 | +- `-debug`: Enables debug mode for more verbose logging. (Default: `false`) |
| 93 | +- `-steamuser`: Your Steam username. Required for downloading certain content. (Default: `""`, will login as anonymous) |
| 94 | +- `-steampassword`: Your Steam password. (Default: `""`) |
| 95 | + |
| 96 | +### Running the Server |
| 97 | + |
| 98 | +Once built, you can run the application from your terminal. |
| 99 | + |
| 100 | +**Basic startup (installs steamcmd to a 'steamcmd' folder and runs on port 8080):** |
| 101 | +```sh |
| 102 | +./steamdownloaderapi -steamuser your_username -steampassword your_password |
0 commit comments