@fett/synology-api 0.0.2-beta.2 → 0.0.2

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 (93) hide show
  1. package/lib/core.d.ts +23 -1
  2. package/lib/core.js +53 -20
  3. package/lib/errorcodes.d.ts +21 -4
  4. package/lib/errorcodes.js +27 -6
  5. package/lib/helpers.js +5 -8
  6. package/lib/modules/Api/Auth.js +13 -8
  7. package/lib/modules/Api/Info.js +4 -4
  8. package/lib/modules/AudioStation/Album.d.ts +17 -0
  9. package/lib/modules/AudioStation/Album.js +17 -0
  10. package/lib/modules/AudioStation/Artist.d.ts +16 -0
  11. package/lib/modules/AudioStation/Artist.js +16 -0
  12. package/lib/modules/AudioStation/Folder.d.ts +14 -0
  13. package/lib/modules/AudioStation/Folder.js +14 -0
  14. package/lib/modules/AudioStation/index.d.ts +4 -0
  15. package/lib/modules/AudioStation/index.js +6 -0
  16. package/lib/modules/Auth/AuthKey.js +2 -2
  17. package/lib/modules/Auth/Encryption.d.ts +8 -0
  18. package/lib/modules/Auth/Encryption.js +10 -0
  19. package/lib/modules/Auth/index.d.ts +2 -0
  20. package/lib/modules/Auth/index.js +3 -1
  21. package/lib/modules/Core/System.d.ts +159 -0
  22. package/lib/modules/Core/System.js +42 -0
  23. package/lib/modules/Core/User.d.ts +51 -0
  24. package/lib/modules/Core/User.js +33 -0
  25. package/lib/modules/Core/index.d.ts +14 -0
  26. package/lib/modules/Core/index.js +15 -0
  27. package/lib/modules/Docker/Container.d.ts +43 -0
  28. package/lib/modules/Docker/Container.js +13 -0
  29. package/lib/modules/Docker/Network.d.ts +0 -0
  30. package/lib/modules/Docker/Network.js +0 -0
  31. package/lib/modules/Docker/Project.d.ts +0 -0
  32. package/lib/modules/Docker/Project.js +0 -0
  33. package/lib/modules/Docker/Registry.d.ts +0 -0
  34. package/lib/modules/Docker/Registry.js +0 -0
  35. package/lib/modules/Docker/index.d.ts +7 -0
  36. package/lib/modules/Docker/index.js +8 -0
  37. package/lib/modules/FileStation/BackgroundTask.d.ts +50 -0
  38. package/lib/modules/FileStation/BackgroundTask.js +22 -0
  39. package/lib/modules/FileStation/CheckPermission.d.ts +10 -0
  40. package/lib/modules/FileStation/CheckPermission.js +13 -0
  41. package/lib/modules/FileStation/CopyMove.d.ts +33 -0
  42. package/lib/modules/FileStation/CopyMove.js +28 -0
  43. package/lib/modules/FileStation/CreateFolder.d.ts +15 -0
  44. package/lib/modules/FileStation/CreateFolder.js +12 -0
  45. package/lib/modules/FileStation/Delete.d.ts +54 -0
  46. package/lib/modules/FileStation/Delete.js +35 -0
  47. package/lib/modules/FileStation/DirSize.d.ts +20 -0
  48. package/lib/modules/FileStation/DirSize.js +28 -0
  49. package/lib/modules/FileStation/Download.d.ts +7 -0
  50. package/lib/modules/FileStation/Download.js +19 -0
  51. package/lib/modules/FileStation/Extract.d.ts +1 -0
  52. package/lib/modules/FileStation/Extract.js +1 -0
  53. package/lib/modules/FileStation/Favorite.d.ts +45 -0
  54. package/lib/modules/FileStation/Favorite.js +60 -0
  55. package/lib/modules/FileStation/List.d.ts +39 -11
  56. package/lib/modules/FileStation/List.js +14 -6
  57. package/lib/modules/FileStation/MD5.d.ts +15 -0
  58. package/lib/modules/FileStation/MD5.js +29 -0
  59. package/lib/modules/FileStation/Rename.d.ts +38 -0
  60. package/lib/modules/FileStation/Rename.js +14 -0
  61. package/lib/modules/FileStation/Search.d.ts +40 -0
  62. package/lib/modules/FileStation/Search.js +49 -0
  63. package/lib/modules/FileStation/Sharing.d.ts +69 -0
  64. package/lib/modules/FileStation/Sharing.js +64 -0
  65. package/lib/modules/FileStation/Thumb.d.ts +18 -0
  66. package/lib/modules/FileStation/Thumb.js +18 -0
  67. package/lib/modules/FileStation/Upload.d.ts +21 -0
  68. package/lib/modules/FileStation/Upload.js +44 -0
  69. package/lib/modules/FileStation/index.d.ts +52 -2
  70. package/lib/modules/FileStation/index.js +53 -3
  71. package/lib/modules/VideoStation/Library.d.ts +4 -5
  72. package/lib/modules/VideoStation/Streaming.d.ts +5 -6
  73. package/lib/modules/VideoStation/Streaming.js +39 -13
  74. package/lib/modules/VideoStation/index.js +1 -1
  75. package/lib/modules/index.d.ts +12 -10
  76. package/lib/modules/index.js +13 -12
  77. package/lib/types/apiInfo.d.ts +55 -4
  78. package/lib/types/apiInfo.js +62 -9
  79. package/lib/{utils.js → utils/common.js} +1 -1
  80. package/lib/utils/encryption.d.ts +12 -0
  81. package/lib/utils/encryption.js +38 -0
  82. package/lib/utils/env.d.ts +2 -0
  83. package/lib/utils/env.js +2 -0
  84. package/lib/utils/formData.d.ts +2 -0
  85. package/lib/utils/formData.js +19 -0
  86. package/lib/utils/index.d.ts +4 -0
  87. package/lib/utils/index.js +4 -0
  88. package/package.json +7 -2
  89. package/lib/modules/VideoStation/HomeVideo.d.ts +0 -6
  90. package/lib/modules/VideoStation/HomeVideo.js +0 -10
  91. /package/lib/modules/{FileStation/File.d.ts → Docker/Image.d.ts} +0 -0
  92. /package/lib/modules/{FileStation/File.js → Docker/Image.js} +0 -0
  93. /package/lib/{utils.d.ts → utils/common.d.ts} +0 -0
