@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/dist/client.js ADDED
@@ -0,0 +1,205 @@
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.MediaFireClient = void 0;
7
+ /**
8
+ * MediaFire Client - Main SDK entry point
9
+ */
10
+ const node_fetch_1 = __importDefault(require("node-fetch"));
11
+ const auth_1 = require("./auth");
12
+ const utils_1 = require("./utils");
13
+ const user_1 = require("./modules/user");
14
+ const files_1 = require("./modules/files");
15
+ const folders_1 = require("./modules/folders");
16
+ const types_1 = require("./types");
17
+ const API_BASE = 'https://www.mediafire.com/api';
18
+ const DEFAULT_APP_ID = '42511';
19
+ const DEFAULT_API_VERSION = '1.3';
20
+ /**
21
+ * MediaFire SDK Client
22
+ *
23
+ * Main entry point for interacting with MediaFire API.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import { MediaFireClient } from '@JesusACD/mediafire';
28
+ *
29
+ * const client = new MediaFireClient();
30
+ *
31
+ * // Login
32
+ * await client.login('email@example.com', 'password');
33
+ *
34
+ * // Use modules
35
+ * const user = await client.user.getInfo();
36
+ * const files = await client.folders.getContent();
37
+ * ```
38
+ */
39
+ class MediaFireClient {
40
+ /**
41
+ * Create a new MediaFire client
42
+ *
43
+ * @param config - Optional configuration
44
+ */
45
+ constructor(config = {}) {
46
+ this.session = null;
47
+ /**
48
+ * Get internal session (for modules)
49
+ */
50
+ this.getInternalSession = () => {
51
+ return this.session;
52
+ };
53
+ this.config = {
54
+ appId: config.appId || DEFAULT_APP_ID,
55
+ apiVersion: config.apiVersion || DEFAULT_API_VERSION,
56
+ timeout: config.timeout || 30000
57
+ };
58
+ }
59
+ /**
60
+ * Authenticate with MediaFire
61
+ *
62
+ * @param email - User email
63
+ * @param password - User password
64
+ * @returns Session data
65
+ * @throws MediaFireError if authentication fails
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const session = await client.login('email@example.com', 'password');
70
+ * console.log(`Logged in as ${session.email}`);
71
+ * ```
72
+ */
73
+ async login(email, password) {
74
+ // Build login params
75
+ const params = new URLSearchParams();
76
+ params.append('application_id', this.config.appId);
77
+ params.append('email', email);
78
+ params.append('password', password);
79
+ params.append('response_format', 'json');
80
+ params.append('token_version', '2');
81
+ // Sort params alphabetically
82
+ const sortedParams = (0, utils_1.sortParams)(params);
83
+ // Generate signature
84
+ const signature = (0, auth_1.generateSignature)(email, password, this.config.appId);
85
+ // Add signature to query
86
+ const query = sortedParams.toString() + '&signature=' + signature;
87
+ // Make login request
88
+ const response = await (0, node_fetch_1.default)(`${API_BASE}/${this.config.apiVersion}/user/get_session_token.php`, {
89
+ method: 'POST',
90
+ headers: {
91
+ 'Content-Type': 'application/x-www-form-urlencoded',
92
+ 'User-Agent': 'MediaFire-SDK/1.0 (Node.js)'
93
+ },
94
+ body: query
95
+ });
96
+ const data = await response.json();
97
+ if (data.response?.result !== 'Success') {
98
+ throw new types_1.MediaFireError(data.response?.message || 'Authentication failed', data.response?.error, data);
99
+ }
100
+ // Store session
101
+ this.session = {
102
+ sessionToken: data.response.session_token || '',
103
+ secretKey: data.response.secret_key || '',
104
+ time: data.response.time || '',
105
+ email
106
+ };
107
+ return {
108
+ sessionToken: this.session.sessionToken,
109
+ secretKey: this.session.secretKey,
110
+ time: this.session.time,
111
+ email
112
+ };
113
+ }
114
+ /**
115
+ * Log out and clear session
116
+ */
117
+ logout() {
118
+ this.session = null;
119
+ }
120
+ /**
121
+ * Check if client is authenticated
122
+ *
123
+ * @returns True if logged in
124
+ */
125
+ isAuthenticated() {
126
+ return this.session !== null;
127
+ }
128
+ /**
129
+ * Get current session data
130
+ *
131
+ * @returns Session data or null if not authenticated
132
+ */
133
+ getSession() {
134
+ if (!this.session)
135
+ return null;
136
+ return {
137
+ sessionToken: this.session.sessionToken,
138
+ secretKey: this.session.secretKey,
139
+ time: this.session.time,
140
+ email: this.session.email
141
+ };
142
+ }
143
+ /**
144
+ * Set session data (for restoring a previous session)
145
+ *
146
+ * @param session - Session data to restore
147
+ */
148
+ setSession(session) {
149
+ this.session = {
150
+ sessionToken: session.sessionToken,
151
+ secretKey: session.secretKey,
152
+ time: session.time,
153
+ email: session.email
154
+ };
155
+ }
156
+ /**
157
+ * User operations module
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const user = await client.user.getInfo();
162
+ * const storage = await client.user.getStorage();
163
+ * ```
164
+ */
165
+ get user() {
166
+ if (!this._user) {
167
+ this._user = new user_1.UserModule(this.getInternalSession);
168
+ }
169
+ return this._user;
170
+ }
171
+ /**
172
+ * Files operations module
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const fileInfo = await client.files.getInfo('quickkey');
177
+ * const links = await client.files.getLinks('quickkey');
178
+ * const results = await client.files.search('query');
179
+ * ```
180
+ */
181
+ get files() {
182
+ if (!this._files) {
183
+ this._files = new files_1.FilesModule(this.getInternalSession);
184
+ }
185
+ return this._files;
186
+ }
187
+ /**
188
+ * Folders operations module
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const content = await client.folders.getContent();
193
+ * const files = await client.folders.getFiles('folderkey');
194
+ * const folders = await client.folders.getFolders('folderkey');
195
+ * ```
196
+ */
197
+ get folders() {
198
+ if (!this._folders) {
199
+ this._folders = new folders_1.FoldersModule(this.getInternalSession);
200
+ }
201
+ return this._folders;
202
+ }
203
+ }
204
+ exports.MediaFireClient = MediaFireClient;
205
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AAAA;;GAEG;AACH,4DAA+B;AAC/B,iCAA2C;AAC3C,mCAAqC;AAErC,yCAA4C;AAC5C,2CAA8C;AAC9C,+CAAkD;AAClD,mCAAuE;AAEvE,MAAM,QA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MC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @JesusACD/mediafire - MediaFire SDK for Node.js
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export { MediaFireClient } from './client';
7
+ export * from './types';
8
+ export { UserModule } from './modules/user';
9
+ export { FilesModule } from './modules/files';
10
+ export { FoldersModule, GetContentOptions } from './modules/folders';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /**
3
+ * @JesusACD/mediafire - MediaFire SDK for Node.js
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.FoldersModule = exports.FilesModule = exports.UserModule = exports.MediaFireClient = void 0;
23
+ // Main client
24
+ var client_1 = require("./client");
25
+ Object.defineProperty(exports, "MediaFireClient", { enumerable: true, get: function () { return client_1.MediaFireClient; } });
26
+ // Types
27
+ __exportStar(require("./types"), exports);
28
+ // Modules (for advanced usage)
29
+ var user_1 = require("./modules/user");
30
+ Object.defineProperty(exports, "UserModule", { enumerable: true, get: function () { return user_1.UserModule; } });
31
+ var files_1 = require("./modules/files");
32
+ Object.defineProperty(exports, "FilesModule", { enumerable: true, get: function () { return files_1.FilesModule; } });
33
+ var folders_1 = require("./modules/folders");
34
+ Object.defineProperty(exports, "FoldersModule", { enumerable: true, get: function () { return folders_1.FoldersModule; } });
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;AAEH,cAAc;AACd,mCAA2C;AAAlC,yGAAA,eAAe,OAAA;AAExB,QAAQ;AACR,0CAAwB;AAExB,+BAA+B;AAC/B,uCAA4C;AAAnC,kGAAA,UAAU,OAAA;AACnB,yCAA8C;AAArC,oGAAA,WAAW,OAAA;AACpB,6CAAqE;AAA5D,wGAAA,aAAa,OAAA"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Files Module - File operations
3
+ */
4
+ import { InternalSession } from '../api';
5
+ import { FileInfo, DownloadLinks, SearchResults } from '../types';
6
+ /**
7
+ * Files module for file operations
8
+ */
9
+ export declare class FilesModule {
10
+ private getSession;
11
+ constructor(getSession: () => InternalSession | null);
12
+ /**
13
+ * Get file information
14
+ *
15
+ * @param quickKey - File quick key
16
+ * @returns File info
17
+ * @throws MediaFireError if not authenticated or API error
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const file = await client.files.getInfo('abc123quickkey');
22
+ * console.log(`File: ${file.name} (${file.sizeFormatted})`);
23
+ * ```
24
+ */
25
+ getInfo(quickKey: string): Promise<FileInfo>;
26
+ /**
27
+ * Get download links for a file
28
+ *
29
+ * @param quickKey - File quick key
30
+ * @returns Download links
31
+ * @throws MediaFireError if not authenticated or API error
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const links = await client.files.getLinks('abc123quickkey');
36
+ * console.log(`Download: ${links.directDownload}`);
37
+ * ```
38
+ */
39
+ getLinks(quickKey: string): Promise<DownloadLinks>;
40
+ /**
41
+ * Search for files
42
+ *
43
+ * @param query - Search query
44
+ * @returns Search results
45
+ * @throws MediaFireError if not authenticated or API error
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const results = await client.files.search('document.pdf');
50
+ * console.log(`Found ${results.total} files`);
51
+ * results.items.forEach(item => console.log(item.name));
52
+ * ```
53
+ */
54
+ search(query: string): Promise<SearchResults>;
55
+ }
56
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/modules/files.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAW,eAAe,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAe,aAAa,EAAE,MAAM,UAAU,CAAC;AAG/E;;GAEG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,MAAM,eAAe,GAAG,IAAI;IAE5D;;;;;;;;;;;;OAYG;IACG,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAqDlD;;;;;;;;;;;;OAYG;IACG,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA2BxD;;;;;;;;;;;;;OAaG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CA8DpD"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilesModule = void 0;
4
+ /**
5
+ * Files Module - File operations
6
+ */
7
+ const api_1 = require("../api");
8
+ const utils_1 = require("../utils");
9
+ /**
10
+ * Files module for file operations
11
+ */
12
+ class FilesModule {
13
+ constructor(getSession) {
14
+ this.getSession = getSession;
15
+ }
16
+ /**
17
+ * Get file information
18
+ *
19
+ * @param quickKey - File quick key
20
+ * @returns File info
21
+ * @throws MediaFireError if not authenticated or API error
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const file = await client.files.getInfo('abc123quickkey');
26
+ * console.log(`File: ${file.name} (${file.sizeFormatted})`);
27
+ * ```
28
+ */
29
+ async getInfo(quickKey) {
30
+ const session = this.getSession();
31
+ if (!session) {
32
+ throw new Error('Not authenticated. Please call login() first.');
33
+ }
34
+ const response = await (0, api_1.apiCall)('file/get_info', {
35
+ quick_key: quickKey
36
+ }, session);
37
+ const info = response.file_info || response.file_infos?.[0];
38
+ if (!info) {
39
+ throw new Error(`File not found: ${quickKey}`);
40
+ }
41
+ const size = parseInt(info.size || '0', 10);
42
+ return {
43
+ quickKey: info.quickkey,
44
+ name: info.filename,
45
+ size,
46
+ sizeFormatted: (0, utils_1.formatBytes)(size),
47
+ created: info.created,
48
+ mimeType: info.mimetype,
49
+ downloads: parseInt(info.downloads || '0', 10),
50
+ privacy: info.privacy,
51
+ passwordProtected: info.password_protected === 'yes'
52
+ };
53
+ }
54
+ /**
55
+ * Get download links for a file
56
+ *
57
+ * @param quickKey - File quick key
58
+ * @returns Download links
59
+ * @throws MediaFireError if not authenticated or API error
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const links = await client.files.getLinks('abc123quickkey');
64
+ * console.log(`Download: ${links.directDownload}`);
65
+ * ```
66
+ */
67
+ async getLinks(quickKey) {
68
+ const session = this.getSession();
69
+ if (!session) {
70
+ throw new Error('Not authenticated. Please call login() first.');
71
+ }
72
+ const response = await (0, api_1.apiCall)('file/get_links', {
73
+ quick_key: quickKey,
74
+ link_type: 'direct_download'
75
+ }, session);
76
+ const linkInfo = response.links?.[0] || {};
77
+ return {
78
+ directDownload: linkInfo.direct_download,
79
+ normalDownload: linkInfo.normal_download,
80
+ viewLink: `https://www.mediafire.com/file/${quickKey}`
81
+ };
82
+ }
83
+ /**
84
+ * Search for files
85
+ *
86
+ * @param query - Search query
87
+ * @returns Search results
88
+ * @throws MediaFireError if not authenticated or API error
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const results = await client.files.search('document.pdf');
93
+ * console.log(`Found ${results.total} files`);
94
+ * results.items.forEach(item => console.log(item.name));
95
+ * ```
96
+ */
97
+ async search(query) {
98
+ const session = this.getSession();
99
+ if (!session) {
100
+ throw new Error('Not authenticated. Please call login() first.');
101
+ }
102
+ const response = await (0, api_1.apiCall)('folder/search', {
103
+ search_text: query,
104
+ filter: 'everything'
105
+ }, session);
106
+ const results = response.results || [];
107
+ const items = results.map(item => {
108
+ if (item.type === 'folder') {
109
+ return {
110
+ id: item.folderkey || '',
111
+ folderKey: item.folderkey || '',
112
+ name: item.name || '',
113
+ created: undefined,
114
+ fileCount: 0,
115
+ folderCount: 0,
116
+ parentFolderKey: item.parent_folderkey,
117
+ parentName: item.parent_name,
118
+ isFolder: true
119
+ };
120
+ }
121
+ else {
122
+ const size = parseInt(item.size || '0', 10);
123
+ return {
124
+ id: item.quickkey || '',
125
+ quickKey: item.quickkey || '',
126
+ name: item.filename || item.name || '',
127
+ size,
128
+ sizeFormatted: (0, utils_1.formatBytes)(size),
129
+ mimeType: item.mimetype,
130
+ parentFolderKey: item.parent_folderkey,
131
+ parentName: item.parent_name,
132
+ isFolder: false
133
+ };
134
+ }
135
+ });
136
+ return {
137
+ query,
138
+ items,
139
+ total: items.length
140
+ };
141
+ }
142
+ }
143
+ exports.FilesModule = FilesModule;
144
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/modules/files.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,gCAAkD;AAElD,oCAAuC;AAEvC;;GAEG;AACH,MAAa,WAAW;IACtB,YAAo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;oBACZ,WAAW,EAAE,CAAC;oBACd,eAAe,EAAE,IAAI,CAAC,gBAAgB;oBACtC,UAAU,EAAE,IAAI,CAAC,WAAW;oBAC5B,QAAQ,EAAE,IAAa;iBACxB,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;gBAC5C,OAAO;oBACL,EAAE,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE;oBACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE;oBAC7B,IAAI,EAAE,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,IAAI,EAAE;oBACtC,IAAI;oBACJ,aAAa,EAAE,IAAA,mBAAW,EAAC,IAAI,CAAC;oBAChC,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,eAAe,EAAE,IAAI,CAAC,gBAAgB;oBACtC,UAAU,EAAE,IAAI,CAAC,WAAW;oBAC5B,QAAQ,EAAE,KAAc;iBACzB,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,KAAK;YACL,KAAK;YACL,KAAK,EAAE,KAAK,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;CACF;AAzLD,kCAyLC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Folders Module - Folder operations
3
+ */
4
+ import { InternalSession } from '../api';
5
+ import { FolderContent, FileItem, FolderItem } from '../types';
6
+ /**
7
+ * Options for listing folder content
8
+ */
9
+ export interface GetContentOptions {
10
+ /** Content type: 'files', 'folders', or 'all' (default) */
11
+ contentType?: 'files' | 'folders' | 'all';
12
+ /** Chunk number for pagination (default: 1) */
13
+ chunk?: number;
14
+ /** Number of items per chunk (default: 100) */
15
+ chunkSize?: number;
16
+ }
17
+ /**
18
+ * Folders module for folder operations
19
+ */
20
+ export declare class FoldersModule {
21
+ private getSession;
22
+ constructor(getSession: () => InternalSession | null);
23
+ /**
24
+ * Get folder content (files and/or folders)
25
+ *
26
+ * @param folderKey - Folder key (default: 'myfiles' for root)
27
+ * @param options - Content options
28
+ * @returns Folder content
29
+ * @throws MediaFireError if not authenticated or API error
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * // List root folder
34
+ * const content = await client.folders.getContent();
35
+ * content.items.forEach(item => {
36
+ * console.log(`${item.isFolder ? '📁' : '📄'} ${item.name}`);
37
+ * });
38
+ *
39
+ * // List specific folder
40
+ * const subContent = await client.folders.getContent('abc123folderkey');
41
+ * ```
42
+ */
43
+ getContent(folderKey?: string, options?: GetContentOptions): Promise<FolderContent>;
44
+ /**
45
+ * Get only files in a folder
46
+ *
47
+ * @param folderKey - Folder key (default: 'myfiles' for root)
48
+ * @param options - Pagination options
49
+ * @returns Array of files
50
+ */
51
+ getFiles(folderKey?: string, options?: Omit<GetContentOptions, 'contentType'>): Promise<FileItem[]>;
52
+ /**
53
+ * Get only folders in a folder
54
+ *
55
+ * @param folderKey - Folder key (default: 'myfiles' for root)
56
+ * @param options - Pagination options
57
+ * @returns Array of folders
58
+ */
59
+ getFolders(folderKey?: string, options?: Omit<GetContentOptions, 'contentType'>): Promise<FolderItem[]>;
60
+ }
61
+ //# sourceMappingURL=folders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"folders.d.ts","sourceRoot":"","sources":["../../src/modules/folders.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAW,eAAe,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,aAAa,EAAe,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG5E;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,2DAA2D;IAC3D,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,KAAK,CAAC;IAC1C,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,MAAM,eAAe,GAAG,IAAI;IAE5D;;;;;;;;;;;;;;;;;;;OAmBG;IACG,UAAU,CAAC,SAAS,GAAE,MAAkB,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,aAAa,CAAC;IA8GxG;;;;;;OAMG;IACG,QAAQ,CAAC,SAAS,GAAE,MAAkB,EAAE,OAAO,GAAE,IAAI,CAAC,iBAAiB,EAAE,aAAa,CAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAKxH;;;;;;OAMG;IACG,UAAU,CAAC,SAAS,GAAE,MAAkB,EAAE,OAAO,GAAE,IAAI,CAAC,iBAAiB,EAAE,aAAa,CAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CAI7H"}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FoldersModule = void 0;
4
+ /**
5
+ * Folders Module - Folder operations
6
+ */
7
+ const api_1 = require("../api");
8
+ const utils_1 = require("../utils");
9
+ /**
10
+ * Folders module for folder operations
11
+ */
12
+ class FoldersModule {
13
+ constructor(getSession) {
14
+ this.getSession = getSession;
15
+ }
16
+ /**
17
+ * Get folder content (files and/or folders)
18
+ *
19
+ * @param folderKey - Folder key (default: 'myfiles' for root)
20
+ * @param options - Content options
21
+ * @returns Folder content
22
+ * @throws MediaFireError if not authenticated or API error
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // List root folder
27
+ * const content = await client.folders.getContent();
28
+ * content.items.forEach(item => {
29
+ * console.log(`${item.isFolder ? '📁' : '📄'} ${item.name}`);
30
+ * });
31
+ *
32
+ * // List specific folder
33
+ * const subContent = await client.folders.getContent('abc123folderkey');
34
+ * ```
35
+ */
36
+ async getContent(folderKey = 'myfiles', options = {}) {
37
+ const session = this.getSession();
38
+ if (!session) {
39
+ throw new Error('Not authenticated. Please call login() first.');
40
+ }
41
+ const { contentType = 'all', chunk = 1, chunkSize = 100 } = options;
42
+ const folders = [];
43
+ const files = [];
44
+ let hasMore = false;
45
+ // Get folders if needed
46
+ if (contentType === 'all' || contentType === 'folders') {
47
+ const response = await (0, api_1.apiCall)('folder/get_content', {
48
+ folder_key: folderKey,
49
+ content_type: 'folders',
50
+ chunk,
51
+ chunk_size: chunkSize
52
+ }, session);
53
+ const folderContent = response.folder_content || {};
54
+ (folderContent.folders || []).forEach(folder => {
55
+ folders.push({
56
+ id: folder.folderkey,
57
+ folderKey: folder.folderkey,
58
+ name: folder.name,
59
+ created: folder.created,
60
+ fileCount: parseInt(folder.file_count || '0', 10),
61
+ folderCount: parseInt(folder.folder_count || '0', 10),
62
+ isFolder: true
63
+ });
64
+ });
65
+ if (folderContent.more_chunks === 'yes') {
66
+ hasMore = true;
67
+ }
68
+ }
69
+ // Get files if needed
70
+ if (contentType === 'all' || contentType === 'files') {
71
+ const response = await (0, api_1.apiCall)('folder/get_content', {
72
+ folder_key: folderKey,
73
+ content_type: 'files',
74
+ chunk,
75
+ chunk_size: chunkSize
76
+ }, session);
77
+ const fileContent = response.folder_content || {};
78
+ (fileContent.files || []).forEach(file => {
79
+ const size = parseInt(file.size || '0', 10);
80
+ files.push({
81
+ id: file.quickkey,
82
+ quickKey: file.quickkey,
83
+ name: file.filename,
84
+ size,
85
+ sizeFormatted: (0, utils_1.formatBytes)(size),
86
+ created: file.created,
87
+ mimeType: file.mimetype,
88
+ privacy: file.privacy,
89
+ isFolder: false
90
+ });
91
+ });
92
+ if (fileContent.more_chunks === 'yes') {
93
+ hasMore = true;
94
+ }
95
+ }
96
+ // Combine results (folders first)
97
+ const items = [...folders, ...files];
98
+ return {
99
+ folderKey,
100
+ items,
101
+ hasMore,
102
+ chunk
103
+ };
104
+ }
105
+ /**
106
+ * Get only files in a folder
107
+ *
108
+ * @param folderKey - Folder key (default: 'myfiles' for root)
109
+ * @param options - Pagination options
110
+ * @returns Array of files
111
+ */
112
+ async getFiles(folderKey = 'myfiles', options = {}) {
113
+ const content = await this.getContent(folderKey, { ...options, contentType: 'files' });
114
+ return content.items.filter((item) => !item.isFolder);
115
+ }
116
+ /**
117
+ * Get only folders in a folder
118
+ *
119
+ * @param folderKey - Folder key (default: 'myfiles' for root)
120
+ * @param options - Pagination options
121
+ * @returns Array of folders
122
+ */
123
+ async getFolders(folderKey = 'myfiles', options = {}) {
124
+ const content = await this.getContent(folderKey, { ...options, contentType: 'folders' });
125
+ return content.items.filter((item) => item.isFolder);
126
+ }
127
+ }
128
+ exports.FoldersModule = FoldersModule;
129
+ //# sourceMappingURL=folders.js.map