steamutils 1.4.98 → 1.4.99
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +14 -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,15 @@ export default class SteamUser {
|
|
5975
5976
|
}
|
5976
5977
|
|
5977
5978
|
async uploadAvatar(filePath) {
|
5979
|
+
let deleteFile = false;
|
5980
|
+
if (typeof filePath === "string" && filePath.startsWith("http")) {
|
5981
|
+
deleteFile = true;
|
5982
|
+
filePath = await downloadImage(url, `TempImg_${Date.now()}.png`);
|
5983
|
+
if (!filePath) {
|
5984
|
+
return;
|
5985
|
+
}
|
5986
|
+
}
|
5987
|
+
|
5978
5988
|
const readable = fs.createReadStream(filePath);
|
5979
5989
|
const result = await this._httpRequest({
|
5980
5990
|
url: "actions/FileUploader/",
|
@@ -5991,6 +6001,9 @@ export default class SteamUser {
|
|
5991
6001
|
},
|
5992
6002
|
});
|
5993
6003
|
readable.close();
|
6004
|
+
if (deleteFile) {
|
6005
|
+
fs.unlink(filePath, () => {});
|
6006
|
+
}
|
5994
6007
|
if (result instanceof ResponseError) {
|
5995
6008
|
return result;
|
5996
6009
|
}
|
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
|
+
}
|