@marcuth/mediafire 1.3.0 → 1.3.1

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.
@@ -73,7 +73,7 @@ class FilesService {
73
73
  const parts = node_path_1.default.parse(filePath);
74
74
  const dirPath = parts.dir;
75
75
  const fileName = parts.base;
76
- const folderInfo = await this.mediafire.folders.getInfoByPath({ folderPath: dirPath });
76
+ const folderInfo = await this.mediafire.folders.ensureAndGetInfoByPath({ folderPath: dirPath });
77
77
  const folderKey = folderInfo.folder_info.folderkey;
78
78
  return await this.upload({
79
79
  file: file,
@@ -23,6 +23,16 @@ export type GetInfoByPathOptions = {
23
23
  export type GetFolderContentsByPathOptions = Omit<GetFolderContentOptions & {
24
24
  folderPath: string;
25
25
  }, "folderKey">;
26
+ export type CreateOptions = {
27
+ name: string;
28
+ parentKey?: string;
29
+ };
30
+ export type CreateByPathOptions = {
31
+ folderPath: string;
32
+ };
33
+ export type EnsureAndGetInfoByPathOptions = {
34
+ folderPath: string;
35
+ };
26
36
  export declare class FoldersService {
27
37
  private readonly mediafire;
28
38
  constructor(mediafire: Mediafire);
@@ -162,4 +172,61 @@ export declare class FoldersService {
162
172
  new_key: string;
163
173
  current_api_version: string;
164
174
  }>;
175
+ create({ name, parentKey }: CreateOptions): Promise<{
176
+ action: string;
177
+ folder_key: string;
178
+ upload_key: string;
179
+ parent_folderkey: string;
180
+ name: string;
181
+ description: string;
182
+ created: string;
183
+ created_utc: string;
184
+ privacy: string;
185
+ file_count: string;
186
+ folder_count: string;
187
+ revision: string;
188
+ dropbox_enabled: string;
189
+ flag: string;
190
+ result: string;
191
+ new_key: string;
192
+ current_api_version: string;
193
+ new_device_revision: number;
194
+ }>;
195
+ createByPath({ folderPath }: CreateByPathOptions): Promise<{
196
+ action: string;
197
+ folder_key: string;
198
+ upload_key: string;
199
+ parent_folderkey: string;
200
+ name: string;
201
+ description: string;
202
+ created: string;
203
+ created_utc: string;
204
+ privacy: string;
205
+ file_count: string;
206
+ folder_count: string;
207
+ revision: string;
208
+ dropbox_enabled: string;
209
+ flag: string;
210
+ result: string;
211
+ new_key: string;
212
+ current_api_version: string;
213
+ new_device_revision: number;
214
+ }>;
215
+ ensureAndGetInfoByPath({ folderPath }: EnsureAndGetInfoByPathOptions): Promise<{
216
+ action: string;
217
+ folder_info: {
218
+ folderkey: string;
219
+ name: string;
220
+ file_count: string;
221
+ folder_count: string;
222
+ revision: string;
223
+ owner_name: string;
224
+ avatar: string;
225
+ dropbox_enabled: string;
226
+ flag: string;
227
+ };
228
+ result: string;
229
+ new_key: string;
230
+ current_api_version: string;
231
+ }>;
165
232
  }
@@ -61,5 +61,52 @@ class FoldersService {
61
61
  ...options
62
62
  });
63
63
  }
64
+ async create({ name, parentKey = utils_1.rootFolderKey }) {
65
+ const action = "folder/create";
66
+ const data = await this.mediafire.request(action, {
67
+ foldername: name,
68
+ parent_key: parentKey,
69
+ });
70
+ return data.response;
71
+ }
72
+ async createByPath({ folderPath }) {
73
+ const parts = folderPath.split(/[\\/]/).filter(part => part.length > 0);
74
+ let currentFolderKey = utils_1.rootFolderKey;
75
+ let lastCreatedFolder = null;
76
+ for (const partName of parts) {
77
+ const folderContents = await this.getContents({
78
+ folderKey: currentFolderKey,
79
+ contentType: content_type_1.ContentType.Folders
80
+ });
81
+ const existingFolder = folderContents.folder_content.folders?.find(folder => folder.name === partName);
82
+ if (existingFolder) {
83
+ currentFolderKey = existingFolder.folderkey;
84
+ }
85
+ else {
86
+ const newFolder = await this.create({
87
+ name: partName,
88
+ parentKey: currentFolderKey
89
+ });
90
+ currentFolderKey = newFolder.folder_key;
91
+ lastCreatedFolder = newFolder;
92
+ }
93
+ }
94
+ if (!lastCreatedFolder) {
95
+ throw new error_1.MediafireError(`The folder at the specified "${folderPath}" path already existed!`);
96
+ }
97
+ return lastCreatedFolder;
98
+ }
99
+ async ensureAndGetInfoByPath({ folderPath }) {
100
+ try {
101
+ return await this.getInfoByPath({ folderPath });
102
+ }
103
+ catch (error) {
104
+ if (error instanceof error_1.MediafireError && error.message.includes("not found")) {
105
+ const { folder_key } = await this.createByPath({ folderPath });
106
+ return await this.getInfo({ folderKey: folder_key });
107
+ }
108
+ throw error;
109
+ }
110
+ }
64
111
  }
65
112
  exports.FoldersService = FoldersService;
@@ -1,3 +1,3 @@
1
1
  export * from "./get-file-info";
2
2
  export * from "./get-links";
3
- export * from "./upload-file";
3
+ export * from "./upload";
@@ -16,4 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./get-file-info"), exports);
18
18
  __exportStar(require("./get-links"), exports);
19
- __exportStar(require("./upload-file"), exports);
19
+ __exportStar(require("./upload"), exports);
@@ -0,0 +1,13 @@
1
+ export interface UploadFileResponse {
2
+ response: {
3
+ action: string;
4
+ doupload: {
5
+ result: string;
6
+ key: string;
7
+ };
8
+ server: string;
9
+ result: string;
10
+ new_key: string;
11
+ current_api_version: string;
12
+ };
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ export interface CreateFolderResponse {
2
+ response: {
3
+ action: string;
4
+ folder_key: string;
5
+ upload_key: string;
6
+ parent_folderkey: string;
7
+ name: string;
8
+ description: string;
9
+ created: string;
10
+ created_utc: string;
11
+ privacy: string;
12
+ file_count: string;
13
+ folder_count: string;
14
+ revision: string;
15
+ dropbox_enabled: string;
16
+ flag: string;
17
+ result: string;
18
+ new_key: string;
19
+ current_api_version: string;
20
+ new_device_revision: number;
21
+ };
22
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ export interface GetFolderInfo {
2
+ response: {
3
+ action: string;
4
+ folder_info: {
5
+ folderkey: string;
6
+ name: string;
7
+ file_count: string;
8
+ folder_count: string;
9
+ revision: string;
10
+ owner_name: string;
11
+ avatar: string;
12
+ dropbox_enabled: string;
13
+ flag: string;
14
+ };
15
+ result: string;
16
+ new_key: string;
17
+ current_api_version: string;
18
+ };
19
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,2 @@
1
1
  export * from "./get-contents";
2
- export * from "./get-folder-info";
2
+ export * from "./get-info";
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./get-contents"), exports);
18
- __exportStar(require("./get-folder-info"), exports);
18
+ __exportStar(require("./get-info"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marcuth/mediafire",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "A simple wrapper for the Mediafire API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -22,6 +22,7 @@
22
22
  "license": "MIT",
23
23
  "type": "commonjs",
24
24
  "devDependencies": {
25
+ "@marcuth/env": "^0.0.1",
25
26
  "@types/node": "^25.0.3",
26
27
  "ts-node": "^10.9.2",
27
28
  "typescript": "^5.9.3"