Skip to content

Commit

Permalink
support IPublishedFileService/GetDetails
Browse files Browse the repository at this point in the history
 * fallback to anonym endpoint when steam web api key is not provided
 * upd. readme
  • Loading branch information
a-sync committed Nov 12, 2023
1 parent b9ec825 commit 7e3ff6d
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 64 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ Only alphanumeric characters + `_` and the optional `*` prefix/suffix is allowed
* **FNF_WW2**
* [1769913157](https://steamcommunity.com/sharedfiles/filedetails/?id=1769913157) FNF WW2 Mod Collection (collection)
* _[2120184260](https://steamcommunity.com/sharedfiles/filedetails/?id=2120184260) FNF WW2 Optionals (collection)_
* 77th JSOC: [arma3pregen.devs.space/?77th_JSOC=2829455808\*](https://arma3pregen.devs.space/?77th_JSOC=2829455808*)
* 77th JSOC: [arma3pregen.devs.space/?77th_JSOC=2982471935\*](https://arma3pregen.devs.space/?77th_JSOC=2982471935*)
* **77th_JSOC**
* _[2829455808](https://steamcommunity.com/sharedfiles/filedetails/?id=2829455808) 77th JSOC | Public Servers Mod Collection (Official) (collection)_
* _[2982471935](https://steamcommunity.com/sharedfiles/filedetails/?id=2982471935) 77th JSOC | Public Servers Mod Collection (Official) (collection)_
* C4G RHS KotH: [arma3pregen.devs.space/?C4G_RHS_KotH=1290398866,\*861133494,\*945476727,\*1180534892,\*1180533757](https://arma3pregen.devs.space/?C4G_RHS_KotH=1290398866,*861133494,*945476727,*1180534892,*1180533757)
* **C4G_RHS_KotH**
* [1290398866](https://steamcommunity.com/sharedfiles/filedetails/?id=1290398866) RHS - King of the Hill by Sa-Matra (collection)
Expand Down Expand Up @@ -79,7 +79,8 @@ Spin up an instance on `http://localhost/` with one of these commands:
_The app can be served from under any subdomain or path._

### Environmental variables
`CACHE_MAX_AGE` env var controls the browser cache for backend requests in seconds. _(default: 0)_
`CACHE_MAX_AGE` controls the browser cache for backend requests in seconds. _[default: 0]_
`STEAM_WEB_API_KEY` enables the usage of [API key](https://steamcommunity.com/dev/apikey) protected steam endpoints. (optional) _[default: empty]_

## Similar projects
* https://github.com/ColinM9991/Arma-Preset-Creator
Expand Down
72 changes: 43 additions & 29 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,51 @@ module.exports = async (req, res) => {

re = JSON.stringify({ response });
} else {
let api = '';
const pl = {};
if (postData.api === 'file1') {
api = 'ISteamRemoteStorage/GetPublishedFileDetails';
pl.itemcount = idList.length;
pl.publishedfileids = idList;
re = await post('https://api.steampowered.com/' + api + '/v1/?', pl);
} else if (postData.api === 'file') {
//todo: if !STEAM_WEB_API_KEY, throw error
if (postData.api === 'file' && STEAM_WEB_API_KEY !== '') {
const api = 'IPublishedFileService/GetDetails';
const pl = {
key: STEAM_WEB_API_KEY,
appid: 107410,
publishedfileids: idList,
includetags: true,
includeadditionalpreviews: false,
includechildren: false,
includekvtags: false,
includevotes: false,
short_description: false,
includeforsaledata: false,
includemetadata: false,
return_playtime_stats: false,
strip_description_bbcode: false
}

const params = new URLSearchParams();
for (const k in pl) {
if (Array.isArray(pl[k])) pl[k].forEach((l, i) => params.append(k + '[' + i + ']', l));
else params.append(k, pl[k]);
}

re = await get('https://api.steampowered.com/' + api + '/v1/?' + params.toString());
}
else if (postData.api === 'file') {
const api = 'ISteamRemoteStorage/GetPublishedFileDetails';
const pl = {
itemcount: idList.length,
publishedfileids: idList
};

// https://api.steampowered.com/IPublishedFileService/GetDetails/v1/?publishedfileids%5B0%5D=1286101012&includetags=true&includeadditionalpreviews=true&includechildren=true&includekvtags=true&includevotes=true&short_description=&includemetadata=true&appid=107410&strip_description_bbcode=true&includereactions=true
api = 'IPublishedFileService/GetDetails';
pl.key = STEAM_WEB_API_KEY;
pl.appid = 107410;
pl.publishedfileids = idList;
pl.includetags = true;
pl.includeadditionalpreviews = true;
pl.includechildren = true;
pl.includekvtags = true;
pl.includevotes = true;
pl.short_description = false;
pl.includemetadata = true;
pl.strip_description_bbcode = true;
pl.includereactions = true;
} else if (postData.api === 'collection') {
api = 'ISteamRemoteStorage/GetCollectionDetails';
pl.collectioncount = idList.length;
pl.publishedfileids = idList;
} else throw new Error('Invalid api');
re = await post('https://api.steampowered.com/' + api + '/v1/?', pl);
}
else if (postData.api === 'collection') {
const api = 'ISteamRemoteStorage/GetCollectionDetails';
const pl = {
collectioncount: idList.length,
publishedfileids: idList
}

re = await post('https://api.steampowered.com/' + api + '/v1/?', pl);
re = await post('https://api.steampowered.com/' + api + '/v1/?', pl);
}
else throw new Error('Invalid api');
}

res.writeHead(200, {
Expand Down
69 changes: 44 additions & 25 deletions backend/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
define('CACHE_MAX_AGE', intval(@getenv('CACHE_MAX_AGE')));
define('STEAM_WEB_API_KEY', strval(@getenv('STEAM_WEB_API_KEY')));

header('Content-Type: application/json');
try {
Expand Down Expand Up @@ -36,44 +37,62 @@
} else {
$api = '';
$pl = [];
if ($postData['api'] === 'file1') {
$api = 'ISteamRemoteStorage/GetPublishedFileDetails';
$pl = [
'itemcount' => count($idList),
'publishedfileids' => $idList
];
} elseif ($postData['api'] === 'file') {
if ($postData['api'] === 'file' && STEAM_WEB_API_KEY !== '') {
$api = 'IPublishedFileService/GetDetails';
$pl = [
'key' => getenv('STEAM_WEB_API_KEY'),
'key' => STEAM_WEB_API_KEY,
'appid' => 107410,
'publishedfileids' => $idList,
'includetags' => true,
'includeadditionalpreviews' => true,
'includechildren' => true,
'includekvtags' => true,
'includevotes' => true,
'includeadditionalpreviews' => false,
'includechildren' => false,
'includekvtags' => false,
'includevotes' => false,
'short_description' => false,
'includemetadata' => true,
'strip_description_bbcode' => true,
'includereactions' => true
'includeforsaledata' => false,
'includemetadata' => false,
'return_playtime_stats' => false,
'strip_description_bbcode' => false
];
} elseif ($postData['api'] === 'collection') {

$re = file_get_contents('https://api.steampowered.com/' . $api . '/v1/?' . http_build_query($pl), false, stream_context_create([
'http' => [
'method' => 'GET',
'header' => 'User-Agent: arma3pregen/1.0'
]
]));
}
elseif ($postData['api'] === 'file') {
$api = 'ISteamRemoteStorage/GetPublishedFileDetails';
$pl = [
'itemcount' => count($idList),
'publishedfileids' => $idList
];

$re = file_get_contents('https://api.steampowered.com/' . $api . '/v1/?', false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded; User-Agent: arma3pregen/1.0',
'content' => http_build_query($pl)
]
]));
}
elseif ($postData['api'] === 'collection') {
$api = 'ISteamRemoteStorage/GetCollectionDetails';
$pl = [
'collectioncount' => count($idList),
'publishedfileids' => $idList
];
} else throw new Error('Invalid api');

$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded; User-Agent: arma3pregen/1.0',
'content' => http_build_query($pl)
]
]);
$re = file_get_contents('https://api.steampowered.com/' . $api . '/v1/?', false, $context);
$re = file_get_contents('https://api.steampowered.com/' . $api . '/v1/?', false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded; User-Agent: arma3pregen/1.0',
'content' => http_build_query($pl)
]
]));
}
else throw new Error('Invalid api');
}

header('Cache-Control: max-age=' . CACHE_MAX_AGE);
Expand Down
15 changes: 8 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ async function parsePresetIds(presetIds) {
}).then(res => res.json());

if (mods.error) console.error(mods.error);
else if (mods.response && mods.response.resultcount > 0) {
else if (mods.response && (mods.response.resultcount > 0 || (mods.response.publishedfiledetails && mods.response.publishedfiledetails.length > 0))) {
for (const f of mods.response.publishedfiledetails) {
if (VALID_APP_IDS.includes(f.consumer_app_id)) {
if (VALID_APP_IDS.includes(f.consumer_app_id) || VALID_APP_IDS.includes(f.consumer_appid)) {
if (collectionChildren[f.publishedfileid]) f._children = collectionChildren[f.publishedfileid];
if (f.result && f.result !== 9) modDetails.push(f);
}
Expand Down Expand Up @@ -443,7 +443,7 @@ function renderDownloadButton() {

const size = uniqueAll.reduce((p, c) => {
const m = getModById(c);
if (m && m.file_size) return p + m.file_size;
if (m && m.file_size) return p + parseInt(m.file_size, 10);
else return p;
}, 0);

Expand Down Expand Up @@ -576,10 +576,10 @@ function showInfoModal(data) {
let size = 0;
for (const c of data.mod._children) {
const m = getModById(c);
if (m && m.file_size) size += m.file_size;
if (m && m.file_size) size += parseInt(m.file_size, 10);
}
tr.append(e('td', 'Total Size'), e('td', formatBytes(size)));
} else tr.append(e('td', 'File Size'), e('td', formatBytes(data.mod.file_size)));
} else tr.append(e('td', 'File Size'), e('td', formatBytes(parseInt(data.mod.file_size, 10))));
detailsTbody.append(tr);
}
if (data.mod._children && data.mod._children.length > 0) {
Expand All @@ -603,9 +603,10 @@ function showInfoModal(data) {
dc.append(detailsTable);
}

if (data.mod.description) {
const desc = data.mod.description || data.mod.file_description
if (desc) {
const descDiv = e('div');
descDiv.innerHTML = parseSteamBBCode(data.mod.description);
descDiv.innerHTML = parseSteamBBCode(desc);
descDiv.className = 'description';
dc.append(descDiv);
}
Expand Down

0 comments on commit 7e3ff6d

Please sign in to comment.