@fett/synology-api 0.1.1 → 0.1.3

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 CHANGED
@@ -28,6 +28,7 @@ npm install @fett/synology-api
28
28
  | :--------------------: | :-----------------: | :----------------------------------------------------------- | :-----: |
29
29
  | server | string | Synology NAS address or QuickConnectId | - |
30
30
  | quickConnectServerType | proxy \| wan \| lan | QuickConnect server type when connecting via QuickConnect ID | proxy |
31
+ | lanPriority | boolean | Prioritize LAN IP when quickConnectServerType is not lan | false |
31
32
  | username | string | Synology NAS username | - |
32
33
  | password | string | Synology NAS password | - |
33
34
 
package/lib/cli/apis.js CHANGED
@@ -42,7 +42,7 @@ export const onMethodCall = (module) => async (method, options) => {
42
42
  }
43
43
  if (options.output) {
44
44
  try {
45
- let out_path = path.resolve(options.output);
45
+ const out_path = path.resolve(options.output);
46
46
  if (!fse.existsSync(out_path)) {
47
47
  fse.ensureFileSync(out_path);
48
48
  console.log(chalk.yellowBright(`Output file created: ${out_path}`));
package/lib/core.d.ts CHANGED
@@ -54,12 +54,14 @@ export declare class SynologyApi extends BaseModuleSynologyApi {
54
54
  params?: Record<string, any>;
55
55
  data?: Record<string, any>;
56
56
  headers?: Record<string, any>;
57
+ responseType?: AxiosRequestConfig["responseType"];
57
58
  }): Promise<AxiosRequestConfig>;
58
59
  protected run(apiName: string, options: {
59
60
  method?: "get" | "post";
60
61
  params?: Record<string, any>;
61
62
  data?: Record<string, any>;
62
63
  headers?: Record<string, any>;
64
+ responseType?: AxiosRequestConfig["responseType"];
63
65
  }): Promise<any>;
64
66
  }
65
67
  export {};
package/lib/core.js CHANGED
@@ -103,6 +103,7 @@ export class SynologyApi extends BaseModuleSynologyApi {
103
103
  "x-syno-token": this.authInfo.synotoken,
104
104
  },
105
105
  data: options.data ?? null,
106
+ responseType: options.responseType ?? "json",
106
107
  };
107
108
  // https agent for node
