Skip to content

Commit

Permalink
steam api file_size type fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-guard committed Feb 25, 2024
1 parent 69c8ec9 commit 5cfd16b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/services/steamcmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ export class SteamCMD extends IService {
const bySize: Partial<PublishedFileDetail>[] = modsMeta
.sort(
/* istanbul ignore next */
(a, b) => (b.file_size || 0) - (a.file_size || 0),
(a, b) => Number(b.file_size || 0) - Number(a.file_size || 0),
);

// add possibly missing mods with size 0 as its unknown
Expand All @@ -785,17 +785,17 @@ export class SteamCMD extends IService {
.map(/* istanbul ignore next */ (x) => ({
publishedfileid: x,
// eslint-disable-next-line @typescript-eslint/naming-convention
file_size: 0,
file_size: '0',
}) as Partial<PublishedFileDetail>));

const maxBatchSize = this.manager.config.updateModsMaxBatchSize || 5;
const maxDownloadSize = this.manager.config.updateModsMaxBatchFileSize || 1_000_000_000; // ~1 GB
let curBatch: Partial<PublishedFileDetail>[] = [];
for (const mod of bySize) {
let curBatchFileSize = curBatch.reduce((acc, x) => acc + (x.file_size || 0), 0);
let curBatchFileSize = curBatch.reduce((acc, x) => acc + Number(x.file_size || 0), 0);

// if this mod would exceed the download limit, then execute the batch first
if (curBatch.length && (curBatchFileSize + (mod.file_size || 0)) >= maxDownloadSize) {
if (curBatch.length && (curBatchFileSize + Number(mod.file_size || 0)) >= maxDownloadSize) {
const curBatchIds = curBatch.map(/* istanbul ignore next */ (x) => x.publishedfileid);
this.log.log(LogLevel.INFO, `Batching mod update for ids: ${curBatchIds.join(', ')}, because the maximum download size per batch (${maxDownloadSize}) would be exceed with the next mod. Current download size: ${curBatchFileSize}`);
if (!await this.updateMod(curBatchIds)) {
Expand All @@ -807,7 +807,7 @@ export class SteamCMD extends IService {
curBatch.push(mod);

// check if batch is full or exceeds size limit
curBatchFileSize = curBatch.reduce((acc, x) => acc + (x.file_size || 0), 0);
curBatchFileSize = curBatch.reduce((acc, x) => acc + Number(x.file_size || 0), 0);
if (curBatchFileSize >= maxDownloadSize || curBatch.length >= maxBatchSize) {
const curBatchIds = curBatch.map((x) => x.publishedfileid);
if (curBatchFileSize >= maxDownloadSize) {
Expand Down
2 changes: 1 addition & 1 deletion src/types/steamcmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface PublishedFileDetail {
creator_app_id: number;
consumer_app_id: number;
filename: string;
file_size: number;
file_size: string;
file_url: string;
hcontent_file: string;
preview_url: string;
Expand Down

0 comments on commit 5cfd16b

Please sign in to comment.