steamutils 1.4.98 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +18 -1
- package/package.json +1 -1
- package/utils.js +26 -0
package/index.js
CHANGED
@@ -7,7 +7,7 @@ import SteamID from "steamid";
|
|
7
7
|
import URL from "url";
|
8
8
|
import Url from "url-parse";
|
9
9
|
import qs from "qs";
|
10
|
-
import { console_log, getCleanObject, JSON_parse, JSON_stringify, removeSpaceKeys, secretAsBuffer, sleep } from "./utils.js";
|
10
|
+
import { console_log, downloadImage, getCleanObject, JSON_parse, JSON_stringify, removeSpaceKeys, secretAsBuffer, sleep } from "./utils.js";
|
11
11
|
import { Header, request } from "./axios.js";
|
12
12
|
import { getTableHasHeaders, querySelectorAll, table2json } from "./cheerio.js";
|
13
13
|
import { getJSObjectFronXML } from "./xml2json.js";
|
@@ -23,6 +23,7 @@ import { AppID_CSGO, E1GameBanOnRecord, E1VACBanOnRecord, EActivityType, ECommen
|
|
23
23
|
import SteamTotp from "steam-totp";
|
24
24
|
import { SteamProto, SteamProtoType } from "./steamproto.js";
|
25
25
|
import EventEmitter from "node:events";
|
26
|
+
import * as url from "node:url";
|
26
27
|
|
27
28
|
const eventEmitter = (globalThis.steamUserEventEmitter = new EventEmitter());
|
28
29
|
|
@@ -5975,6 +5976,19 @@ export default class SteamUser {
|
|
5975
5976
|
}
|
5976
5977
|
|
5977
5978
|
async uploadAvatar(filePath) {
|
5979
|
+
if (typeof filePath !== "string") {
|
5980
|
+
console.error("Invalid file path", filePath);
|
5981
|
+
return;
|
5982
|
+
}
|
5983
|
+
let deleteFile = false;
|
5984
|
+
if (filePath.startsWith("http")) {
|
5985
|
+
deleteFile = true;
|
5986
|
+
filePath = await downloadImage(filePath, `TempImg_${Date.now()}.png`);
|
5987
|
+
if (!filePath) {
|
5988
|
+
return;
|
5989
|
+
}
|
5990
|
+
}
|
5991
|
+
|
5978
5992
|
const readable = fs.createReadStream(filePath);
|
5979
5993
|
const result = await this._httpRequest({
|
5980
5994
|
url: "actions/FileUploader/",
|
@@ -5991,6 +6005,9 @@ export default class SteamUser {
|
|
5991
6005
|
},
|
5992
6006
|
});
|
5993
6007
|
readable.close();
|
6008
|
+
if (deleteFile) {
|
6009
|
+
fs.unlink(filePath, () => {});
|
6010
|
+
}
|
5994
6011
|
if (result instanceof ResponseError) {
|
5995
6012
|
return result;
|
5996
6013
|
}
|
package/package.json
CHANGED
package/utils.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import moment from "moment";
|
2
2
|
import SteamTotp from "steam-totp";
|
3
3
|
import { EAuthTokenPlatformType } from "./const.js";
|
4
|
+
import fs from "fs";
|
5
|
+
import axios from "axios";
|
4
6
|
|
5
7
|
const isBrowser = typeof window !== "undefined";
|
6
8
|
const g_rgCurrencyData = {
|
@@ -1022,3 +1024,27 @@ export function calculateAccountXP(currentXp, xpEarnedThisWeek, xpEarned, nextXp
|
|
1022
1024
|
})() || {}
|
1023
1025
|
);
|
1024
1026
|
}
|
1027
|
+
|
1028
|
+
export async function downloadImage(url, filePath) {
|
1029
|
+
let response = null;
|
1030
|
+
try {
|
1031
|
+
response = await axios.get(url, {
|
1032
|
+
responseType: "arraybuffer",
|
1033
|
+
});
|
1034
|
+
} catch (e) {
|
1035
|
+
/* empty */
|
1036
|
+
}
|
1037
|
+
|
1038
|
+
if (!response || !response.data) {
|
1039
|
+
return;
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
return new Promise((resolve) => {
|
1043
|
+
fs.writeFile(filePath, response.data, (err) => {
|
1044
|
+
if (err) {
|
1045
|
+
resolve();
|
1046
|
+
}
|
1047
|
+
resolve(filePath);
|
1048
|
+
});
|
1049
|
+
});
|
1050
|
+
}
|