@@ -0,0 +1,18 @@
1
+ import { SynologyApiResponse } from "../../types/index.js";
2
+ export type GetThumbRequest = {
3
+ path: string;
4
+ size?: "small" | "medium" | "large" | "original";
5
+ /**
6
+ Optional. Return rotated
7
+ thumbnail.
8
+ Rotate Options:
9
+ 0: Do not rotate.
10
+ 1: Rotate 90°.
11
+ 2: Rotate 180°.
12
+ 3: Rotate 270°.
13
+ 4: Rotate 360°.
14
+ */
15
+ rotate?: 0 | 1 | 2 | 3 | 4;
16
+ };
17
+ export type GetThumbResponse = SynologyApiResponse<{}>;
18
+ export declare function getThumbUrl(params: GetThumbRequest): Promise<GetThumbResponse>;
@@ -0,0 +1,18 @@
1
+ import { FileStationApi } from "../../types/index.js";
2
+ import { buildUrlWithQuery } from "../../utils/index.js";
3
+ export async function getThumbUrl(params) {
4
+ const { path, size = "small", rotate = 0 } = params;
5
+ const options = await this.genRequestOptions(FileStationApi.Thumb, {
6
+ method: "get",
7
+ params: {
8
+ path,
9
+ size,
10
+ rotate,
11
+ },
12
+ });
13
+ const thumbUrl = buildUrlWithQuery(options.url, options.params);
14
+ return {
15
+ success: true,
16
+ data: thumbUrl,
17
+ };
18
+ }
@@ -0,0 +1,21 @@
1
+ import { AxiosProgressEvent } from "axios";
2
+ import { SynologyApiResponse } from "../../types/index.js";
3
+ declare enum OverwriteEnum {
4
+ OVERWRITE = "overwrite",
5
+ SKIP = "skip"
6
+ }
7
+ export type UploadFileParams = {
8
+ path: string;
9
+ file: File | Blob | string | any;
10
+ overwrite?: OverwriteEnum;
11
+ create_parents?: boolean;
12
+ onUploadProgress?: (progress: AxiosProgressEvent) => void;
13
+ };
14
+ export type UploadFileResponse = SynologyApiResponse<{
15
+ blSkip: boolean;
16
+ file: string;
17
+ pid: number;
18
+ progress: number;
19
+ }>;
20
+ export declare function uploadFile(params: UploadFileParams): Promise<UploadFileResponse>;
21
+ export {};
@@ -0,0 +1,44 @@
1
+ import { isNode, createFormData, getFormDataHeaders } from "../../utils/index.js";
2
+ import { FileStationApi } from "../../types/index.js";
3
+ var OverwriteEnum;
4
+ (function (OverwriteEnum) {
5
+ OverwriteEnum["OVERWRITE"] = "overwrite";
6
+ OverwriteEnum["SKIP"] = "skip";
7
+ })(OverwriteEnum || (OverwriteEnum = {}));
8
+ export async function uploadFile(params) {
9
+ if (!this.isConnecting) {
10
+ await this.connect();
11
+ }
12
+ const { path, file, overwrite = OverwriteEnum.OVERWRITE, create_parents = true } = params;
13
+ const api = this.getApiInfoByName(FileStationApi.Upload);
14
+ let fileContent = file;
15
+ let fileName = "";
16
+ let formData = createFormData();
17
+ formData.append("method", "upload");
18
+ formData.append("version", String(api?.maxVersion));
19
+ formData.append("api", FileStationApi.Upload);
20
+ formData.append("path", path);
21
+ formData.append("overwrite", overwrite);
22
+ formData.append("create_parents", String(create_parents));
23
+ // nodejs environment
24
+ if (isNode) {
25
+ if (typeof file === "string") {
26
+ fileName = require("path").basename(file);
27
+ fileContent = await require("node:fs/promises").readFile(file);
28
+ }
29
+ formData.append("file", fileContent, {
30
+ filename: fileName,
31
+ contentType: "application/octet-stream", // 可根据文件类型修改
32
+ });
33
+ }
34
+ else {
35
+ // for browser environment
36
+ formData.append("file", file);
37
+ }
38
+ const res = this.run(FileStationApi.Upload, {
39
+ method: "post",
40
+ data: formData,
41
+ headers: getFormDataHeaders(formData),
42
+ });
43
+ return res;
44
+ }
@@ -2,11 +2,61 @@
2
2
  * reference :https://global.download.synology.com/download/Document/Software/DeveloperGuide/Package/FileStation/All/enu/Synology_File_Station_API_Guide.pdf