108
109
  if (isNode) {
@@ -123,7 +124,7 @@ export class SynologyApi extends BaseModuleSynologyApi {
123
124
  const apiKey = getApiKey(apiName);
124
125
  try {
125
126
  let result = (await Axios(requestOptions)).data;
126
- if (!isUndfined(apiKey)) {
127
+ if (!isUndfined(apiKey) && options.responseType === "json") {
127
128
  result = resWithErrorCode(apiKey, result);
128
129
  }
129
130
  return result;
@@ -99,12 +99,4 @@ export declare const SYNOLOGY_ERROR_CODES: {
99
99
  9999: string;
100
100
  };
101
101
  };
102
- export declare const resWithErrorCode: (apiKey: string, res: SynologyApiResponse<any>) => SynologyApiResponse<any> | {
103
- error: {
104
- reason: any;
105
- code: number;
106
- message?: string;
107
- };
108
- data?: any;
109
- success: boolean;
110
- };
102
+ export declare const resWithErrorCode: (apiKey: string, res: SynologyApiResponse<any> | any) => any;
package/lib/helpers.js CHANGED
@@ -22,7 +22,7 @@ const getServersFromServerInfo = async (serverInfo, quickConnectServerType, lanP
22
22
  serverMap[QuickConnectServerType.lan] =
23
23
  `http://${serverInfo.server.interface?.[0].ip}:${serverInfo.service.port}`;
24
24
  }
25
- let server = serverMap[quickConnectServerType];
25
+ const server = serverMap[quickConnectServerType];
26
26
  if (lanPriority && serverMap[QuickConnectServerType.lan]) {
27
27
  const lanServer = serverMap[QuickConnectServerType.lan];
28
28
  if (lanServer && (await pingpang(lanServer))) {
@@ -1,7 +1,8 @@
1
- import { SynologyApiResponse } from "../../types/index.js";
1
+ import { AxiosRequestConfig } from "axios";
2
2
  export type DownloadFileParams = {
3
3
  path: string;
4
4
  mode?: "download" | "open";
5
+ responseType?: AxiosRequestConfig["responseType"];
5
6
  };
6
- export type DownloadFileResponse = SynologyApiResponse<string>;
7
+ export type DownloadFileResponse = DownloadFileParams["responseType"];
7
8
  export declare function getDownloadFile(params: DownloadFileParams): Promise<DownloadFileResponse>;
@@ -1,19 +1,13 @@
1
1
  import { FileStationApi } from "../../types/index.js";
2
- import { buildUrlWithQuery } from "../../utils/index.js";
3
2
  export async function getDownloadFile(params) {
4
- const { path, mode = "download" } = params;
5
- const api = this.getApiInfoByName(FileStationApi.Download);
6
- const query = {
7
- method: "download",
8
- path,
9
- mode,
10
- version: api.maxVersion,
11
- api: FileStationApi.Download,
12
- _sid: this.authInfo.sid,
13
- };
14
- const url = buildUrlWithQuery(`${this.baseUrl}${api.path}`, query);
15
- return {
16
- data: url,
17
- success: true,
18
- };
3
+ const { path, mode = "download", responseType } = params;
4
+ const res = await this.run(FileStationApi.Download, {
5
+ params: {
6
+ path,
7
+ mode,
8
+ method: "download",
9
+ },
10
+ responseType,
11
+ });
12
+ return res;
19
13
  }
@@ -2,15 +2,22 @@ import { FileStationApi } from "../../types/index.js";
2
2
  import { buildUrlWithQuery } from "../../utils/index.js";
3
3
  export async function getThumbUrl(params) {
4
4
  const { path, size = "small", rotate = 0 } = params;
5
+ if (!this.isConnecting) {
6
+ await this.connect();
7
+ }
8
+ const apiInfo = this.getApiInfoByName(FileStationApi.Thumb);
5
9
  const options = await this.genRequestOptions(FileStationApi.Thumb, {
6
- method: "get",
7
10
  params: {
8
11
  path,
9
12
  size,
10
13
  rotate,
14
+ method: "get",
15
+ version: apiInfo.maxVersion || apiInfo.minVersion,
16
+ SynoToken: this.authInfo.synotoken,
17
+ _sid: this.authInfo.sid,
11
18
  },
12
19
  });
13
- const thumbUrl = buildUrlWithQuery(options.url, options.params);
20
+ const thumbUrl = buildUrlWithQuery(`${this.baseUrl}${apiInfo.path}`, options.params);
14
21
  return {
15
22
  success: true,
16
23
  data: thumbUrl,
@@ -12,7 +12,7 @@ export async function uploadFile(params) {
12
12
  }
13
13
  const api = this.getApiInfoByName(FileStationApi.Upload);
14
14
  const { path, file, overwrite = OverwriteEnum.OVERWRITE, create_parents = true } = params;
15
- let formData = createFormData();
15
+ const formData = createFormData();
16
16
  formData.append("method", "upload");
17
17
  formData.append("version", String(api?.maxVersion));
18
18
  formData.append("api", FileStationApi.Upload);
@@ -11,7 +11,7 @@ export async function uploadFile(params) {
11
11
  }
12
12
  const api = this.getApiInfoByName(FileStationApi.Upload);
13
13
  const { path, file, overwrite = OverwriteEnum.OVERWRITE, create_parents = true } = params;
14
- let formData = createFormData();
14
+ const formData = createFormData();
15
15
  formData.append("method", "upload");
16
16
  formData.append("version", String(api?.maxVersion));
17
17
  formData.append("api", FileStationApi.Upload);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fett/synology-api",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "synology api for nodejs",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -58,6 +58,7 @@
58
58
  "pub": "npm publish --access=public",
59
59
  "pub:beta": "npm publish --access=public --tag=beta",
60
60
  "test": "vitest",
61
+ "test:debug": "node --inspect-brk=9230 ./node_modules/vitest/vitest.mjs run --pool=forks",
61
62
  "coverage": "vitest run --coverage"
62
63
  },
63
64
  "devDependencies": {