@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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +228 -0
  3. package/dist/enums/action-on-duplicate-file.d.ts +5 -0
  4. package/dist/enums/action-on-duplicate-file.js +9 -0
  5. package/dist/enums/content-type.d.ts +5 -0
  6. package/dist/enums/content-type.js +9 -0
  7. package/dist/enums/details.d.ts +5 -0
  8. package/dist/enums/details.js +9 -0
  9. package/dist/enums/index.d.ts +6 -0
  10. package/dist/enums/index.js +22 -0
  11. package/dist/enums/order-by.d.ts +6 -0
  12. package/dist/enums/order-by.js +10 -0
  13. package/dist/enums/order-direction.d.ts +4 -0
  14. package/dist/enums/order-direction.js +8 -0
  15. package/dist/enums/upload-status.d.ts +13 -0
  16. package/dist/enums/upload-status.js +17 -0
  17. package/dist/error.d.ts +3 -0
  18. package/dist/error.js +10 -0
  19. package/dist/files-service.d.ts +154 -0
  20. package/dist/files-service.js +107 -0
  21. package/dist/folders-service.d.ts +165 -0
  22. package/dist/folders-service.js +65 -0
  23. package/dist/index.d.ts +4 -0
  24. package/dist/index.js +20 -0
  25. package/dist/interfaces/files/get-file-info.d.ts +32 -0
  26. package/dist/interfaces/files/get-file-info.js +2 -0
  27. package/dist/interfaces/files/get-links.d.ts +17 -0
  28. package/dist/interfaces/files/get-links.js +2 -0
  29. package/dist/interfaces/files/index.d.ts +3 -0
  30. package/dist/interfaces/files/index.js +19 -0
  31. package/dist/interfaces/files/poll-upload.d.ts +20 -0
  32. package/dist/interfaces/files/poll-upload.js +2 -0
  33. package/dist/interfaces/files/upload-file.d.ts +13 -0
  34. package/dist/interfaces/files/upload-file.js +2 -0
  35. package/dist/interfaces/folders/get-contents.d.ts +53 -0
  36. package/dist/interfaces/folders/get-contents.js +2 -0
  37. package/dist/interfaces/folders/get-folder-info.d.ts +19 -0
  38. package/dist/interfaces/folders/get-folder-info.js +2 -0
  39. package/dist/interfaces/folders/index.d.ts +2 -0
  40. package/dist/interfaces/folders/index.js +18 -0
  41. package/dist/interfaces/index.d.ts +3 -0
  42. package/dist/interfaces/index.js +19 -0
  43. package/dist/interfaces/user/get-session-token-response.d.ts +12 -0
  44. package/dist/interfaces/user/get-session-token-response.js +2 -0
  45. package/dist/interfaces/user/index.d.ts +1 -0
  46. package/dist/interfaces/user/index.js +17 -0
  47. package/dist/mediafire.d.ts +35 -0
  48. package/dist/mediafire.js +96 -0
  49. package/dist/utils/constants.d.ts +6 -0
  50. package/dist/utils/constants.js +9 -0
  51. package/dist/utils/delay.d.ts +1 -0
  52. package/dist/utils/delay.js +6 -0
  53. package/dist/utils/index.d.ts +1 -0
  54. package/dist/utils/index.js +17 -0
  55. package/package.json +33 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Marcuth
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,228 @@
1
+ # @marcuth/mediafire
2
+
3
+ **@marcuth/mediafire** is a package for the [Mediafire](https://mediafire.com) service designed to communicate with its API, handling authentication, file management, and folder organization.
4
+
5
+ ## 📦 Installation
6
+
7
+ Installation is straightforward; simply use your preferred package manager. Here is an example using NPM:
8
+
9
+ ```bash
10
+ npm i @marcuth/mediafire
11
+
12
+ ```
13
+
14
+ ## 🚀 Usage
15
+
16
+ <a href="https://www.buymeacoffee.com/marcuth">
17
+   <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" width="200">
18
+ </a>
19
+
20
+ ### Authentication
21
+
22
+ To access the routes, you must first authenticate. There are two ways to do this: using email and password (the only method implemented so far) or via API Keys.
23
+
24
+ **Using email and password:**
25
+
26
+ ```ts
27
+ import { Mediafire } from "@marcuth/mediafire"
28
+
29
+ ;(async () => {
30
+ const mediafire = new Mediafire({
31
+ email: "YOUR_EMAIL",
32
+ password: "YOUR_PASSWORD"
33
+ })
34
+
35
+ await mediafire.logIn()
36
+ })();
37
+
38
+ ```
39
+
40
+ ---
41
+
42
+ ### Folders
43
+
44
+ #### Getting information
45
+
46
+ ```ts
47
+ import { Mediafire } from "@marcuth/mediafire"
48
+
49
+ ;(async () => {
50
+ // Your way of instantiating Mediafire
51
+
52
+ const folderInfo = await mediafire.folders.getInfo({
53
+ folderKey: "your-folder-key"
54
+ })
55
+
56
+ console.log(folderInfo)
57
+ })();
58
+
59
+ ```
60
+
61
+ #### Getting information by path
62
+
63
+ ```ts
64
+ import { Mediafire } from "@marcuth/mediafire"
65
+
66
+ ;(async () => {
67
+ // Your way of instantiating Mediafire
68
+
69
+ const folderInfo = await mediafire.folders.getInfo({
70
+ folderPath: "path/to/folder"
71
+ })
72
+
73
+ console.log(folderInfo)
74
+ })();
75
+
76
+ ```
77
+
78
+ #### Getting contents
79
+
80
+ ```ts
81
+ import { Mediafire } from "@marcuth/mediafire"
82
+
83
+ ;(async () => {
84
+ // Your way of instantiating Mediafire
85
+
86
+ const folderContents = await mediafire.folders.getContents({
87
+ folderKey: "your-folder-key"
88
+ })
89
+
90
+ console.log(folderContents)
91
+ })();
92
+
93
+ ```
94
+
95
+ #### Getting contents by path
96
+
97
+ ```ts
98
+ import { Mediafire } from "@marcuth/mediafire"
99
+
100
+ ;(async () => {
101
+ // Your way of instantiating Mediafire
102
+
103
+ const folderContents = await mediafire.folders.getContents({
104
+ folderPath: "path/to/folder"
105
+ })
106
+
107
+ console.log(folderContents)
108
+ })();
109
+
110
+ ```
111
+
112
+ ---
113
+
114
+ ### Files
115
+
116
+ #### Getting information
117
+
118
+ ```ts
119
+ import { Mediafire } from "@marcuth/mediafire"
120
+
121
+ ;(async () => {
122
+ // Your way of instantiating Mediafire
123
+
124
+ const fileInfo = await mediafire.files.getInfo({
125
+ quickKey: "your-quick-key"
126
+ })
127
+
128
+ console.log(fileInfo)
129
+ })();
130
+
131
+ ```
132
+
133
+ #### Getting information by path
134
+
135
+ ```ts
136
+ import { Mediafire } from "@marcuth/mediafire"
137
+
138
+ ;(async () => {
139
+ // Your way of instantiating Mediafire
140
+
141
+ const fileInfo = await mediafire.files.getInfoByPath({
142
+ filePath: "path/to/folder/file.ext"
143
+ })
144
+
145
+ console.log(fileInfo)
146
+ })();
147
+
148
+ ```
149
+
150
+ #### Getting download links
151
+
152
+ ```ts
153
+ import { Mediafire } from "@marcuth/mediafire"
154
+
155
+ ;(async () => {
156
+ // Your way of instantiating Mediafire
157
+
158
+ const fileLinksInfo = await mediafire.files.getLinks({
159
+ quickKey: "your-quick-key"
160
+ })
161
+
162
+ console.log(fileLinksInfo)
163
+ })();
164
+
165
+ ```
166
+
167
+ #### Uploading a file
168
+
169
+ ```ts
170
+ import { Mediafire } from "@marcuth/mediafire"
171
+ import fs from "node:fs"
172
+
173
+ ;(async () => {
174
+ // Your way of instantiating Mediafire
175
+
176
+ const uploadInfo = await mediafire.files.upload({
177
+ fileName: "file.ext",
178
+ file: fs.createReadStream("path/to/source-file.ext")
179
+ })
180
+
181
+ console.log(uploadInfo)
182
+ })();
183
+
184
+ ```
185
+
186
+ #### Uploading a file to a specific path
187
+
188
+ ```ts
189
+ import { Mediafire } from "@marcuth/mediafire"
190
+ import fs from "node:fs"
191
+
192
+ ;(async () => {
193
+ // Your way of instantiating Mediafire
194
+
195
+ const uploadInfo = await mediafire.files.uploadToPath({
196
+ filePath: "path/to/destination/file.ext",
197
+ file: fs.createReadStream("path/to/source-file.ext")
198
+ })
199
+
200
+ console.log(uploadInfo)
201
+ })();
202
+
203
+ ```
204
+
205
+ ---
206
+
207
+ ## 🧪 Testing
208
+
209
+ Automated tests are located in the `__tests__` directory. To run them:
210
+
211
+ ```bash
212
+ npm run test
213
+
214
+ ```
215
+
216
+ ## 🤝 Contributing
217
+
218
+ Want to contribute? Follow these steps:
219
+
220
+ 1. Fork the repository.
221
+ 2. Create a new branch (`git checkout -b feature-new`).
222
+ 3. Commit your changes (`git commit -m 'Add new feature'`).
223
+ 4. Push to the branch (`git push origin feature-new`).
224
+ 5. Open a Pull Request.
225
+
226
+ ## 📝 License
227
+
228
+ This project is licensed under the MIT License.
@@ -0,0 +1,5 @@
1
+ export declare enum ActionOnDuplicateFile {
2
+ Keep = "keep",
3
+ Skip = "skip",
4
+ Replace = "replace"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActionOnDuplicateFile = void 0;
4
+ var ActionOnDuplicateFile;
5
+ (function (ActionOnDuplicateFile) {
6
+ ActionOnDuplicateFile["Keep"] = "keep";
7
+ ActionOnDuplicateFile["Skip"] = "skip";
8
+ ActionOnDuplicateFile["Replace"] = "replace";
9
+ })(ActionOnDuplicateFile || (exports.ActionOnDuplicateFile = ActionOnDuplicateFile = {}));
@@ -0,0 +1,5 @@
1
+ export declare enum ContentType {
2
+ Folders = "folders",
3
+ Files = "files",
4
+ Both = "both"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentType = void 0;
4
+ var ContentType;
5
+ (function (ContentType) {
6
+ ContentType["Folders"] = "folders";
7
+ ContentType["Files"] = "files";
8
+ ContentType["Both"] = "both";
9
+ })(ContentType || (exports.ContentType = ContentType = {}));
@@ -0,0 +1,5 @@
1
+ export declare enum Details {
2
+ No = "no",
3
+ Yes = "yes",
4
+ Shallow = "shallow"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Details = void 0;
4
+ var Details;
5
+ (function (Details) {
6
+ Details["No"] = "no";
7
+ Details["Yes"] = "yes";
8
+ Details["Shallow"] = "shallow";
9
+ })(Details || (exports.Details = Details = {}));
@@ -0,0 +1,6 @@
1
+ export * from "./action-on-duplicate-file";
2
+ export * from "./content-type";
3
+ export * from "./details";
4
+ export * from "./order-direction";
5
+ export * from "./order-by";
6
+ export * from "./upload-status";
@@ -0,0 +1,22 @@
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("./action-on-duplicate-file"), exports);
18
+ __exportStar(require("./content-type"), exports);
19
+ __exportStar(require("./details"), exports);
20
+ __exportStar(require("./order-direction"), exports);
21
+ __exportStar(require("./order-by"), exports);
22
+ __exportStar(require("./upload-status"), exports);
@@ -0,0 +1,6 @@
1
+ export declare enum OrderBy {
2
+ Name = "name",
3
+ Date = "date",
4
+ Size = "size",
5
+ Downloads = "downloads"
6
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrderBy = void 0;
4
+ var OrderBy;
5
+ (function (OrderBy) {
6
+ OrderBy["Name"] = "name";
7
+ OrderBy["Date"] = "date";
8
+ OrderBy["Size"] = "size";
9
+ OrderBy["Downloads"] = "downloads";
10
+ })(OrderBy || (exports.OrderBy = OrderBy = {}));
@@ -0,0 +1,4 @@
1
+ export declare enum OrderDirection {
2
+ Asc = "asc",
3
+ Desc = "desc"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrderDirection = void 0;
4
+ var OrderDirection;
5
+ (function (OrderDirection) {
6
+ OrderDirection["Asc"] = "asc";
7
+ OrderDirection["Desc"] = "desc";
8
+ })(OrderDirection || (exports.OrderDirection = OrderDirection = {}));
@@ -0,0 +1,13 @@
1
+ export declare enum UploadStatus {
2
+ Unknown = "0",
3
+ Ready = "2",
4
+ UploadInProgress = "3",
5
+ UploadCompleted = "4",
6
+ WaitingForVerification = "5",
7
+ VerifyingFile = "6",
8
+ FinishedVerification = "11",
9
+ UploadInProgressSecondary = "17",
10
+ WaitingForAssembly = "18",
11
+ AssemblingFile = "19",
12
+ NoMoreRequests = "99"
13
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UploadStatus = void 0;
4
+ var UploadStatus;
5
+ (function (UploadStatus) {
6
+ UploadStatus["Unknown"] = "0";
7
+ UploadStatus["Ready"] = "2";
8
+ UploadStatus["UploadInProgress"] = "3";
9
+ UploadStatus["UploadCompleted"] = "4";
10
+ UploadStatus["WaitingForVerification"] = "5";
11
+ UploadStatus["VerifyingFile"] = "6";
12
+ UploadStatus["FinishedVerification"] = "11";
13
+ UploadStatus["UploadInProgressSecondary"] = "17";
14
+ UploadStatus["WaitingForAssembly"] = "18";
15
+ UploadStatus["AssemblingFile"] = "19";
16
+ UploadStatus["NoMoreRequests"] = "99";
17
+ })(UploadStatus || (exports.UploadStatus = UploadStatus = {}));
@@ -0,0 +1,3 @@
1
+ export declare class MediafireError extends Error {
2
+ constructor(message: string);
3
+ }
package/dist/error.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MediafireError = void 0;
4
+ class MediafireError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "MediafireError";
8
+ }
9
+ }
10
+ exports.MediafireError = MediafireError;
@@ -0,0 +1,154 @@
1
+ import { ActionOnDuplicateFile } from "./enums/action-on-duplicate-file";
2
+ import { Mediafire } from "./mediafire";
3
+ export type UploadOptions = {
4
+ file: Buffer | NodeJS.ReadableStream;
5
+ fileName: string;
6
+ folderKey?: string;
7
+ actionOnDuplicate?: ActionOnDuplicateFile | `${ActionOnDuplicateFile}`;
8
+ };
9
+ export type FileActionOptions = {
10
+ quickKey: string;
11
+ };
12
+ export type MoveFileOptions = {
13
+ quickKey: string;
14
+ folderKey: string;
15
+ };
16
+ export type GetInfoByPathOptions = {
17
+ filePath: string;
18
+ };
19
+ export type PollUploadOptions = {
20
+ uploadKey: string;
21
+ };
22
+ export type UploadToPathOptions = Omit<UploadOptions & {
23
+ filePath: string;
24
+ }, "folderKey" | "fileName">;
25
+ export declare class FilesService {
26
+ private readonly mediafire;
27
+ private readonly pollDelay;
28
+ constructor(mediafire: Mediafire, pollDelay: number);
29
+ upload({ file, fileName, folderKey, actionOnDuplicate }: UploadOptions): Promise<{
30
+ doupload: {
31
+ result: string;
32
+ upload_key: string;
33
+ quick_key: string;
34
+ download_links: {
35
+ quickkey: string;
36
+ normal_download: string;
37
+ one_time: {
38
+ download: string;
39
+ };
40
+ }[];
41
+ };
42
+ action: string;
43
+ server: string;
44
+ result: string;
45
+ new_key: string;
46
+ current_api_version: string;
47
+ }>;
48
+ pollUpload({ uploadKey }: PollUploadOptions): Promise<{
49
+ action: string;
50
+ doupload: {
51
+ result: string;
52
+ status: string;
53
+ description: string;
54
+ quickkey: string;
55
+ hash: string;
56
+ filename: string;
57
+ size: string;
58
+ created: string;
59
+ revision: string;
60
+ created_utc: string;
61
+ };
62
+ result: string;
63
+ current_api_version: string;
64
+ new_key?: undefined;
65
+ }>;
66
+ getInfo({ quickKey }: FileActionOptions): Promise<{
67
+ action: string;
68
+ file_info: {
69
+ quickkey: string;
70
+ filename: string;
71
+ ready: string;
72
+ created: string;
73
+ downloads: string;
74
+ description: string;
75
+ size: string;
76
+ privacy: string;
77
+ password_protected: string;
78
+ hash: string;
79
+ filetype: string;
80
+ mimetype: string;
81
+ owner_name: string;
82
+ flag: string;
83
+ parent_folderkey: string;
84
+ revision: string;
85
+ view: string;
86
+ edit: string;
87
+ links: {
88
+ normal_download: string;
89
+ };
90
+ created_utc: string;
91
+ };
92
+ result: string;
93
+ new_key: string;
94
+ current_api_version: string;
95
+ }>;
96
+ getInfoByPath({ filePath }: GetInfoByPathOptions): Promise<{
97
+ quickkey: string;
98
+ hash: string;
99
+ filename: string;
100
+ description: string;
101
+ size: string;
102
+ privacy: string;
103
+ created: string;
104
+ password_protected: string;
105
+ mimetype: string;
106
+ filetype: string;
107
+ view: string;
108
+ edit: string;
109
+ revision: string;
110
+ flag: string;
111
+ downloads: string;
112
+ views: string;
113
+ links: {
114
+ normal_download: string;
115
+ };
116
+ created_utc: string;
117
+ }>;
118
+ uploadToPath({ filePath, file, actionOnDuplicate }: UploadToPathOptions): Promise<{
119
+ doupload: {
120
+ result: string;
121
+ upload_key: string;
122
+ quick_key: string;
123
+ download_links: {
124
+ quickkey: string;
125
+ normal_download: string;
126
+ one_time: {
127
+ download: string;
128
+ };
129
+ }[];
130
+ };
131
+ action: string;
132
+ server: string;
133
+ result: string;
134
+ new_key: string;
135
+ current_api_version: string;
136
+ }>;
137
+ move({ quickKey, folderKey }: MoveFileOptions): Promise<any>;
138
+ getLinks({ quickKey }: FileActionOptions): Promise<{
139
+ action: string;
140
+ links: {
141
+ quickkey: string;
142
+ normal_download: string;
143
+ one_time: {
144
+ download: string;
145
+ };
146
+ }[];
147
+ one_time_key_request_count: string;
148
+ one_time_key_request_max_count: string;
149
+ result: string;
150
+ new_key: string;
151
+ current_api_version: string;
152
+ }>;
153
+ delete({ quickKey }: FileActionOptions): Promise<any>;
154
+ }
@@ -0,0 +1,107 @@
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.FilesService = void 0;
7
+ const form_data_1 = __importDefault(require("form-data"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const content_type_1 = require("./enums/content-type");
10
+ const error_1 = require("./error");
11
+ class FilesService {
12
+ constructor(mediafire, pollDelay) {
13
+ this.mediafire = mediafire;
14
+ this.pollDelay = pollDelay;
15
+ }
16
+ async upload({ file, fileName, folderKey, actionOnDuplicate }) {
17
+ const action = "upload/simple";
18
+ const form = new form_data_1.default();
19
+ form.append("Filedata", file, { filename: fileName });
20
+ const data = await this.mediafire.request(action, {
21
+ folder_key: folderKey,
22
+ action_on_duplicate: actionOnDuplicate,
23
+ }, form);
24
+ const resonseData = data.response;
25
+ const uploadKey = resonseData.doupload.key;
26
+ const pollUploadInfo = await this.pollUpload({ uploadKey: uploadKey });
27
+ const quickKey = pollUploadInfo.doupload.quickkey;
28
+ const linksInfo = await this.getLinks({ quickKey: quickKey });
29
+ const downloadLinks = linksInfo.links;
30
+ return {
31
+ ...resonseData,
32
+ doupload: {
33
+ result: resonseData.doupload.result,
34
+ upload_key: resonseData.doupload.key,
35
+ quick_key: quickKey,
36
+ download_links: downloadLinks
37
+ }
38
+ };
39
+ }
40
+ async pollUpload({ uploadKey }) {
41
+ const action = "upload/poll_upload";
42
+ const data = await this.mediafire.request(action, {
43
+ key: uploadKey
44
+ });
45
+ const responseData = data.response;
46
+ if (!responseData.doupload.quickkey) {
47
+ throw new error_1.MediafireError("Not found quick_key in poll upload");
48
+ }
49
+ return responseData;
50
+ }
51
+ async getInfo({ quickKey }) {
52
+ const action = "file/get_info";
53
+ const data = await this.mediafire.request(action, {
54
+ quick_key: quickKey
55
+ });
56
+ return data.response;
57
+ }
58
+ async getInfoByPath({ filePath }) {
59
+ const parts = node_path_1.default.parse(filePath);
60
+ const dirPath = parts.dir;
61
+ const fileName = parts.base;
62
+ const folderContents = await this.mediafire.folders.getContentsByPath({
63
+ folderPath: dirPath,
64
+ contentType: content_type_1.ContentType.Files
65
+ });
66
+ const file = folderContents.folder_content.files?.find(file => file.filename === fileName);
67
+ if (!file) {
68
+ throw new error_1.MediafireError(`File not found: ${fileName} at ${filePath}`);
69
+ }
70
+ return file;
71
+ }
72
+ async uploadToPath({ filePath, file, actionOnDuplicate }) {
73
+ const parts = node_path_1.default.parse(filePath);
74
+ const dirPath = parts.dir;
75
+ const fileName = parts.base;
76
+ const folderInfo = await this.mediafire.folders.getInfoByPath({ folderPath: dirPath });
77
+ const folderKey = folderInfo.folder_info.folderkey;
78
+ return await this.upload({
79
+ file: file,
80
+ fileName: fileName,
81
+ folderKey: folderKey,
82
+ actionOnDuplicate: actionOnDuplicate
83
+ });
84
+ }
85
+ async move({ quickKey, folderKey }) {
86
+ const action = "file/move";
87
+ return await this.mediafire.request(action, {
88
+ quick_key: quickKey,
89
+ folder_key: folderKey
90
+ });
91
+ }
92
+ async getLinks({ quickKey }) {
93
+ const action = "file/get_links";
94
+ const data = await this.mediafire.request(action, {
95
+ quick_key: quickKey
96
+ });
97
+ return data.response;
98
+ }
99
+ async delete({ quickKey }) {
100
+ const action = "file/delete";
101
+ const data = await this.mediafire.request(action, {
102
+ quick_key: quickKey
103
+ });
104
+ return data;
105
+ }
106
+ }
107
+ exports.FilesService = FilesService;