@jesusacd/mediafire 1.0.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/README.md +183 -0
- package/dist/api.d.ts +29 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +82 -0
- package/dist/api.js.map +1 -0
- package/dist/auth.d.ts +29 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +85 -0
- package/dist/auth.js.map +1 -0
- package/dist/client.d.ts +110 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +205 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/files.d.ts +56 -0
- package/dist/modules/files.d.ts.map +1 -0
- package/dist/modules/files.js +144 -0
- package/dist/modules/files.js.map +1 -0
- package/dist/modules/folders.d.ts +61 -0
- package/dist/modules/folders.d.ts.map +1 -0
- package/dist/modules/folders.js +129 -0
- package/dist/modules/folders.js.map +1 -0
- package/dist/modules/user.d.ts +40 -0
- package/dist/modules/user.d.ts.map +1 -0
- package/dist/modules/user.js +78 -0
- package/dist/modules/user.js.map +1 -0
- package/dist/types/index.d.ts +226 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +20 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +32 -0
- package/dist/utils.js.map +1 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# @jesusacd/mediafire
|
|
2
|
+
|
|
3
|
+
SDK para Node.js que permite interactuar con la API de MediaFire de forma programática.
|
|
4
|
+
|
|
5
|
+
## Instalación
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @jesusacd/mediafire
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { MediaFireClient } from "@jesusacd/mediafire";
|
|
15
|
+
|
|
16
|
+
const client = new MediaFireClient();
|
|
17
|
+
|
|
18
|
+
// Login
|
|
19
|
+
await client.login("email@example.com", "password");
|
|
20
|
+
|
|
21
|
+
// Obtener información del usuario
|
|
22
|
+
const user = await client.user.getInfo();
|
|
23
|
+
console.log(`¡Hola, ${user.displayName}!`);
|
|
24
|
+
|
|
25
|
+
// Obtener cuota de almacenamiento
|
|
26
|
+
const storage = await client.user.getStorage();
|
|
27
|
+
console.log(`Usado: ${storage.usedFormatted} / ${storage.totalFormatted}`);
|
|
28
|
+
|
|
29
|
+
// Listar archivos en la carpeta raíz
|
|
30
|
+
const content = await client.folders.getContent();
|
|
31
|
+
content.items.forEach((item) => {
|
|
32
|
+
console.log(`${item.isFolder ? "📁" : "📄"} ${item.name}`);
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## API Reference
|
|
37
|
+
|
|
38
|
+
### MediaFireClient
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const client = new MediaFireClient();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### Métodos de Autenticación
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// Login
|
|
48
|
+
const session = await client.login(email, password);
|
|
49
|
+
|
|
50
|
+
// Verificar si está autenticado
|
|
51
|
+
client.isAuthenticated(); // boolean
|
|
52
|
+
|
|
53
|
+
// Cerrar sesión
|
|
54
|
+
client.logout();
|
|
55
|
+
|
|
56
|
+
// Obtener/restaurar sesión
|
|
57
|
+
const session = client.getSession();
|
|
58
|
+
client.setSession(session);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Módulo User
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// Información del usuario
|
|
65
|
+
const user = await client.user.getInfo();
|
|
66
|
+
// { email, displayName, firstName, lastName, premium, validated, createdAt }
|
|
67
|
+
|
|
68
|
+
// Cuota de almacenamiento
|
|
69
|
+
const storage = await client.user.getStorage();
|
|
70
|
+
// { usedBytes, totalBytes, usedFormatted, totalFormatted, percentUsed }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Módulo Files
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
// Información de un archivo
|
|
77
|
+
const file = await client.files.getInfo("quickkey");
|
|
78
|
+
// { quickKey, name, size, sizeFormatted, mimeType, downloads, privacy }
|
|
79
|
+
|
|
80
|
+
// Enlaces de descarga
|
|
81
|
+
const links = await client.files.getLinks("quickkey");
|
|
82
|
+
// { directDownload, normalDownload, viewLink }
|
|
83
|
+
|
|
84
|
+
// Buscar archivos
|
|
85
|
+
const results = await client.files.search("documento.pdf");
|
|
86
|
+
// { query, items, total }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Módulo Folders
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// Listar contenido de carpeta (raíz por defecto)
|
|
93
|
+
const content = await client.folders.getContent();
|
|
94
|
+
const content = await client.folders.getContent("folderkey");
|
|
95
|
+
const content = await client.folders.getContent("folderkey", {
|
|
96
|
+
contentType: "files", // 'files' | 'folders' | 'all'
|
|
97
|
+
chunk: 1,
|
|
98
|
+
chunkSize: 100,
|
|
99
|
+
});
|
|
100
|
+
// { folderKey, items, hasMore, chunk }
|
|
101
|
+
|
|
102
|
+
// Solo archivos
|
|
103
|
+
const files = await client.folders.getFiles("folderkey");
|
|
104
|
+
|
|
105
|
+
// Solo carpetas
|
|
106
|
+
const folders = await client.folders.getFolders("folderkey");
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Manejo de Errores
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { MediaFireClient, MediaFireError } from "@jesusacd/mediafire";
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await client.login("email", "wrong-password");
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (error instanceof MediaFireError) {
|
|
118
|
+
console.log(`Error: ${error.message}`);
|
|
119
|
+
console.log(`Code: ${error.code}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Ejemplo Completo
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { MediaFireClient, MediaFireError } from "@JesusACD/mediafire";
|
|
128
|
+
|
|
129
|
+
async function main() {
|
|
130
|
+
const client = new MediaFireClient();
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
// Login
|
|
134
|
+
console.log("Iniciando sesión...");
|
|
135
|
+
await client.login(process.env.MF_EMAIL!, process.env.MF_PASSWORD!);
|
|
136
|
+
console.log("✅ Sesión iniciada");
|
|
137
|
+
|
|
138
|
+
// Usuario
|
|
139
|
+
const user = await client.user.getInfo();
|
|
140
|
+
console.log(`\n👤 Usuario: ${user.displayName}`);
|
|
141
|
+
console.log(` Email: ${user.email}`);
|
|
142
|
+
console.log(` Premium: ${user.premium ? "Sí" : "No"}`);
|
|
143
|
+
|
|
144
|
+
// Storage
|
|
145
|
+
const storage = await client.user.getStorage();
|
|
146
|
+
console.log(`\n💾 Almacenamiento:`);
|
|
147
|
+
console.log(
|
|
148
|
+
` Usado: ${storage.usedFormatted} / ${storage.totalFormatted}`,
|
|
149
|
+
);
|
|
150
|
+
console.log(` ${storage.percentUsed}% usado`);
|
|
151
|
+
|
|
152
|
+
// Archivos raíz
|
|
153
|
+
console.log(`\n📂 Carpeta raíz:`);
|
|
154
|
+
const content = await client.folders.getContent();
|
|
155
|
+
content.items.forEach((item) => {
|
|
156
|
+
const icon = item.isFolder ? "📁" : "📄";
|
|
157
|
+
const size = item.isFolder ? "" : ` (${(item as any).sizeFormatted})`;
|
|
158
|
+
console.log(` ${icon} ${item.name}${size}`);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Búsqueda
|
|
162
|
+
console.log(`\n🔍 Buscando archivos...`);
|
|
163
|
+
const results = await client.files.search("test");
|
|
164
|
+
console.log(` Encontrados: ${results.total} archivos`);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error instanceof MediaFireError) {
|
|
167
|
+
console.error(`❌ Error de MediaFire: ${error.message}`);
|
|
168
|
+
} else {
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
main();
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Requisitos
|
|
178
|
+
|
|
179
|
+
- Node.js >= 16.0.0
|
|
180
|
+
|
|
181
|
+
## Licencia
|
|
182
|
+
|
|
183
|
+
MIT
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal session state
|
|
3
|
+
*/
|
|
4
|
+
export interface InternalSession {
|
|
5
|
+
sessionToken: string;
|
|
6
|
+
secretKey: string;
|
|
7
|
+
time: string;
|
|
8
|
+
email: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* API call options
|
|
12
|
+
*/
|
|
13
|
+
export interface ApiCallOptions {
|
|
14
|
+
/** API version to use */
|
|
15
|
+
apiVersion?: string;
|
|
16
|
+
/** Request timeout in ms */
|
|
17
|
+
timeout?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Make an API call to MediaFire
|
|
21
|
+
*
|
|
22
|
+
* @param endpoint - API endpoint (e.g., 'user/get_info')
|
|
23
|
+
* @param params - Request parameters
|
|
24
|
+
* @param session - Session data for authenticated calls
|
|
25
|
+
* @param options - Additional options
|
|
26
|
+
* @returns Parsed API response
|
|
27
|
+
*/
|
|
28
|
+
export declare function apiCall<T = unknown>(endpoint: string, params?: Record<string, string | number | boolean | undefined>, session?: InternalSession | null, options?: ApiCallOptions): Promise<T>;
|
|
29
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAsB,OAAO,CAAC,CAAC,GAAG,OAAO,EACvC,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAM,EAClE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,EAChC,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,CAAC,CAAC,CAiFZ"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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.apiCall = apiCall;
|
|
7
|
+
/**
|
|
8
|
+
* MediaFire API Client - Low-level HTTP client
|
|
9
|
+
*/
|
|
10
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
11
|
+
const auth_1 = require("./auth");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
const API_BASE = 'https://www.mediafire.com/api';
|
|
15
|
+
const DEFAULT_API_VERSION = '1.3';
|
|
16
|
+
/**
|
|
17
|
+
* Make an API call to MediaFire
|
|
18
|
+
*
|
|
19
|
+
* @param endpoint - API endpoint (e.g., 'user/get_info')
|
|
20
|
+
* @param params - Request parameters
|
|
21
|
+
* @param session - Session data for authenticated calls
|
|
22
|
+
* @param options - Additional options
|
|
23
|
+
* @returns Parsed API response
|
|
24
|
+
*/
|
|
25
|
+
async function apiCall(endpoint, params = {}, session, options = {}) {
|
|
26
|
+
const apiVersion = options.apiVersion || DEFAULT_API_VERSION;
|
|
27
|
+
// Clean endpoint (remove .php if present)
|
|
28
|
+
const cleanEndpoint = endpoint.endsWith('.php') ? endpoint.slice(0, -4) : endpoint;
|
|
29
|
+
const url = `${API_BASE}/${apiVersion}/${cleanEndpoint}.php`;
|
|
30
|
+
// Build query params
|
|
31
|
+
const queryParams = new URLSearchParams();
|
|
32
|
+
queryParams.append('response_format', 'json');
|
|
33
|
+
// Add session token if available
|
|
34
|
+
if (session?.sessionToken) {
|
|
35
|
+
queryParams.append('session_token', session.sessionToken);
|
|
36
|
+
}
|
|
37
|
+
// Add all other params
|
|
38
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
39
|
+
if (value !== undefined && value !== null) {
|
|
40
|
+
queryParams.append(key, String(value));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
// Sort params alphabetically (required for signature)
|
|
44
|
+
const sortedParams = (0, utils_1.sortParams)(queryParams);
|
|
45
|
+
// Add signature for authenticated calls
|
|
46
|
+
if (session?.secretKey && session?.time) {
|
|
47
|
+
const uri = `/api/${apiVersion}/${cleanEndpoint}.php`;
|
|
48
|
+
const query = sortedParams.toString();
|
|
49
|
+
const signature = (0, auth_1.generateRequestSignature)(session.secretKey, session.time, uri, query);
|
|
50
|
+
sortedParams.append('signature', signature);
|
|
51
|
+
}
|
|
52
|
+
// Make request
|
|
53
|
+
const response = await (0, node_fetch_1.default)(url, {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: {
|
|
56
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
57
|
+
'User-Agent': 'MediaFire-SDK/1.0 (Node.js)'
|
|
58
|
+
},
|
|
59
|
+
body: sortedParams.toString()
|
|
60
|
+
});
|
|
61
|
+
const responseText = await response.text();
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
throw new types_1.MediaFireError(`API request failed: ${response.status}`, response.status, responseText);
|
|
64
|
+
}
|
|
65
|
+
let data;
|
|
66
|
+
try {
|
|
67
|
+
data = JSON.parse(responseText);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw new types_1.MediaFireError(`Invalid JSON response: ${responseText}`);
|
|
71
|
+
}
|
|
72
|
+
// Check for API-level errors
|
|
73
|
+
if (data.response?.result === 'Error') {
|
|
74
|
+
throw new types_1.MediaFireError(data.response?.message || 'Unknown MediaFire API error', data.response?.error, data);
|
|
75
|
+
}
|
|
76
|
+
// Handle secret key regeneration
|
|
77
|
+
if (data.response?.new_key === 'yes' && session) {
|
|
78
|
+
session.secretKey = (0, auth_1.regenerateSecretKey)(session.secretKey);
|
|
79
|
+
}
|
|
80
|
+
return data.response;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"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"}
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate SHA1 signature for authentication
|
|
3
|
+
* Signature is: SHA1(email + password + application_id)
|
|
4
|
+
*
|
|
5
|
+
* @param email - User email
|
|
6
|
+
* @param password - User password
|
|
7
|
+
* @param appId - Application ID
|
|
8
|
+
* @returns Hex-encoded SHA1 signature
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateSignature(email: string, password: string, appId: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Regenerate secret key using MediaFire's algorithm
|
|
13
|
+
* New key = (old_key * 16807) % 2147483647
|
|
14
|
+
*
|
|
15
|
+
* @param currentKey - Current secret key
|
|
16
|
+
* @returns New secret key
|
|
17
|
+
*/
|
|
18
|
+
export declare function regenerateSecretKey(currentKey: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Generate request signature for authenticated API calls
|
|
21
|
+
*
|
|
22
|
+
* @param secretKey - Current secret key
|
|
23
|
+
* @param time - Server time from login
|
|
24
|
+
* @param uri - API endpoint URI
|
|
25
|
+
* @param query - Query string (sorted)
|
|
26
|
+
* @returns MD5 signature
|
|
27
|
+
*/
|
|
28
|
+
export declare function generateRequestSignature(secretKey: string, time: string, uri: string, query: string): string;
|
|
29
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAMxF;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAI9D;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,MAAM,CAIR"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.generateSignature = generateSignature;
|
|
37
|
+
exports.regenerateSecretKey = regenerateSecretKey;
|
|
38
|
+
exports.generateRequestSignature = generateRequestSignature;
|
|
39
|
+
/**
|
|
40
|
+
* Authentication utilities for MediaFire API
|
|
41
|
+
*/
|
|
42
|
+
const crypto = __importStar(require("crypto"));
|
|
43
|
+
/**
|
|
44
|
+
* Generate SHA1 signature for authentication
|
|
45
|
+
* Signature is: SHA1(email + password + application_id)
|
|
46
|
+
*
|
|
47
|
+
* @param email - User email
|
|
48
|
+
* @param password - User password
|
|
49
|
+
* @param appId - Application ID
|
|
50
|
+
* @returns Hex-encoded SHA1 signature
|
|
51
|
+
*/
|
|
52
|
+
function generateSignature(email, password, appId) {
|
|
53
|
+
const sha1 = crypto.createHash('sha1');
|
|
54
|
+
sha1.update(email);
|
|
55
|
+
sha1.update(password);
|
|
56
|
+
sha1.update(appId);
|
|
57
|
+
return sha1.digest('hex');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Regenerate secret key using MediaFire's algorithm
|
|
61
|
+
* New key = (old_key * 16807) % 2147483647
|
|
62
|
+
*
|
|
63
|
+
* @param currentKey - Current secret key
|
|
64
|
+
* @returns New secret key
|
|
65
|
+
*/
|
|
66
|
+
function regenerateSecretKey(currentKey) {
|
|
67
|
+
const oldKey = parseInt(currentKey, 10);
|
|
68
|
+
const newKey = (oldKey * 16807) % 2147483647;
|
|
69
|
+
return String(newKey);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Generate request signature for authenticated API calls
|
|
73
|
+
*
|
|
74
|
+
* @param secretKey - Current secret key
|
|
75
|
+
* @param time - Server time from login
|
|
76
|
+
* @param uri - API endpoint URI
|
|
77
|
+
* @param query - Query string (sorted)
|
|
78
|
+
* @returns MD5 signature
|
|
79
|
+
*/
|
|
80
|
+
function generateRequestSignature(secretKey, time, uri, query) {
|
|
81
|
+
const secretKeyMod = parseInt(secretKey, 10) % 256;
|
|
82
|
+
const signatureBase = `${secretKeyMod}${time}${uri}?${query}`;
|
|
83
|
+
return crypto.createHash('md5').update(signatureBase).digest('hex');
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,8CAMC;AASD,kDAIC;AAWD,4DASC;AArDD;;GAEG;AACH,+CAAiC;AAEjC;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAAC,KAAa,EAAE,QAAgB,EAAE,KAAa;IAC9E,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,UAAkB;IACpD,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,UAAU,CAAC;IAC7C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,wBAAwB,CACtC,SAAiB,EACjB,IAAY,EACZ,GAAW,EACX,KAAa;IAEb,MAAM,YAAY,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC;IACnD,MAAM,aAAa,GAAG,GAAG,YAAY,GAAG,IAAI,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;IAC9D,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACtE,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { UserModule } from './modules/user';
|
|
2
|
+
import { FilesModule } from './modules/files';
|
|
3
|
+
import { FoldersModule } from './modules/folders';
|
|
4
|
+
import { MediaFireConfig, SessionData } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* MediaFire SDK Client
|
|
7
|
+
*
|
|
8
|
+
* Main entry point for interacting with MediaFire API.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { MediaFireClient } from '@JesusACD/mediafire';
|
|
13
|
+
*
|
|
14
|
+
* const client = new MediaFireClient();
|
|
15
|
+
*
|
|
16
|
+
* // Login
|
|
17
|
+
* await client.login('email@example.com', 'password');
|
|
18
|
+
*
|
|
19
|
+
* // Use modules
|
|
20
|
+
* const user = await client.user.getInfo();
|
|
21
|
+
* const files = await client.folders.getContent();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class MediaFireClient {
|
|
25
|
+
private config;
|
|
26
|
+
private session;
|
|
27
|
+
private _user?;
|
|
28
|
+
private _files?;
|
|
29
|
+
private _folders?;
|
|
30
|
+
/**
|
|
31
|
+
* Create a new MediaFire client
|
|
32
|
+
*
|
|
33
|
+
* @param config - Optional configuration
|
|
34
|
+
*/
|
|
35
|
+
constructor(config?: MediaFireConfig);
|
|
36
|
+
/**
|
|
37
|
+
* Authenticate with MediaFire
|
|
38
|
+
*
|
|
39
|
+
* @param email - User email
|
|
40
|
+
* @param password - User password
|
|
41
|
+
* @returns Session data
|
|
42
|
+
* @throws MediaFireError if authentication fails
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const session = await client.login('email@example.com', 'password');
|
|
47
|
+
* console.log(`Logged in as ${session.email}`);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
login(email: string, password: string): Promise<SessionData>;
|
|
51
|
+
/**
|
|
52
|
+
* Log out and clear session
|
|
53
|
+
*/
|
|
54
|
+
logout(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Check if client is authenticated
|
|
57
|
+
*
|
|
58
|
+
* @returns True if logged in
|
|
59
|
+
*/
|
|
60
|
+
isAuthenticated(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Get current session data
|
|
63
|
+
*
|
|
64
|
+
* @returns Session data or null if not authenticated
|
|
65
|
+
*/
|
|
66
|
+
getSession(): SessionData | null;
|
|
67
|
+
/**
|
|
68
|
+
* Set session data (for restoring a previous session)
|
|
69
|
+
*
|
|
70
|
+
* @param session - Session data to restore
|
|
71
|
+
*/
|
|
72
|
+
setSession(session: SessionData): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get internal session (for modules)
|
|
75
|
+
*/
|
|
76
|
+
private getInternalSession;
|
|
77
|
+
/**
|
|
78
|
+
* User operations module
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const user = await client.user.getInfo();
|
|
83
|
+
* const storage = await client.user.getStorage();
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
get user(): UserModule;
|
|
87
|
+
/**
|
|
88
|
+
* Files operations module
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const fileInfo = await client.files.getInfo('quickkey');
|
|
93
|
+
* const links = await client.files.getLinks('quickkey');
|
|
94
|
+
* const results = await client.files.search('query');
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
get files(): FilesModule;
|
|
98
|
+
/**
|
|
99
|
+
* Folders operations module
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const content = await client.folders.getContent();
|
|
104
|
+
* const files = await client.folders.getFiles('folderkey');
|
|
105
|
+
* const folders = await client.folders.getFolders('folderkey');
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
get folders(): FoldersModule;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAkB,MAAM,SAAS,CAAC;AAMvE;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,OAAO,CAAgC;IAG/C,OAAO,CAAC,KAAK,CAAC,CAAa;IAC3B,OAAO,CAAC,MAAM,CAAC,CAAc;IAC7B,OAAO,CAAC,QAAQ,CAAC,CAAgB;IAEjC;;;;OAIG;gBACS,MAAM,GAAE,eAAoB;IAQxC;;;;;;;;;;;;;OAaG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAoElE;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;;;OAIG;IACH,eAAe,IAAI,OAAO;IAI1B;;;;OAIG;IACH,UAAU,IAAI,WAAW,GAAG,IAAI;IAUhC;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAStC;;OAEG;IACH,OAAO,CAAC,kBAAkB,CAExB;IAEF;;;;;;;;OAQG;IACH,IAAI,IAAI,IAAI,UAAU,CAKrB;IAED;;;;;;;;;OASG;IACH,IAAI,KAAK,IAAI,WAAW,CAKvB;IAED;;;;;;;;;OASG;IACH,IAAI,OAAO,IAAI,aAAa,CAK3B;CACF"}
|