@marcuth/mediafire 1.3.0
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/LICENSE +21 -0
- package/README.md +228 -0
- package/dist/enums/action-on-duplicate-file.d.ts +5 -0
- package/dist/enums/action-on-duplicate-file.js +9 -0
- package/dist/enums/content-type.d.ts +5 -0
- package/dist/enums/content-type.js +9 -0
- package/dist/enums/details.d.ts +5 -0
- package/dist/enums/details.js +9 -0
- package/dist/enums/index.d.ts +6 -0
- package/dist/enums/index.js +22 -0
- package/dist/enums/order-by.d.ts +6 -0
- package/dist/enums/order-by.js +10 -0
- package/dist/enums/order-direction.d.ts +4 -0
- package/dist/enums/order-direction.js +8 -0
- package/dist/enums/upload-status.d.ts +13 -0
- package/dist/enums/upload-status.js +17 -0
- package/dist/error.d.ts +3 -0
- package/dist/error.js +10 -0
- package/dist/files-service.d.ts +154 -0
- package/dist/files-service.js +107 -0
- package/dist/folders-service.d.ts +165 -0
- package/dist/folders-service.js +65 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/interfaces/files/get-file-info.d.ts +32 -0
- package/dist/interfaces/files/get-file-info.js +2 -0
- package/dist/interfaces/files/get-links.d.ts +17 -0
- package/dist/interfaces/files/get-links.js +2 -0
- package/dist/interfaces/files/index.d.ts +3 -0
- package/dist/interfaces/files/index.js +19 -0
- package/dist/interfaces/files/poll-upload.d.ts +20 -0
- package/dist/interfaces/files/poll-upload.js +2 -0
- package/dist/interfaces/files/upload-file.d.ts +13 -0
- package/dist/interfaces/files/upload-file.js +2 -0
- package/dist/interfaces/folders/get-contents.d.ts +53 -0
- package/dist/interfaces/folders/get-contents.js +2 -0
- package/dist/interfaces/folders/get-folder-info.d.ts +19 -0
- package/dist/interfaces/folders/get-folder-info.js +2 -0
- package/dist/interfaces/folders/index.d.ts +2 -0
- package/dist/interfaces/folders/index.js +18 -0
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/index.js +19 -0
- package/dist/interfaces/user/get-session-token-response.d.ts +12 -0
- package/dist/interfaces/user/get-session-token-response.js +2 -0
- package/dist/interfaces/user/index.d.ts +1 -0
- package/dist/interfaces/user/index.js +17 -0
- package/dist/mediafire.d.ts +35 -0
- package/dist/mediafire.js +96 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.js +9 -0
- package/dist/utils/delay.d.ts +1 -0
- package/dist/utils/delay.js +6 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/package.json +33 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Mediafire = void 0;
|
|
7
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const folders_service_1 = require("./folders-service");
|
|
12
|
+
const files_service_1 = require("./files-service");
|
|
13
|
+
class Mediafire {
|
|
14
|
+
constructor({ email, password, appId = utils_1.defaultAppId }) {
|
|
15
|
+
this.api = axios_1.default.create({ baseURL: utils_1.baseUrl });
|
|
16
|
+
this.email = email;
|
|
17
|
+
this.password = password;
|
|
18
|
+
this.appId = appId;
|
|
19
|
+
this.folders = new folders_service_1.FoldersService(this);
|
|
20
|
+
this.files = new files_service_1.FilesService(this, utils_1.filePollDefaultDelay);
|
|
21
|
+
}
|
|
22
|
+
generateAndPutLogInSignature(searchParams) {
|
|
23
|
+
const sha1 = node_crypto_1.default.createHash("sha1");
|
|
24
|
+
sha1.update(this.email, "ascii");
|
|
25
|
+
sha1.update(this.password, "ascii");
|
|
26
|
+
sha1.update(this.appId, "ascii");
|
|
27
|
+
const signature = sha1.digest("hex");
|
|
28
|
+
searchParams.append("signature", signature);
|
|
29
|
+
}
|
|
30
|
+
async ensureCredentials() {
|
|
31
|
+
if (!this.accessToken || this.secretKey || !this.sessionTime) {
|
|
32
|
+
await this.logIn();
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
accessToken: this.accessToken,
|
|
36
|
+
secretKey: this.secretKey,
|
|
37
|
+
sessionTime: this.sessionTime,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async logIn() {
|
|
41
|
+
const path = "/user/get_session_token.php";
|
|
42
|
+
const searchParams = new URLSearchParams();
|
|
43
|
+
searchParams.append("application_id", this.appId);
|
|
44
|
+
searchParams.append("token_version", utils_1.tokenVersion.toString());
|
|
45
|
+
searchParams.append("response_format", "json");
|
|
46
|
+
searchParams.append("email", this.email);
|
|
47
|
+
searchParams.append("password", this.password);
|
|
48
|
+
this.generateAndPutLogInSignature(searchParams);
|
|
49
|
+
const response = await this.api.post(path, null, {
|
|
50
|
+
params: searchParams
|
|
51
|
+
});
|
|
52
|
+
const data = response.data.response;
|
|
53
|
+
this.accessToken = data.session_token;
|
|
54
|
+
this.secretKey = data.secret_key;
|
|
55
|
+
this.sessionTime = data.time;
|
|
56
|
+
}
|
|
57
|
+
async request(action, params = {}, body) {
|
|
58
|
+
const { accessToken, secretKey, sessionTime } = await this.ensureCredentials();
|
|
59
|
+
const path = `${action}.php`;
|
|
60
|
+
const uri = `/api/${utils_1.apiVersion}/${action}.php`;
|
|
61
|
+
const searchParams = new URLSearchParams();
|
|
62
|
+
for (const paramKey in params) {
|
|
63
|
+
const paramValue = params[paramKey];
|
|
64
|
+
if (paramValue) {
|
|
65
|
+
searchParams.append(paramKey, paramValue);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
searchParams.append("response_format", "json");
|
|
69
|
+
searchParams.append("session_token", accessToken);
|
|
70
|
+
searchParams.sort();
|
|
71
|
+
let query = searchParams.toString();
|
|
72
|
+
const secretKeyMod = BigInt(secretKey) % 256n;
|
|
73
|
+
const signatureBase = `${secretKeyMod}${sessionTime}${uri}?${query}`;
|
|
74
|
+
const signature = node_crypto_1.default.createHash("md5").update(signatureBase).digest("hex");
|
|
75
|
+
const urlWithQuery = `${path}?${query}&signature=${signature}`;
|
|
76
|
+
const headers = {};
|
|
77
|
+
let payload = body;
|
|
78
|
+
if (body instanceof form_data_1.default) {
|
|
79
|
+
Object.assign(headers, body.getHeaders());
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
83
|
+
if (!body) {
|
|
84
|
+
payload = query + `&signature=${signature}`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const response = await this.api.post(urlWithQuery, payload, { headers: headers });
|
|
88
|
+
const responseData = response.data.response;
|
|
89
|
+
if (responseData.new_key === "yes") {
|
|
90
|
+
const current = BigInt(secretKey);
|
|
91
|
+
this.secretKey = String((current * 16807n) % 2147483647n);
|
|
92
|
+
}
|
|
93
|
+
return response.data;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.Mediafire = Mediafire;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const apiVersion = "1.3";
|
|
2
|
+
export declare const defaultAppId = "42511";
|
|
3
|
+
export declare const baseUrl = "https://www.mediafire.com/api/1.3/";
|
|
4
|
+
export declare const tokenVersion = 2;
|
|
5
|
+
export declare const rootFolderKey = "myfiles";
|
|
6
|
+
export declare const filePollDefaultDelay = 5000;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filePollDefaultDelay = exports.rootFolderKey = exports.tokenVersion = exports.baseUrl = exports.defaultAppId = exports.apiVersion = void 0;
|
|
4
|
+
exports.apiVersion = "1.3";
|
|
5
|
+
exports.defaultAppId = "42511";
|
|
6
|
+
exports.baseUrl = `https://www.mediafire.com/api/${exports.apiVersion}/`;
|
|
7
|
+
exports.tokenVersion = 2;
|
|
8
|
+
exports.rootFolderKey = "myfiles";
|
|
9
|
+
exports.filePollDefaultDelay = 5000;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function delay(ms: number): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./constants";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@marcuth/mediafire",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "A simple wrapper for the Mediafire API",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/*",
|
|
10
|
+
"!/**/__tests__"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"mediafire",
|
|
17
|
+
"wrapper",
|
|
18
|
+
"api",
|
|
19
|
+
"file upload"
|
|
20
|
+
],
|
|
21
|
+
"author": "Marcuth",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"type": "commonjs",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^25.0.3",
|
|
26
|
+
"ts-node": "^10.9.2",
|
|
27
|
+
"typescript": "^5.9.3"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"axios": "^1.13.2",
|
|
31
|
+
"form-data": "^4.0.5"
|
|
32
|
+
}
|
|
33
|
+
}
|