@fett/synology-api 0.0.3-beta.3 → 0.0.3-beta.5

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/lib/core.js CHANGED
@@ -106,13 +106,12 @@ export class SynologyApi extends BaseModuleSynologyApi {
106
106
  // https agent for node
107
107
  if (isNode) {
108
108
  if (this.agent?.https) {
109
- const hspa = await import("https-proxy-agent");
110
- requestOptions.httpsAgent = new hspa.HttpsProxyAgent(`https://${this.agent.https.host}:${this.agent.https.port}`);
109
+ const { HttpsProxyAgent } = require("https-proxy-agent");
110
+ requestOptions.httpsAgent = new HttpsProxyAgent(`https://${this.agent.https.host}:${this.agent.https.port}`);
111
111
  }
112
112
  // http agent
113
113
  if (this.agent?.http) {
114
- const hpa = await import("http-proxy-agent");
115
- const HttpProxyAgent = hpa.HttpProxyAgent;
114
+ const { HttpProxyAgent } = require("http-proxy-agent");
116
115
  requestOptions.httpAgent = new HttpProxyAgent(`http://${this.agent.http.host}:${this.agent.http.port}`);
117
116
  }
118
117
  }
@@ -1,8 +1,7 @@
1
- import { SynologyApiKeysMap } from "./modules/index.js";
2
1
  import { SynologyApiResponse } from "./types/index.js";
3
2
  export declare const COMMON_CODES = "COMMON_CODES";
4
3
  export declare const SYNOLOGY_ERROR_CODES: {
5
- [SynologyApiKeysMap.FileStation]: {
4
+ FileStation: {
6
5
  400: string;
7
6
  401: string;
8
7
  402: string;
@@ -42,7 +41,7 @@ export declare const SYNOLOGY_ERROR_CODES: {
42
41
  2001: string;
43
42
  2002: string;
44
43
  };
45
- [SynologyApiKeysMap.AudioStation]: {};
44
+ AudioStation: {};
46
45
  COMMON_CODES: {
47
46
  0: string;
48
47
  100: string;
package/lib/errorcodes.js CHANGED
@@ -1,10 +1,9 @@
1
- import { SynologyApiKeysMap } from "./modules/index.js";
2
1
  import { isUndfined } from "./utils/index.js";
3
2
  const CODE_SUCCESS = 0;
4
3
  const CODE_UNKNOWN = 9999;
5
4
  export const COMMON_CODES = "COMMON_CODES";
6
5
  export const SYNOLOGY_ERROR_CODES = {
7
- [SynologyApiKeysMap.FileStation]: {
6
+ ['FileStation']: {
8
7
  400: "Invalid parameter of file operation",
9
8
  401: "Unknown error of file operation",
10
9
  402: "System is too busy",
@@ -48,7 +47,7 @@ export const SYNOLOGY_ERROR_CODES = {
48
47
  2001: "Cannot generate sharing link because too many sharing links exist.",
49
48
  2002: " Failed to access sharing links.",
50
49
  },
51
- [SynologyApiKeysMap.AudioStation]: {},
50
+ ['AudioStation']: {},
52
51
  ["COMMON_CODES"]: {
53
52
  [CODE_SUCCESS]: "Success",
54
53
  100: "Unknown error",
@@ -17,5 +17,5 @@ export type UploadFileResponse = SynologyApiResponse<{
17
17
  pid: number;
18
18
  progress: number;
19
19
  }>;
20
- export declare function uploadFileBase(params: UploadFileParams, parseFileFn: (file: File | Blob | string, formdata: any) => any): Promise<UploadFileResponse>;
20
+ export declare function uploadFileBase(_that: any, params: UploadFileParams, parseFileFn: (file: File | Blob | string, formdata: any) => Promise<any>): Promise<UploadFileResponse>;
21
21
  export {};
@@ -5,9 +5,9 @@ var OverwriteEnum;
5
5
  OverwriteEnum["OVERWRITE"] = "overwrite";
6
6
  OverwriteEnum["SKIP"] = "skip";
7
7
  })(OverwriteEnum || (OverwriteEnum = {}));
8
- export async function uploadFileBase(params, parseFileFn) {
8
+ export async function uploadFileBase(_that, params, parseFileFn) {
9
9
  const { path, file, overwrite = OverwriteEnum.OVERWRITE, create_parents = true } = params;
10
- const api = this.getApiInfoByName(FileStationApi.Upload);
10
+ const api = _that.getApiInfoByName(FileStationApi.Upload);
11
11
  let formData = createFormData();
12
12
  formData.append("method", "upload");
13
13
  formData.append("version", String(api?.maxVersion));
@@ -15,8 +15,8 @@ export async function uploadFileBase(params, parseFileFn) {
15
15
  formData.append("path", path);
16
16
  formData.append("overwrite", overwrite);
17
17
  formData.append("create_parents", String(create_parents));
18
- formData = parseFileFn(file, formData);
19
- const res = this.run(FileStationApi.Upload, {
18
+ formData = await parseFileFn(file, formData);
19
+ const res = _that.run(FileStationApi.Upload, {
20
20
  method: "post",
21
21
  data: formData,
22
22
  headers: getFormDataHeaders(formData),
@@ -1 +1 @@
1
- export declare function uploadFile(...args: any[]): Promise<import("./Upload.base.js").UploadFileResponse>;
1
+ export declare function uploadFile(args: any): Promise<import("./Upload.base.js").UploadFileResponse>;
@@ -1,18 +1,18 @@
1
1
  import { isNode } from "../../utils/index.js";
2
2
  import { uploadFileBase } from "./Upload.base.js";
3
- export async function uploadFile(...args) {
3
+ export async function uploadFile(args) {
4
4
  if (!this.isConnecting) {
5
5
  await this.connect();
6
6
  }
7
7
  // @ts-ignore
8
- return uploadFileBase(...args, async (file, formdata) => {
8
+ return uploadFileBase(this, args, async (file, formdata) => {
9
9
  // nodejs environment
10
10
  if (isNode) {
11
11
  let fileContent;
12
12
  let fileName = "";
13
13
  if (typeof file === "string") {
14
- fileName = await import("path").then((p) => p.basename(file));
15
- fileContent = await import("node:fs/promises").then((fs) => fs.readFile(file));
14
+ fileName = require("path").basename(file);
15
+ fileContent = await require("path").readFile(file);
16
16
  }
17
17
  formdata.append("file", fileContent, {
18
18
  filename: fileName,
@@ -1 +1 @@
1
- export declare function uploadFile(...args: any[]): Promise<void>;
1
+ export declare function uploadFile(args: any): Promise<import("./Upload.base.js").UploadFileResponse>;
@@ -1,10 +1,10 @@
1
1
  import { uploadFileBase } from "./Upload.base.js";
2
- export async function uploadFile(...args) {
2
+ export async function uploadFile(args) {
3
3
  if (!this.isConnecting) {
4
4
  await this.connect();
5
5
  }
6
6
  // @ts-ignore
7
- uploadFileBase(...args, async (file, formdata) => {
7
+ return uploadFileBase(this, args, async (file, formdata) => {
8
8
  formdata.append("file", file);
9
9
  return formdata;
10
10
  });
@@ -1,6 +1,4 @@
1
1
  import { uploadFile } from "./Upload.js";
2
- export * from "./index.js";
3
- export type * from "./index.js";
4
2
  export declare const METHODS: {
5
3
  uploadFile: typeof uploadFile;
6
4
  getInfo: typeof import("./Info.js").getInfo;
@@ -1,6 +1,5 @@
1
1
  import { METHODS as BASE_METHODS } from "./index.base.js";
2
2
  import { uploadFile } from "./Upload.js";
3
- export * from "./index.js";
4
3
  export const METHODS = {
5
4
  ...BASE_METHODS,
6
5
  uploadFile,
@@ -1,5 +1,4 @@
1
1
  import { uploadFile } from "./Upload.rn.js";
2
- export * from "./index.js";
3
2
  export declare const METHODS: {
4
3
  uploadFile: typeof uploadFile;
5
4
  getInfo: typeof import("./Info.js").getInfo;
@@ -1,6 +1,5 @@
1
1
  import { METHODS as BASE_METHODS } from "./index.base.js";
2
2
  import { uploadFile } from "./Upload.rn.js";
3
- export * from "./index.js";
4
3
  export const METHODS = {
5
4
  ...BASE_METHODS,
6
5
  uploadFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fett/synology-api",
3
- "version": "0.0.3-beta.3",
3
+ "version": "0.0.3-beta.5",
4
4
  "description": "synology api for nodejs",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -13,6 +13,10 @@
13
13
  "import": "./lib/index.js",
14
14
  "require": "./lib/index.js",
15
15
  "react-native": "./lib/index.rn.js"
16
+ },
17
+ "./react-native": {
18
+ "import": "./lib/index.rn.js",
19
+ "require": "./lib/index.rn.js"
16
20
  }
17
21
  },
18
22
  "files": [