3
3
  */
4
4
  import { getInfo } from "./Info.js";
5
- import { getFileList, getFileListShare } from "./List.js";
5
+ import { getFileList, getShareFileList, getVirtualFolderList } from "./List.js";
6
+ import { addFavorite, deleteFavorite, getFavoriteList, clearBrokenFavorite, editFavorite } from "./Favorite.js";
7
+ import { startSearch, stopSearch, getSearchList, cleanSearch } from "./Search.js";
8
+ import { createFolder } from "./CreateFolder.js";
9
+ import { getDownloadFile } from "./Download.js";
10
+ import { stopDeleteFile, startDeleteFile, getDeleteFileStatus } from "./Delete.js";
11
+ import { uploadFile } from "./Upload.js";
12
+ import { getThumbUrl } from "./Thumb.js";
13
+ import { startDirSizeCalc, stopDirSizeCalc, getDirSizeCalcStatus } from "./DirSize.js";
14
+ import { startMD5Calc, stopMD5Calc, getMD5CalcStatus } from "./MD5.js";
15
+ import { checkPermission } from "./CheckPermission.js";
16
+ import { rename } from "./Rename.js";
17
+ import { startCopyMove, getCopyMoveStatus, stopCopyMove } from "./CopyMove.js";
18
+ import { getSharingInfo, getSharingList, createSharingLink, deleteSharingLink, editSharingLink, clearInvalidSharingLink } from "./Sharing.js";
19
+ import { getBackgroundTaskList, clearFinishedBackgroundTasks } from "./BackgroundTask.js";
6
20
  export declare const METHODS: {
7
21
  getInfo: typeof getInfo;
8
22
  getFileList: typeof getFileList;
9
- getFileListShare: typeof getFileListShare;
23
+ getShareFileList: typeof getShareFileList;
24
+ getVirtualFolderList: typeof getVirtualFolderList;
25
+ getFavoriteList: typeof getFavoriteList;
26
+ addFavorite: typeof addFavorite;
27
+ deleteFavorite: typeof deleteFavorite;
28
+ editFavorite: typeof editFavorite;
29
+ clearBrokenFavorite: typeof clearBrokenFavorite;
30
+ startSearch: typeof startSearch;
31
+ stopSearch: typeof stopSearch;
32
+ getSearchList: typeof getSearchList;
33
+ cleanSearch: typeof cleanSearch;
34
+ createFolder: typeof createFolder;
35
+ getDownloadFile: typeof getDownloadFile;
36
+ stopDeleteFile: typeof stopDeleteFile;
37
+ startDeleteFile: typeof startDeleteFile;
38
+ getDeleteFileStatus: typeof getDeleteFileStatus;
39
+ uploadFile: typeof uploadFile;
40
+ getThumbUrl: typeof getThumbUrl;
41
+ startDirSizeCalc: typeof startDirSizeCalc;
42
+ stopDirSizeCalc: typeof stopDirSizeCalc;
43
+ getDirSizeCalcStatus: typeof getDirSizeCalcStatus;
44
+ startMD5Calc: typeof startMD5Calc;
45
+ getMD5CalcStatus: typeof getMD5CalcStatus;
46
+ stopMD5Calc: typeof stopMD5Calc;
47
+ checkPermission: typeof checkPermission;
48
+ rename: typeof rename;
49
+ clearFinishedBackgroundTasks: typeof clearFinishedBackgroundTasks;
50
+ getBackgroundTaskList: typeof getBackgroundTaskList;
51
+ getSharingInfo: typeof getSharingInfo;
52
+ getSharingList: typeof getSharingList;
53
+ createSharingLink: typeof createSharingLink;
54
+ deleteSharingLink: typeof deleteSharingLink;
55
+ editSharingLink: typeof editSharingLink;
56
+ clearInvalidSharingLink: typeof clearInvalidSharingLink;
57
+ startCopyMove: typeof startCopyMove;
58
+ getCopyMoveStatus: typeof getCopyMoveStatus;
59
+ stopCopyMove: typeof stopCopyMove;
10
60
  };
