@fett/synology-api 0.1.2 → 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/lib/core.js CHANGED
@@ -103,10 +103,8 @@ 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
- if (options.responseType) {
108
- requestOptions.responseType = options.responseType;
109
- }
110
108
  // https agent for node
111
109
  if (isNode) {
112
110
  if (this.agent?.https) {
@@ -126,7 +124,7 @@ export class SynologyApi extends BaseModuleSynologyApi {
126
124
  const apiKey = getApiKey(apiName);
127
125
  try {
128
126
  let result = (await Axios(requestOptions)).data;
129
- if (!isUndfined(apiKey)) {
127
+ if (!isUndfined(apiKey) && options.responseType === "json") {
130
128
  result = resWithErrorCode(apiKey, result);
131
129
  }
132
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;
@@ -1,5 +1,8 @@
1
+ import { AxiosRequestConfig } from "axios";
1
2
  export type DownloadFileParams = {
2
3
  path: string;
4
+ mode?: "download" | "open";
5
+ responseType?: AxiosRequestConfig["responseType"];
3
6
  };
4
- export type DownloadFileResponse = Buffer;
5
- export declare function getDownload(params: DownloadFileParams): Promise<DownloadFileResponse>;
7
+ export type DownloadFileResponse = DownloadFileParams["responseType"];
8
+ export declare function getDownloadFile(params: DownloadFileParams): Promise<DownloadFileResponse>;
@@ -1,35 +1,13 @@
1
1
  import { FileStationApi } from "../../types/index.js";
2
- import { isNode } from "../../utils/index.js";
3
- export async function getDownload(params) {
4
- const { path } = params;
2
+ export async function getDownloadFile(params) {
3
+ const { path, mode = "download", responseType } = params;
5
4
  const res = await this.run(FileStationApi.Download, {
6
- responseType: "arraybuffer",
7
5
  params: {
8
6
  path,
9
- mode: "download",
7
+ mode,
8
+ method: "download",
10
9
  },
10
+ responseType,
11
11
  });
12
- return isNode ? Buffer.from(res) : res;
12
+ return res;
13
13
  }
14
- // export async function getFileOpenUrl(params: DownloadFileParams): Promise<{
15
- // data: string;
16
- // success: boolean;
17
- // }> {
18
- // if (!this.isConnecting) {
19
- // await this.connect();
20
- // }
21
- // const { path } = params;
22
- // const apiInfo = this.getApiInfoByName(FileStationApi.Download);
23
- // const url = buildUrlWithQuery(`${this.baseUrl}${apiInfo.path}`, {
24
- // api: FileStationApi.Download,
25
- // method:"download",
26
- // path,
27
- // mode: "open",
28
- // version: apiInfo.maxVersion,
29
- // _sid: this.authInfo?.sid,
30
- // });
31
- // return {
32
- // data: url,
33
- // success: true,
34
- // };
35
- // }
@@ -1,3 +1,4 @@
1
+ import { SynologyApiResponse } from "../../types/index.js";
1
2
  export type GetThumbRequest = {
2
3
  path: string;
3
4
  size?: "small" | "medium" | "large" | "original";
@@ -13,5 +14,5 @@ export type GetThumbRequest = {
13
14
  */
14
15
  rotate?: 0 | 1 | 2 | 3 | 4;
15
16
  };
16
- export type GetThumbResponse = Buffer;
17
- export declare function getThumb(params: GetThumbRequest): Promise<GetThumbResponse>;
17
+ export type GetThumbResponse = SynologyApiResponse<{}>;
18
+ export declare function getThumbUrl(params: GetThumbRequest): Promise<GetThumbResponse>;
@@ -1,14 +1,25 @@
1
1
  import { FileStationApi } from "../../types/index.js";
2
- import { isNode } from "../../utils/index.js";
3
- export async function getThumb(params) {
2
+ import { buildUrlWithQuery } from "../../utils/index.js";
3
+ export async function getThumbUrl(params) {
4
4
  const { path, size = "small", rotate = 0 } = params;
5
- const res = await this.run(FileStationApi.Thumb, {
6
- responseType: "arraybuffer",
5
+ if (!this.isConnecting) {
6
+ await this.connect();
7
+ }
8
+ const apiInfo = this.getApiInfoByName(FileStationApi.Thumb);
9
+ const options = await this.genRequestOptions(FileStationApi.Thumb, {
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
- return isNode ? Buffer.from(res) : res;
20
+ const thumbUrl = buildUrlWithQuery(`${this.baseUrl}${apiInfo.path}`, options.params);
21
+ return {
22
+ success: true,
23
+ data: thumbUrl,
24
+ };
14
25
  }
@@ -6,9 +6,9 @@ import { getFileList, getShareFileList, getVirtualFolderList } from "./List.js";
6
6
  import { addFavorite, deleteFavorite, getFavoriteList, clearBrokenFavorite, editFavorite } from "./Favorite.js";
7
7
  import { startSearch, stopSearch, getSearchList, cleanSearch } from "./Search.js";
8
8
  import { createFolder } from "./CreateFolder.js";
9
- import { getDownload } from "./Download.js";
9
+ import { getDownloadFile } from "./Download.js";
10
10
  import { stopDeleteFile, startDeleteFile, getDeleteFileStatus } from "./Delete.js";
11
- import { getThumb } from "./Thumb.js";
11
+ import { getThumbUrl } from "./Thumb.js";
12
12
  import { startDirSizeCalc, stopDirSizeCalc, getDirSizeCalcStatus } from "./DirSize.js";
13
13
  import { startMD5Calc, stopMD5Calc, getMD5CalcStatus } from "./MD5.js";
14
14
  import { checkPermission } from "./CheckPermission.js";
@@ -31,11 +31,11 @@ export declare const METHODS: {
31
31
  getSearchList: typeof getSearchList;
32
32
  cleanSearch: typeof cleanSearch;
33
33
  createFolder: typeof createFolder;
34
- getDownload: typeof getDownload;
34
+ getDownloadFile: typeof getDownloadFile;
35
35
  stopDeleteFile: typeof stopDeleteFile;
36
36
  startDeleteFile: typeof startDeleteFile;
37
37
  getDeleteFileStatus: typeof getDeleteFileStatus;
38
- getThumb: typeof getThumb;
38
+ getThumbUrl: typeof getThumbUrl;
39
39
  startDirSizeCalc: typeof startDirSizeCalc;
40
40
  stopDirSizeCalc: typeof stopDirSizeCalc;
41
41
  getDirSizeCalcStatus: typeof getDirSizeCalcStatus;
@@ -6,9 +6,9 @@ import { getFileList, getShareFileList, getVirtualFolderList } from "./List.js";
6
6
  import { addFavorite, deleteFavorite, getFavoriteList, clearBrokenFavorite, editFavorite, } from "./Favorite.js";
7
7
  import { startSearch, stopSearch, getSearchList, cleanSearch } from "./Search.js";
8
8
  import { createFolder } from "./CreateFolder.js";
9
- import { getDownload } from "./Download.js";
9
+ import { getDownloadFile } from "./Download.js";
10
10
  import { stopDeleteFile, startDeleteFile, getDeleteFileStatus } from "./Delete.js";
11
- import { getThumb } from "./Thumb.js";
11
+ import { getThumbUrl } from "./Thumb.js";
12
12
  import { startDirSizeCalc, stopDirSizeCalc, getDirSizeCalcStatus } from "./DirSize.js";
13
13
  import { startMD5Calc, stopMD5Calc, getMD5CalcStatus } from "./MD5.js";
14
14
  import { checkPermission } from "./CheckPermission.js";
@@ -32,12 +32,11 @@ export const METHODS = {
32
32
  getSearchList,
33
33
  cleanSearch,
34
34
  createFolder,
35
- getDownload,
36
- // getFileOpenUrl,
35
+ getDownloadFile,
37
36
  stopDeleteFile,
38
37
  startDeleteFile,
39
38
  getDeleteFileStatus,
40
- getThumb,
39
+ getThumbUrl,
41
40
  startDirSizeCalc,
42
41
  stopDirSizeCalc,
43
42
  getDirSizeCalcStatus,
@@ -15,11 +15,11 @@ export declare const METHODS: {
15
15
  getSearchList: typeof import("./Search.js").getSearchList;
16
16
  cleanSearch: typeof import("./Search.js").cleanSearch;
17
17
  createFolder: typeof import("./CreateFolder.js").createFolder;
18
- getDownload: typeof import("./Download.js").getDownload;
18
+ getDownloadFile: typeof import("./Download.js").getDownloadFile;
19
19
  stopDeleteFile: typeof import("./Delete.js").stopDeleteFile;
20
20
  startDeleteFile: typeof import("./Delete.js").startDeleteFile;
21
21
  getDeleteFileStatus: typeof import("./Delete.js").getDeleteFileStatus;
22
- getThumb: typeof import("./Thumb.js").getThumb;
22
+ getThumbUrl: typeof import("./Thumb.js").getThumbUrl;
23
23
  startDirSizeCalc: typeof import("./DirSize.js").startDirSizeCalc;
24
24
  stopDirSizeCalc: typeof import("./DirSize.js").stopDirSizeCalc;
25
25
  getDirSizeCalcStatus: typeof import("./DirSize.js").getDirSizeCalcStatus;
@@ -15,11 +15,11 @@ export declare const METHODS: {
15
15
  getSearchList: typeof import("./Search.js").getSearchList;
16
16
  cleanSearch: typeof import("./Search.js").cleanSearch;
17
17
  createFolder: typeof import("./CreateFolder.js").createFolder;
18
- getDownload: typeof import("./Download.js").getDownload;
18
+ getDownloadFile: typeof import("./Download.js").getDownloadFile;
19
19
  stopDeleteFile: typeof import("./Delete.js").stopDeleteFile;
20
20
  startDeleteFile: typeof import("./Delete.js").startDeleteFile;
21
21
  getDeleteFileStatus: typeof import("./Delete.js").getDeleteFileStatus;
22
- getThumb: typeof import("./Thumb.js").getThumb;
22
+ getThumbUrl: typeof import("./Thumb.js").getThumbUrl;
23
23
  startDirSizeCalc: typeof import("./DirSize.js").startDirSizeCalc;
24
24
  stopDirSizeCalc: typeof import("./DirSize.js").stopDirSizeCalc;
25
25
  getDirSizeCalcStatus: typeof import("./DirSize.js").getDirSizeCalcStatus;
@@ -21,8 +21,7 @@ export async function getStreamUrl(params) {
21
21
  allow_api: VideoStationApi.Streaming,
22
22
  allow_methods: ["stream"],
23
23
  });
24
- const apiInfo = this.getApiInfoByName(VideoStationApi.Streaming);
25
- const url = `${this.baseUrl}${apiInfo.path}/1.mp4`;
24
+ const url = `${this.baseUrl}entry.cgi/1.mp4`;
26
25
  const query = {
27
26
  ...params,
28
27
  api: VideoStationApi.Streaming,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fett/synology-api",
3
- "version": "0.1.2",
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",