11
61
  export declare const KEY = "FileStation";
12
62
  export declare const ALIAS_KEY = "fs";
@@ -2,12 +2,62 @@
2
2
  * reference :https://global.download.synology.com/download/Document/Software/DeveloperGuide/Package/FileStation/All/enu/Synology_File_Station_API_Guide.pdf
3
3
  */
4
4
  import { getInfo } from "./Info.js";
5
- import { getFileList, getFileListShare } from "./List.js";
6
- // fs methods
5
+ import { getFileList, getShareFileList, getVirtualFolderList } from "./List.js";
6
+ import { addFavorite, deleteFavorite, getFavoriteList, clearBrokenFavorite, editFavorite, } from "./Favorite.js";
7
+ import { startSearch, stopSearch, getSearchList, cleanSearch } from "./Search.js";
8
+ import { createFolder } from "./CreateFolder.js";
9
+ import { getDownloadFile } from "./Download.js";
10
+ import { stopDeleteFile, startDeleteFile, getDeleteFileStatus } from "./Delete.js";
11
+ import { uploadFile } from "./Upload.js";
12
+ import { getThumbUrl } from "./Thumb.js";
13
+ import { startDirSizeCalc, stopDirSizeCalc, getDirSizeCalcStatus } from "./DirSize.js";
14
+ import { startMD5Calc, stopMD5Calc, getMD5CalcStatus } from "./MD5.js";
15
+ import { checkPermission } from "./CheckPermission.js";
16
+ import { rename } from "./Rename.js";
17
+ import { startCopyMove, getCopyMoveStatus, stopCopyMove } from "./CopyMove.js";
18
+ import { getSharingInfo, getSharingList, createSharingLink, deleteSharingLink, editSharingLink, clearInvalidSharingLink, } from "./Sharing.js";
19
+ import { getBackgroundTaskList, clearFinishedBackgroundTasks } from "./BackgroundTask.js";
20
+ // methods
7
21
  export const METHODS = {
8
22
  getInfo,
9
23
  getFileList,
10
- getFileListShare,
24
+ getShareFileList,
25
+ getVirtualFolderList,
26
+ getFavoriteList,
27
+ addFavorite,
28
+ deleteFavorite,
29
+ editFavorite,
30
+ clearBrokenFavorite,
31
+ startSearch,
32
+ stopSearch,
33
+ getSearchList,
34
+ cleanSearch,
35
+ createFolder,
36
+ getDownloadFile,
37
+ stopDeleteFile,
38
+ startDeleteFile,
39
+ getDeleteFileStatus,
40
+ uploadFile,
41
+ getThumbUrl,
42
+ startDirSizeCalc,
43
+ stopDirSizeCalc,
44
+ getDirSizeCalcStatus,
45
+ startMD5Calc,
46
+ getMD5CalcStatus,
47
+ stopMD5Calc,
48
+ checkPermission,
49
+ rename,
50
+ clearFinishedBackgroundTasks,
51
+ getBackgroundTaskList,
52
+ getSharingInfo,
53
+ getSharingList,
54
+ createSharingLink,
55
+ deleteSharingLink,
56
+ editSharingLink,
57
+ clearInvalidSharingLink,
58
+ startCopyMove,
59
+ getCopyMoveStatus,
60
+ stopCopyMove,
11
61
  };
12
62
  // name space
13
63
  export const KEY = "FileStation";
@@ -31,13 +31,12 @@ interface File {
31
31
  video_profile: number;
32
32
  watched_ratio: number;
33
33
  }
34
- export type Additional = {
35
- file: File[];
36
- watched_ratio: number;
37
- };
38
34
  export type VideoStationAcrossLibraryResponse = SynologyApiResponse<{
39
35
  movie: Array<{
40
- additional: Additional;
36
+ additional: {
37
+ file: File[];
38
+ watched_ratio: number;
39
+ };
41
40
  certificate: string;
42
41
  create_time: number;
43
42
  id: number;
@@ -1,11 +1,10 @@
1
1
  import { SynologyApiResponse } from "../../types/index.js";
2
- export type VideoStationGetStreamUrlParams = {
3
- stream_id: string;
4
- tid: string;
5
- };
6
- export type VideoStationGetStreamUrlResponse = SynologyApiResponse<string>;
7
- export declare function getStreamUrl(params: VideoStationGetStreamUrlParams): Promise<string>;
8
2
  export declare function getStreamId(id: number): Promise<SynologyApiResponse<{
9
3
  format: string;
10
4
  stream_id: string;
11
5
  }>>;
6
+ export type VideoStationGetStreamUrlParams = {
7
+ id: number;
8
+ };
9
+ export type VideoStationGetStreamUrlResponse = SynologyApiResponse<string>;
10
+ export declare function getStreamUrl(params: VideoStationGetStreamUrlParams): Promise<VideoStationGetStreamUrlResponse>;
@@ -1,17 +1,5 @@
1
- import { buildUrlWithQuery } from "../../utils.js";
1
+ import { buildUrlWithQuery } from "../../utils/index.js";
2
2
  import { VideoStationApi } from "../../types/index.js";
3
- export async function getStreamUrl(params) {
4
- const url = `${this.baseUrl}entry.cgi/1.mp4`;
5
- const query = {
6
- ...params,
7
- api: VideoStationApi.Streaming,
8
- method: "stream",
9
- format: "raw",
10
- version: 2,
11
- _sid: this.authInfo?.sid,
12
- };
13
- return buildUrlWithQuery(url, query);
14
- }
15
3
  // 基于视频ID获取播放流ID
16
4
  export async function getStreamId(id) {
17
5
  return await this.run(VideoStationApi.Streaming, {
@@ -22,3 +10,41 @@ export async function getStreamId(id) {
22
10
  },
23
11
  });
24
12
  }
13
+ export async function getStreamUrl(params) {
14
+ try {
15
+ const movies = await this.vs.getMoiveInfo({
16
+ id: [params.id],
17
+ });
18
+ const fileInfo = movies?.data?.movie?.[0]?.additional?.file?.[0];
19
+ const result = await this.vs.getStreamId(fileInfo.id);
20
+ const streamGrant = await this.au.getAuthKeyGrant({
21
+ allow_api: VideoStationApi.Streaming,
22
+ allow_methods: ["stream"],
23
+ });
24
+ const url = `${this.baseUrl}entry.cgi/1.mp4`;
25
+ const query = {
26
+ ...params,
27
+ api: VideoStationApi.Streaming,
28
+ method: "stream",
29
+ format: "raw",
30
+ version: 2,
31
+ _sid: this.authInfo?.sid,
32
+ stream_id: `"${result.data.stream_id}"`,
33
+ tid: `"${streamGrant.data.tid}"`,
34
+ };
35
+ return {
36
+ success: true,
37
+ data: buildUrlWithQuery(url, query),
38
+ };
39
+ }
40
+ catch (e) {
41
+ return {
42
+ success: false,
43
+ data: "",
44
+ error: {
45
+ code: 0,
46
+ message: e.message,
47
+ },
48
+ };
49
+ }
50
+ }
@@ -2,7 +2,7 @@ import { getInfo } from "./Info.js";
2
2
  import { getAcrossLibrary, getLibrary } from "./Library.js";
3
3
  import { getStreamUrl, getStreamId } from "./Streaming.js";
4
4
  import { getMoiveInfo } from "./Movie.js";
5
- // fs methods
5
+ // methods
6
6
  export const METHODS = {
7
7
  getInfo,
8
8
  getAcrossLibrary,
@@ -2,17 +2,14 @@ import * as AudioStation from "./AudioStation/index.js";
2
2
  import * as FileStation from "./FileStation/index.js";
3
3
  import * as VideoStation from "./VideoStation/index.js";
4
4
  import * as Auth from "./Auth/index.js";
5
- export declare const SynologyApiModules: (typeof AudioStation | typeof FileStation | typeof VideoStation | typeof Auth)[];
6
- export declare const SynologyApiKeys: {
7
- FileStation: string;
8
- fs: string;
9
- AudioStation: string;
10
- as: string;
11
- VideoStation: string;
12
- vs: string;
13
- Auth: string;
14
- au: string;
5
+ import * as Core from "./Core/index.js";
6
+ import * as Docker from "./Docker/index.js";
7
+ type EnumFromArray<T extends string[]> = {
8
+ [K in T[number]]: K;
15
9
  };
10
+ export declare const SynologyApiModules: (typeof AudioStation | typeof FileStation | typeof VideoStation | typeof Auth | typeof Core | typeof Docker)[];
11
+ export declare const SynologyApiKeys: any[];
12
+ export declare const SynologyApiKeysMap: EnumFromArray<typeof SynologyApiKeys>;
16
13
  export declare const SynologyApiMethods: {};
17
14
  export declare class BaseSynologyApi {
18
15
  [AudioStation.KEY]: AudioStation.TMethods;
@@ -23,5 +20,10 @@ export declare class BaseSynologyApi {
23
20
  [VideoStation.ALIAS_KEY]: VideoStation.TMethods;
24
21
  [Auth.KEY]: Auth.TMethods;
25
22
  [Auth.ALIAS_KEY]: Auth.TMethods;
23
+ [Core.KEY]: Core.TMethods;
24
+ [Core.ALIAS_KEY]: Core.TMethods;
25
+ [Docker.KEY]: Docker.TMethods;
26
+ [Docker.ALIAS_KEY]: Docker.TMethods;
26
27
  constructor();
27
28
  }
29
+ export {};
@@ -36,18 +36,19 @@ import * as AudioStation from "./AudioStation/index.js";
36
36
  import * as FileStation from "./FileStation/index.js";
37
37
  import * as VideoStation from "./VideoStation/index.js";
38
38
  import * as Auth from "./Auth/index.js";
39
+ import * as Core from "./Core/index.js";
40
+ import * as Docker from "./Docker/index.js";
39
41
  import { BindMethods } from "../decorators/index.js";
40
- export const SynologyApiModules = [FileStation, AudioStation, VideoStation, Auth];
41
- export const SynologyApiKeys = {
42
- FileStation: FileStation.KEY,
43
- fs: FileStation.ALIAS_KEY,
44
- AudioStation: AudioStation.KEY,
45
- as: AudioStation.ALIAS_KEY,
46
- VideoStation: VideoStation.KEY,
47
- vs: VideoStation.ALIAS_KEY,
48
- Auth: Auth.KEY,
49
- au: Auth.ALIAS_KEY,
50
- };
42
+ export const SynologyApiModules = [FileStation, AudioStation, VideoStation, Auth, Core, Docker];
43
+ export const SynologyApiKeys = SynologyApiModules.reduce((acc, module) => {
44
+ acc = { ...acc, [module.KEY]: module.KEY, [module.ALIAS_KEY]: module.ALIAS_KEY };
45
+ return acc;
46
+ }, []);
47
+ export const SynologyApiKeysMap = SynologyApiModules.reduce((acc, module) => {
48
+ acc[module.KEY] = module.KEY;
49
+ acc[module.ALIAS_KEY] = module.ALIAS_KEY;
50
+ return acc;
51
+ }, {});
51
52
  export const SynologyApiMethods = SynologyApiModules.reduce((acc, module) => {
52
53
  acc[module.KEY] = module.METHODS;
53
54
  acc[module.ALIAS_KEY] = module.METHODS;
@@ -60,7 +61,7 @@ let BaseSynologyApi = (() => {
60
61
  let _classThis;
61
62
  var BaseSynologyApi = class {
62
63
  static { _classThis = this; }
63
- static { AudioStation.KEY, AudioStation.ALIAS_KEY, FileStation.KEY, FileStation.ALIAS_KEY, VideoStation.KEY, VideoStation.ALIAS_KEY, Auth.KEY, Auth.ALIAS_KEY; }
64
+ static { AudioStation.KEY, AudioStation.ALIAS_KEY, FileStation.KEY, FileStation.ALIAS_KEY, VideoStation.KEY, VideoStation.ALIAS_KEY, Auth.KEY, Auth.ALIAS_KEY, Core.KEY, Core.ALIAS_KEY, Docker.KEY, Docker.ALIAS_KEY; }
64
65
  static {
65
66
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
66
67
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * api info
3
3
  * */
4
- export declare enum SynologyApiInfo {
4
+ export declare enum SynoApi {
5
5
  Auth = "SYNO.API.Auth",
6
6
  Info = "SYNO.API.Info",
7
7
  OTP = "SYNO.API.OTP",
8
- AuthKey = "SYNO.API.Auth.Key"
8
+ AuthKey = "SYNO.API.Auth.Key",
9
+ Encryption = "SYNO.API.Encryption"
9
10
  }
10
11
  /**
11
12
  * AudioStation
@@ -31,12 +32,26 @@ export declare enum AudioStationApi {
31
32
  */
32
33
  export declare enum FileStationApi {
33
34
  File = "SYNO.FileStation.File",
35
+ Delete = "SYNO.FileStation.Delete",
34
36
  Info = "SYNO.FileStation.Info",
37
+ Favorite = "SYNO.FileStation.Favorite",
38
+ Search = "SYNO.FileStation.Search",
35
39
  List = "SYNO.FileStation.List",
36
- Quota = "SYNO.FileStation.Quota",
37
40
  Share = "SYNO.FileStation.Share",
41
+ Upload = "SYNO.FileStation.Upload",
42
+ Download = "SYNO.FileStation.Download",
43
+ VirtualFolder = "SYNO.FileStation.VirtualFolder",
38
44
  Thumb = "SYNO.FileStation.Thumb",
39
- Upload = "SYNO.FileStation.Upload"
45
+ DirSize = "SYNO.FileStation.DirSize",
46
+ MD5 = "SYNO.FileStation.MD5",
47
+ CheckPermission = "SYNO.FileStation.CheckPermission",
48
+ Sharing = "SYNO.FileStation.Sharing",
49
+ CreateFolder = "SYNO.FileStation.CreateFolder",
50
+ Rename = "SYNO.FileStation.Rename",
51
+ CopyMove = "SYNO.FileStation.CopyMove",
52
+ Extract = "SYNO.FileStation.Extract",
53
+ Compress = "SYNO.FileStation.Compress",
54
+ BackgroundTask = "SYNO.FileStation.BackgroundTask"
40
55
  }
41
56
  /**
42
57
  * VideoStation API
@@ -50,3 +65,39 @@ export declare enum VideoStationApi {
50
65
  Streaming = "SYNO.VideoStation2.Streaming",
51
66
  Movie = "SYNO.VideoStation2.Movie"
52
67
  }
68
+ /**
69
+ * core api
70
+ */
71
+ export declare enum CoreApi {
72
+ /**
73
+ * package api
74
+ */
75
+ Package = "SYNO.Core.Package",
76
+ PackageControl = "SYNO.Core.Package.Control",
77
+ /**
78
+ * System api
79
+ */
80
+ System = "SYNO.Core.System",
81
+ SystemProcess = "SYNO.Core.System.Process",
82
+ SystemStatus = "SYNO.Core.System.Status",
83
+ SystemUtilization = "SYNO.Core.System.Utilization",
84
+ SystemHealth = "SYNO.Core.System.SystemHealth",
85
+ /**
86
+ * User api
87
+ * */
88
+ User = "SYNO.Core.User",
89
+ Group = "SYNO.Core.User.Group",
90
+ PasswordPolicy = "SYNO.Core.User.PasswordPolicy",
91
+ PasswordExpiry = "SYNO.Core.User.PasswordExpiry",
92
+ PasswordConfirm = "SYNO.Core.User.PasswordConfirm",
93
+ UsernamePolicy = "SYNO.Core.User.UsernamePolicy"
94
+ }
95
+ /**
96
+ * docker api
97
+ */
98
+ export declare enum DockerApi {
99
+ Container = "SYNO.Docker.Container",
100
+ Image = "SYNO.Docker.Image",
101
+ Network = "SYNO.Docker.Network",
102
+ Migrate = "SYNO.Docker.Migrate"
103
+ }
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * api info
3
3
  * */
4
- export var SynologyApiInfo;
5
- (function (SynologyApiInfo) {
6
- SynologyApiInfo["Auth"] = "SYNO.API.Auth";
7
- SynologyApiInfo["Info"] = "SYNO.API.Info";
8
- SynologyApiInfo["OTP"] = "SYNO.API.OTP";
9
- SynologyApiInfo["AuthKey"] = "SYNO.API.Auth.Key";
10
- })(SynologyApiInfo || (SynologyApiInfo = {}));
4
+ export var SynoApi;
5
+ (function (SynoApi) {
6
+ SynoApi["Auth"] = "SYNO.API.Auth";
7
+ SynoApi["Info"] = "SYNO.API.Info";
8
+ SynoApi["OTP"] = "SYNO.API.OTP";
9
+ SynoApi["AuthKey"] = "SYNO.API.Auth.Key";
10
+ SynoApi["Encryption"] = "SYNO.API.Encryption";
11
+ })(SynoApi || (SynoApi = {}));
11
12
  /**
12
13
  * AudioStation
13
14
  * */
@@ -34,12 +35,26 @@ export var AudioStationApi;
34
35
  export var FileStationApi;
35
36
  (function (FileStationApi) {
36
37
  FileStationApi["File"] = "SYNO.FileStation.File";
38
+ FileStationApi["Delete"] = "SYNO.FileStation.Delete";
37
39
  FileStationApi["Info"] = "SYNO.FileStation.Info";
40
+ FileStationApi["Favorite"] = "SYNO.FileStation.Favorite";
41
+ FileStationApi["Search"] = "SYNO.FileStation.Search";
38
42
  FileStationApi["List"] = "SYNO.FileStation.List";
39
- FileStationApi["Quota"] = "SYNO.FileStation.Quota";
40
43
  FileStationApi["Share"] = "SYNO.FileStation.Share";
41
- FileStationApi["Thumb"] = "SYNO.FileStation.Thumb";
42
44
  FileStationApi["Upload"] = "SYNO.FileStation.Upload";
45
+ FileStationApi["Download"] = "SYNO.FileStation.Download";
46
+ FileStationApi["VirtualFolder"] = "SYNO.FileStation.VirtualFolder";
47
+ FileStationApi["Thumb"] = "SYNO.FileStation.Thumb";
48
+ FileStationApi["DirSize"] = "SYNO.FileStation.DirSize";
49
+ FileStationApi["MD5"] = "SYNO.FileStation.MD5";
50
+ FileStationApi["CheckPermission"] = "SYNO.FileStation.CheckPermission";
51
+ FileStationApi["Sharing"] = "SYNO.FileStation.Sharing";
52
+ FileStationApi["CreateFolder"] = "SYNO.FileStation.CreateFolder";
53
+ FileStationApi["Rename"] = "SYNO.FileStation.Rename";
54
+ FileStationApi["CopyMove"] = "SYNO.FileStation.CopyMove";
55
+ FileStationApi["Extract"] = "SYNO.FileStation.Extract";
56
+ FileStationApi["Compress"] = "SYNO.FileStation.Compress";
57
+ FileStationApi["BackgroundTask"] = "SYNO.FileStation.BackgroundTask";
43
58
  })(FileStationApi || (FileStationApi = {}));
44
59
  /**
45
60
  * VideoStation API
@@ -54,3 +69,41 @@ export var VideoStationApi;
54
69
  VideoStationApi["Streaming"] = "SYNO.VideoStation2.Streaming";
55
70
  VideoStationApi["Movie"] = "SYNO.VideoStation2.Movie";
56
71
  })(VideoStationApi || (VideoStationApi = {}));
72
+ /**
73
+ * core api
74
+ */
75
+ export var CoreApi;
76
+ (function (CoreApi) {
77
+ /**
78
+ * package api
79
+ */
80
+ CoreApi["Package"] = "SYNO.Core.Package";
81
+ CoreApi["PackageControl"] = "SYNO.Core.Package.Control";
82
+ /**
83
+ * System api
84
+ */
85
+ CoreApi["System"] = "SYNO.Core.System";
86
+ CoreApi["SystemProcess"] = "SYNO.Core.System.Process";
87
+ CoreApi["SystemStatus"] = "SYNO.Core.System.Status";
88
+ CoreApi["SystemUtilization"] = "SYNO.Core.System.Utilization";
89
+ CoreApi["SystemHealth"] = "SYNO.Core.System.SystemHealth";
90
+ /**
91
+ * User api
92
+ * */
93
+ CoreApi["User"] = "SYNO.Core.User";
94
+ CoreApi["Group"] = "SYNO.Core.User.Group";
95
+ CoreApi["PasswordPolicy"] = "SYNO.Core.User.PasswordPolicy";
96
+ CoreApi["PasswordExpiry"] = "SYNO.Core.User.PasswordExpiry";
97
+ CoreApi["PasswordConfirm"] = "SYNO.Core.User.PasswordConfirm";
98
+ CoreApi["UsernamePolicy"] = "SYNO.Core.User.UsernamePolicy";
99
+ })(CoreApi || (CoreApi = {}));
100
+ /**
101
+ * docker api
102
+ */
103
+ export var DockerApi;
104
+ (function (DockerApi) {
105
+ DockerApi["Container"] = "SYNO.Docker.Container";
106
+ DockerApi["Image"] = "SYNO.Docker.Image";
107
+ DockerApi["Network"] = "SYNO.Docker.Network";
108
+ DockerApi["Migrate"] = "SYNO.Docker.Migrate";
109
+ })(DockerApi || (DockerApi = {}));
@@ -16,7 +16,7 @@ export function isUndfined(value) {
16
16
  return value === undefined;
17
17
  }
18
18
  export function getApiKey(apiName) {
19
- return apiName.split('.')[1];
19
+ return apiName.split(".")[1];
20
20
  }
21
21
  export function buildUrlWithQuery(url, query) {
22
22
  return `${url}?${queryObjToString(query)}`;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generate a random passphrase
3
+ * @param length The length of the passphrase
4
+ * @returns A random passphrase
5
+ */
6
+ export declare function genRandomPassphrase(length: number): string;
7
+ /**
8
+ * RSA encrypt
9
+ * @param publicKey The public key
10
+ * @param plaintext The plaintext to encrypt
11
+ * @returns The encrypted text
12
+ */
@@ -0,0 +1,38 @@
1
+ // import crypto from "crypto";
2
+ /**
3
+ * Generate a random passphrase
4
+ * @param length The length of the passphrase
5
+ * @returns A random passphrase
6
+ */
7
+ export function genRandomPassphrase(length) {
8
+ const charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+-/";
9
+ const passphrase = new Array(length)
10
+ .fill(0)
11
+ .map(() => charset.charAt(Math.floor(Math.random() * charset.length)))
12
+ .join("");
13
+ return passphrase;
14
+ }
15
+ /**
16
+ * RSA encrypt
17
+ * @param publicKey The public key
18
+ * @param plaintext The plaintext to encrypt
19
+ * @returns The encrypted text
20
+ */
21
+ // export function rsaEncrypt(publicKey: string, plaintext: string) {
22
+ // const encrypted = crypto.publicEncrypt(
23
+ // {
24
+ // key: publicKey,
25
+ // padding: crypto.constants.RSA_PKCS1_OAEP_PADDING, // 推荐使用 OAEP 填充方式,更安全
26
+ // },
27
+ // Buffer.from(plaintext, "utf8")
28
+ // );
29
+ // const encryptedBase64 = encrypted.toString("base64");
30
+ // return encryptedBase64;
31
+ // }
32
+ // export function aesEncrypt(plaintext: string, key: string) {
33
+ // const iv = crypto.randomBytes(12);
34
+ // const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
35
+ // const encrypted = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
36
+ // const tag = cipher.getAuthTag();
37
+ // return `${iv.toString('base64')}:${encrypted.toString('base64')}:${tag.toString('base64')}`;
38
+ // }
@@ -0,0 +1,2 @@
1
+ export declare const isBrowser: boolean;
2
+ export declare const isNode: boolean;
@@ -0,0 +1,2 @@
1
+ export const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
2
+ export const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;