@fett/synology-api 0.0.2-beta.1 → 0.0.2-beta.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/cli/apis.js +3 -0
- package/lib/core.d.ts +23 -1
- package/lib/core.js +53 -20
- package/lib/errorcodes.d.ts +21 -4
- package/lib/errorcodes.js +27 -6
- package/lib/helpers.js +5 -8
- package/lib/modules/Api/Auth.js +13 -8
- package/lib/modules/Api/Info.js +4 -4
- package/lib/modules/AudioStation/Album.d.ts +17 -0
- package/lib/modules/AudioStation/Album.js +17 -0
- package/lib/modules/AudioStation/Artist.d.ts +16 -0
- package/lib/modules/AudioStation/Artist.js +16 -0
- package/lib/modules/AudioStation/Folder.d.ts +14 -0
- package/lib/modules/AudioStation/Folder.js +14 -0
- package/lib/modules/AudioStation/index.d.ts +4 -0
- package/lib/modules/AudioStation/index.js +6 -0
- package/lib/modules/Auth/AuthKey.js +2 -2
- package/lib/modules/Auth/Encryption.d.ts +8 -0
- package/lib/modules/Auth/Encryption.js +10 -0
- package/lib/modules/Auth/index.d.ts +2 -0
- package/lib/modules/Auth/index.js +3 -1
- package/lib/modules/Core/System.d.ts +159 -0
- package/lib/modules/Core/System.js +42 -0
- package/lib/modules/Core/User.d.ts +51 -0
- package/lib/modules/Core/User.js +33 -0
- package/lib/modules/Core/index.d.ts +14 -0
- package/lib/modules/Core/index.js +15 -0
- package/lib/modules/Docker/Container.d.ts +43 -0
- package/lib/modules/Docker/Container.js +13 -0
- package/lib/modules/Docker/Network.d.ts +0 -0
- package/lib/modules/Docker/Network.js +0 -0
- package/lib/modules/Docker/Project.d.ts +0 -0
- package/lib/modules/Docker/Project.js +0 -0
- package/lib/modules/Docker/Registry.d.ts +0 -0
- package/lib/modules/Docker/Registry.js +0 -0
- package/lib/modules/Docker/index.d.ts +7 -0
- package/lib/modules/Docker/index.js +8 -0
- package/lib/modules/FileStation/BackgroundTask.d.ts +50 -0
- package/lib/modules/FileStation/BackgroundTask.js +22 -0
- package/lib/modules/FileStation/CheckPermission.d.ts +10 -0
- package/lib/modules/FileStation/CheckPermission.js +13 -0
- package/lib/modules/FileStation/CopyMove.d.ts +33 -0
- package/lib/modules/FileStation/CopyMove.js +28 -0
- package/lib/modules/FileStation/CreateFolder.d.ts +15 -0
- package/lib/modules/FileStation/CreateFolder.js +12 -0
- package/lib/modules/FileStation/Delete.d.ts +54 -0
- package/lib/modules/FileStation/Delete.js +35 -0
- package/lib/modules/FileStation/DirSize.d.ts +20 -0
- package/lib/modules/FileStation/DirSize.js +28 -0
- package/lib/modules/FileStation/Download.d.ts +7 -0
- package/lib/modules/FileStation/Download.js +19 -0
- package/lib/modules/FileStation/Extract.d.ts +1 -0
- package/lib/modules/FileStation/Extract.js +1 -0
- package/lib/modules/FileStation/Favorite.d.ts +45 -0
- package/lib/modules/FileStation/Favorite.js +60 -0
- package/lib/modules/FileStation/List.d.ts +39 -11
- package/lib/modules/FileStation/List.js +14 -6
- package/lib/modules/FileStation/MD5.d.ts +15 -0
- package/lib/modules/FileStation/MD5.js +29 -0
- package/lib/modules/FileStation/Rename.d.ts +38 -0
- package/lib/modules/FileStation/Rename.js +14 -0
- package/lib/modules/FileStation/Search.d.ts +40 -0
- package/lib/modules/FileStation/Search.js +49 -0
- package/lib/modules/FileStation/Sharing.d.ts +69 -0
- package/lib/modules/FileStation/Sharing.js +64 -0
- package/lib/modules/FileStation/Thumb.d.ts +18 -0
- package/lib/modules/FileStation/Thumb.js +18 -0
- package/lib/modules/FileStation/Upload.d.ts +21 -0
- package/lib/modules/FileStation/Upload.js +44 -0
- package/lib/modules/FileStation/index.d.ts +52 -2
- package/lib/modules/FileStation/index.js +53 -3
- package/lib/modules/VideoStation/Library.d.ts +4 -5
- package/lib/modules/VideoStation/Streaming.d.ts +5 -6
- package/lib/modules/VideoStation/Streaming.js +39 -13
- package/lib/modules/VideoStation/index.js +1 -1
- package/lib/modules/index.d.ts +12 -10
- package/lib/modules/index.js +13 -12
- package/lib/types/apiInfo.d.ts +55 -4
- package/lib/types/apiInfo.js +62 -9
- package/lib/{utils.js → utils/common.js} +1 -1
- package/lib/utils/encryption.d.ts +12 -0
- package/lib/utils/encryption.js +38 -0
- package/lib/utils/env.d.ts +2 -0
- package/lib/utils/env.js +2 -0
- package/lib/utils/formData.d.ts +2 -0
- package/lib/utils/formData.js +19 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +4 -0
- package/package.json +7 -2
- package/lib/modules/VideoStation/HomeVideo.d.ts +0 -6
- package/lib/modules/VideoStation/HomeVideo.js +0 -10
- /package/lib/modules/{FileStation/File.d.ts → Docker/Image.d.ts} +0 -0
- /package/lib/modules/{FileStation/File.js → Docker/Image.js} +0 -0
- /package/lib/{utils.d.ts → utils/common.d.ts} +0 -0
package/lib/cli/apis.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { program } from "commander";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
+
import ora from "ora";
|
|
3
4
|
import { loadConfig } from "./config.js";
|
|
4
5
|
import { SynologyApi } from "../core.js";
|
|
5
6
|
import { SynologyApiModules, SynologyApiMethods } from "../modules/index.js";
|
|
@@ -28,7 +29,9 @@ export const onMethodCall = (module) => async (method, options) => {
|
|
|
28
29
|
throw new Error(`Module method ${module} is not a function`);
|
|
29
30
|
}
|
|
30
31
|
const synologyApi = new SynologyApi(connection);
|
|
32
|
+
const spinner = ora("waiting...").start();
|
|
31
33
|
const result = await synologyApi[module]?.[method](params);
|
|
34
|
+
spinner.stop();
|
|
32
35
|
if (pretty) {
|
|
33
36
|
console.log(JSON.stringify(result, null, 2));
|
|
34
37
|
}
|
package/lib/core.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from "axios";
|
|
1
2
|
import { BaseSynologyApi } from "./modules/index.js";
|
|
3
|
+
interface Agent {
|
|
4
|
+
http?: {
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
};
|
|
8
|
+
https?: {
|
|
9
|
+
host: string;
|
|
10
|
+
port: number;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
2
13
|
export interface SynologyApiOptions {
|
|
3
14
|
server: string;
|
|
4
15
|
username: string;
|
|
5
16
|
password: string;
|
|
17
|
+
agent?: Agent;
|
|
6
18
|
}
|
|
7
19
|
export interface SynologyApiInfoData {
|
|
8
20
|
maxVersion: number;
|
|
@@ -20,6 +32,7 @@ export declare class SynologyApi extends BaseSynologyApi {
|
|
|
20
32
|
server: string;
|
|
21
33
|
username: string;
|
|
22
34
|
password: string;
|
|
35
|
+
agent?: Agent;
|
|
23
36
|
baseUrl: string;
|
|
24
37
|
isConnecting: boolean;
|
|
25
38
|
private authInfo;
|
|
@@ -28,11 +41,20 @@ export declare class SynologyApi extends BaseSynologyApi {
|
|
|
28
41
|
connect(): Promise<boolean>;
|
|
29
42
|
disconnect(): Promise<boolean>;
|
|
30
43
|
private _getApiInfo;
|
|
44
|
+
protected getApiInfoByName(apiName: string): SynologyApiInfoData;
|
|
31
45
|
hasApi(apiName: string): any;
|
|
32
|
-
|
|
46
|
+
getApiInfo(): Record<string, SynologyApiInfoData>;
|
|
47
|
+
protected genRequestOptions(apiName: string, options: {
|
|
48
|
+
method?: "get" | "post";
|
|
49
|
+
params?: Record<string, any>;
|
|
50
|
+
data?: Record<string, any>;
|
|
51
|
+
headers?: Record<string, any>;
|
|
52
|
+
}): Promise<AxiosRequestConfig>;
|
|
53
|
+
protected run(apiName: string, options: {
|
|
33
54
|
method?: "get" | "post";
|
|
34
55
|
params?: Record<string, any>;
|
|
35
56
|
data?: Record<string, any>;
|
|
36
57
|
headers?: Record<string, any>;
|
|
37
58
|
}): Promise<any>;
|
|
38
59
|
}
|
|
60
|
+
export {};
|
package/lib/core.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// reference: https://kb.synology.com/zh-tw/DSM/tutorial/What_websites_does_Synology_NAS_connect_to_when_running_services_or_updating_software
|
|
2
|
-
import
|
|
2
|
+
import Axios from "axios";
|
|
3
|
+
import { isNode } from "./utils/index.js";
|
|
3
4
|
import { BaseSynologyApi } from "./modules/index.js";
|
|
4
|
-
import { isHttpUrl, getApiKey, isUndfined } from "./utils.js";
|
|
5
|
+
import { isHttpUrl, getApiKey, isUndfined } from "./utils/index.js";
|
|
5
6
|
import { getServerInfo } from "./helpers.js";
|
|
6
7
|
import { login, logout, getApiInfo } from "./modules/Api/index.js";
|
|
7
8
|
import { resWithErrorCode } from "./errorcodes.js";
|
|
@@ -15,12 +16,12 @@ export class SynologyApi extends BaseSynologyApi {
|
|
|
15
16
|
this.username = options.username;
|
|
16
17
|
this.password = options.password;
|
|
17
18
|
this.baseUrl = `${this.server}/webapi/`;
|
|
19
|
+
this.agent = options.agent ?? undefined;
|
|
18
20
|
}
|
|
19
21
|
async connect() {
|
|
20
22
|
// if quickconnect id
|
|
21
23
|
if (!isHttpUrl(this.server)) {
|
|
22
24
|
this.server = await getServerInfo(this.server);
|
|
23
|
-
// reset base url
|
|
24
25
|
this.baseUrl = `${this.server}/webapi/`;
|
|
25
26
|
}
|
|
26
27
|
try {
|
|
@@ -57,13 +58,22 @@ export class SynologyApi extends BaseSynologyApi {
|
|
|
57
58
|
console.error(err);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
getApiInfoByName(apiName) {
|
|
62
|
+
return this.apiInfo[apiName];
|
|
63
|
+
}
|
|
60
64
|
hasApi(apiName) {
|
|
61
65
|
if (!this.isConnecting) {
|
|
62
66
|
throw new Error("Not connected");
|
|
63
67
|
}
|
|
64
68
|
return Object.prototype.hasOwnProperty.call(this.apiInfo, apiName);
|
|
65
69
|
}
|
|
66
|
-
|
|
70
|
+
getApiInfo() {
|
|
71
|
+
if (!this.isConnecting) {
|
|
72
|
+
throw new Error("Not connected");
|
|
73
|
+
}
|
|
74
|
+
return this.apiInfo;
|
|
75
|
+
}
|
|
76
|
+
async genRequestOptions(apiName, options) {
|
|
67
77
|
if (!this.isConnecting) {
|
|
68
78
|
const res = await this.connect();
|
|
69
79
|
if (!res) {
|
|
@@ -73,27 +83,50 @@ export class SynologyApi extends BaseSynologyApi {
|
|
|
73
83
|
if (!this.hasApi(apiName)) {
|
|
74
84
|
throw new Error(`${apiName} not found`);
|
|
75
85
|
}
|
|
76
|
-
const { method = "get", params, data, headers } = options;
|
|
77
86
|
const api = this.apiInfo[apiName];
|
|
78
87
|
const url = `${this.baseUrl}${api.path}`;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
// create options
|
|
89
|
+
const requestOptions = {
|
|
90
|
+
url: url,
|
|
91
|
+
method: options.method || "get",
|
|
92
|
+
params: {
|
|
93
|
+
api: apiName,
|
|
94
|
+
version: api.maxVersion || api.minVersion,
|
|
95
|
+
_sid: this.authInfo.sid,
|
|
96
|
+
...(options.params ?? {}),
|
|
97
|
+
},
|
|
98
|
+
headers: {
|
|
99
|
+
...(options.headers ?? {}),
|
|
100
|
+
"x-syno-token": this.authInfo.synotoken,
|
|
101
|
+
},
|
|
102
|
+
data: options.data ?? null,
|
|
84
103
|
};
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
// https agent for node
|
|
105
|
+
if (isNode) {
|
|
106
|
+
if (this.agent?.https) {
|
|
107
|
+
const HttpsProxyAgent = require("https-proxy-agent").HttpsProxyAgent;
|
|
108
|
+
requestOptions.httpsAgent = new HttpsProxyAgent(`https://${this.agent.https.host}:${this.agent.https.port}`);
|
|
109
|
+
}
|
|
110
|
+
// http agent
|
|
111
|
+
if (this.agent?.http) {
|
|
112
|
+
const HttpProxyAgent = require("http-proxy-agent").HttpProxyAgent;
|
|
113
|
+
requestOptions.httpAgent = new HttpProxyAgent(`http://${this.agent.http.host}:${this.agent.http.port}`);
|
|
114
|
+
}
|
|
91
115
|
}
|
|
92
|
-
|
|
116
|
+
return requestOptions;
|
|
117
|
+
}
|
|
118
|
+
async run(apiName, options) {
|
|
119
|
+
const requestOptions = await this.genRequestOptions(apiName, options);
|
|
93
120
|
const apiKey = getApiKey(apiName);
|
|
94
|
-
|
|
95
|
-
result =
|
|
121
|
+
try {
|
|
122
|
+
let result = (await Axios(requestOptions)).data;
|
|
123
|
+
if (!isUndfined(apiKey)) {
|
|
124
|
+
result = resWithErrorCode(apiKey, result);
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
return resWithErrorCode(apiKey, { error: err, success: false });
|
|
96
130
|
}
|
|
97
|
-
return result;
|
|
98
131
|
}
|
|
99
132
|
}
|
package/lib/errorcodes.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SynologyApiKeysMap } from "./modules/index.js";
|
|
2
2
|
import { SynologyApiResponse } from "./types/index.js";
|
|
3
|
+
export declare const COMMON_CODES = "COMMON_CODES";
|
|
3
4
|
export declare const SYNOLOGY_ERROR_CODES: {
|
|
4
|
-
[
|
|
5
|
+
[SynologyApiKeysMap.FileStation]: {
|
|
5
6
|
400: string;
|
|
6
7
|
401: string;
|
|
7
8
|
402: string;
|
|
@@ -25,8 +26,23 @@ export declare const SYNOLOGY_ERROR_CODES: {
|
|
|
25
26
|
420: string;
|
|
26
27
|
421: string;
|
|
27
28
|
599: string;
|
|
29
|
+
800: string;
|
|
30
|
+
801: string;
|
|
31
|
+
802: string;
|
|
32
|
+
1000: string;
|
|
33
|
+
1001: string;
|
|
34
|
+
1002: string;
|
|
35
|
+
1003: string;
|
|
36
|
+
1004: string;
|
|
37
|
+
1006: string;
|
|
38
|
+
1007: string;
|
|
39
|
+
1100: string;
|
|
40
|
+
1101: string;
|
|
41
|
+
2000: string;
|
|
42
|
+
2001: string;
|
|
43
|
+
2002: string;
|
|
28
44
|
};
|
|
29
|
-
[
|
|
45
|
+
[SynologyApiKeysMap.AudioStation]: {};
|
|
30
46
|
COMMON_CODES: {
|
|
31
47
|
0: string;
|
|
32
48
|
100: string;
|
|
@@ -86,8 +102,9 @@ export declare const SYNOLOGY_ERROR_CODES: {
|
|
|
86
102
|
};
|
|
87
103
|
export declare const resWithErrorCode: (apiKey: string, res: SynologyApiResponse<any>) => SynologyApiResponse<any> | {
|
|
88
104
|
error: {
|
|
89
|
-
|
|
105
|
+
reason: any;
|
|
90
106
|
code: number;
|
|
107
|
+
message?: string;
|
|
91
108
|
};
|
|
92
109
|
data?: any;
|
|
93
110
|
success: boolean;
|
package/lib/errorcodes.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isUndfined } from "./utils.js";
|
|
1
|
+
import { SynologyApiKeysMap } from "./modules/index.js";
|
|
2
|
+
import { isUndfined } from "./utils/index.js";
|
|
3
3
|
const CODE_SUCCESS = 0;
|
|
4
4
|
const CODE_UNKNOWN = 9999;
|
|
5
|
+
export const COMMON_CODES = "COMMON_CODES";
|
|
5
6
|
export const SYNOLOGY_ERROR_CODES = {
|
|
6
|
-
[
|
|
7
|
+
[SynologyApiKeysMap.FileStation]: {
|
|
7
8
|
400: "Invalid parameter of file operation",
|
|
8
9
|
401: "Unknown error of file operation",
|
|
9
10
|
402: "System is too busy",
|
|
@@ -27,9 +28,28 @@ export const SYNOLOGY_ERROR_CODES = {
|
|
|
27
28
|
420: "Illegal file name on FAT file system",
|
|
28
29
|
421: "Device or resource busy",
|
|
29
30
|
599: "No such task of the file operation",
|
|
31
|
+
// favorite
|
|
32
|
+
800: "A folder path of favorite folder is already added to user's favorites.",
|
|
33
|
+
801: "A name of favorite folder conflicts with an existing folder path in the user's favorites.",
|
|
34
|
+
802: "There are too many favorites to be added.",
|
|
35
|
+
// copy move
|
|
36
|
+
1000: "Failed to copy files/folders. More information in <errors> object.",
|
|
37
|
+
1001: " Failed to move files/folders. More information in <errors> object.",
|
|
38
|
+
1002: " An error occurred at the destination. More information in <errors> object.",
|
|
39
|
+
1003: " Cannot overwrite or skip the existing file because no overwrite parameter is given.",
|
|
40
|
+
1004: " File cannot overwrite a folder with the same name, or folder cannot overwrite a file with the same name.",
|
|
41
|
+
1006: "Cannot copy/move file/folder with special characters to a FAT32 file system.",
|
|
42
|
+
1007: " Cannot copy/move a file bigger than 4G to a FAT32 file system.",
|
|
43
|
+
// create folder
|
|
44
|
+
1100: "Failed to create a folder. More information in <errors> object.",
|
|
45
|
+
1101: "The number of folders to the parent folder would exceed the system limitation.",
|
|
46
|
+
// sharing
|
|
47
|
+
2000: " Sharing link does not exist.",
|
|
48
|
+
2001: "Cannot generate sharing link because too many sharing links exist.",
|
|
49
|
+
2002: " Failed to access sharing links.",
|
|
30
50
|
},
|
|
31
|
-
[
|
|
32
|
-
COMMON_CODES: {
|
|
51
|
+
[SynologyApiKeysMap.AudioStation]: {},
|
|
52
|
+
["COMMON_CODES"]: {
|
|
33
53
|
[CODE_SUCCESS]: "Success",
|
|
34
54
|
100: "Unknown error",
|
|
35
55
|
101: "No parameter of API, method or version",
|
|
@@ -89,6 +109,7 @@ export const SYNOLOGY_ERROR_CODES = {
|
|
|
89
109
|
};
|
|
90
110
|
export const resWithErrorCode = (apiKey, res) => {
|
|
91
111
|
const errorCodes = SYNOLOGY_ERROR_CODES[apiKey];
|
|
112
|
+
const commonErrorCode = SYNOLOGY_ERROR_CODES[COMMON_CODES];
|
|
92
113
|
const code = res?.error?.code;
|
|
93
114
|
if (isUndfined(code))
|
|
94
115
|
return res;
|
|
@@ -96,7 +117,7 @@ export const resWithErrorCode = (apiKey, res) => {
|
|
|
96
117
|
...res,
|
|
97
118
|
error: {
|
|
98
119
|
...res.error,
|
|
99
|
-
|
|
120
|
+
reason: res?.error?.message || errorCodes?.[code] || commonErrorCode?.[code] || "Unknown error",
|
|
100
121
|
},
|
|
101
122
|
};
|
|
102
123
|
};
|
package/lib/helpers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Axios from "axios";
|
|
2
2
|
import { GLOBAL_QUICK_CONNECT_URL, QUICK_CONNECT_PINGPANG_API } from "./constants.js";
|
|
3
3
|
const getServersFromServerInfo = async (serverInfo) => {
|
|
4
4
|
// first lan ip
|
|
@@ -35,7 +35,7 @@ export const getServerInfo = async (quickConnectId) => {
|
|
|
35
35
|
get_ca_fingerprints: true,
|
|
36
36
|
command: "get_server_info",
|
|
37
37
|
};
|
|
38
|
-
const serverInfo = await
|
|
38
|
+
const serverInfo = (await Axios.post(GLOBAL_QUICK_CONNECT_URL, params)).data;
|
|
39
39
|
if (!serverInfo?.service?.relay_ip && !serverInfo?.service?.relay_port) {
|
|
40
40
|
const relayRequestParams = {
|
|
41
41
|
version: 1,
|
|
@@ -44,9 +44,7 @@ export const getServerInfo = async (quickConnectId) => {
|
|
|
44
44
|
platform: "web",
|
|
45
45
|
command: "request_tunnel",
|
|
46
46
|
};
|
|
47
|
-
const result = await
|
|
48
|
-
.post(`https://${serverInfo.env.control_host}/Serv.php`, { json: relayRequestParams })
|
|
49
|
-
.json();
|
|
47
|
+
const result = (await Axios.post(`https://${serverInfo.env.control_host}/Serv.php`, relayRequestParams)).data;
|
|
50
48
|
return getServersFromServerInfo(result);
|
|
51
49
|
}
|
|
52
50
|
else {
|
|
@@ -56,9 +54,8 @@ export const getServerInfo = async (quickConnectId) => {
|
|
|
56
54
|
// pingpang
|
|
57
55
|
export const pingpang = async (server) => {
|
|
58
56
|
try {
|
|
59
|
-
const result = await
|
|
60
|
-
.
|
|
61
|
-
.json();
|
|
57
|
+
const result = (await Axios.get(`${server}/${QUICK_CONNECT_PINGPANG_API}`))
|
|
58
|
+
.data;
|
|
62
59
|
if (result.success) {
|
|
63
60
|
return true;
|
|
64
61
|
}
|
package/lib/modules/Api/Auth.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import Axios from "axios";
|
|
2
|
+
import { SynoApi } from "../../types/index.js";
|
|
3
3
|
export async function login(core) {
|
|
4
4
|
const params = {
|
|
5
|
-
api: SynologyApiInfo.Auth,
|
|
6
|
-
version: 6,
|
|
7
5
|
method: "login",
|
|
6
|
+
api: SynoApi.Auth,
|
|
7
|
+
version: 6,
|
|
8
8
|
account: core.username,
|
|
9
9
|
passwd: core.password,
|
|
10
|
-
|
|
10
|
+
enable_device_token: "no",
|
|
11
|
+
enable_syno_token: "yes",
|
|
12
|
+
logintype: "local",
|
|
13
|
+
client: "browser",
|
|
14
|
+
session: "webui",
|
|
15
|
+
format: "cookie",
|
|
11
16
|
};
|
|
12
17
|
const url = `${core.baseUrl}entry.cgi`;
|
|
13
|
-
const result = await
|
|
18
|
+
const result = (await Axios.get(url, { params: params })).data;
|
|
14
19
|
if (!result.success) {
|
|
15
20
|
throw new Error(result.error.message);
|
|
16
21
|
}
|
|
@@ -18,12 +23,12 @@ export async function login(core) {
|
|
|
18
23
|
}
|
|
19
24
|
export async function logout(core) {
|
|
20
25
|
const params = {
|
|
21
|
-
api:
|
|
26
|
+
api: SynoApi.Auth,
|
|
22
27
|
version: 6,
|
|
23
28
|
method: "logout",
|
|
24
29
|
};
|
|
25
30
|
const url = `${core.baseUrl}entry.cgi`;
|
|
26
|
-
const result = await
|
|
31
|
+
const result = (await Axios.get(url, { params: params })).data;
|
|
27
32
|
if (!result.success) {
|
|
28
33
|
throw new Error(result.error.message);
|
|
29
34
|
}
|
package/lib/modules/Api/Info.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import Axios from "axios";
|
|
2
|
+
import { SynoApi } from "../../types/index.js";
|
|
3
3
|
export async function getApiInfo(core) {
|
|
4
4
|
const params = {
|
|
5
|
-
api:
|
|
5
|
+
api: SynoApi.Info,
|
|
6
6
|
version: 1,
|
|
7
7
|
method: "query",
|
|
8
8
|
};
|
|
9
9
|
const url = `${core.baseUrl}entry.cgi`;
|
|
10
|
-
const result = await
|
|
10
|
+
const result = (await Axios.get(url, { params: params })).data;
|
|
11
11
|
if (!result.success) {
|
|
12
12
|
throw new Error(result.error.message);
|
|
13
13
|
}
|
|
@@ -27,4 +27,21 @@ export type AudioStationAlbumListResponse = SynologyApiResponse<{
|
|
|
27
27
|
year: number;
|
|
28
28
|
}>;
|
|
29
29
|
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Get the list of albums from AudioStation
|
|
32
|
+
*
|
|
33
|
+
* @param params - Parameters for retrieving the album list
|
|
34
|
+
* @param params.limit - Maximum number of results to return, defaults to 1000
|
|
35
|
+
* @param params.offset - Starting offset for results, defaults to 0
|
|
36
|
+
* @param params.library - Specify library type, can be 'all' or 'personal', defaults to 'all'
|
|
37
|
+
* @param params.additional - Array of additional information to retrieve, defaults to ['avg_rating']
|
|
38
|
+
* @param params.version - API version
|
|
39
|
+
* @param params.filter - Filter condition
|
|
40
|
+
* @param params.artist - Filter by artist name
|
|
41
|
+
* @param params.genre - Filter by genre
|
|
42
|
+
* @param params.sort_by - Field to sort by, can be 'time', 'random', 'year', 'name', 'display_artist', or 'avg_rating', defaults to 'name'
|
|
43
|
+
* @param params.sort_direction - Sort direction, can be 'ASC' or 'DESC', defaults to 'ASC'
|
|
44
|
+
*
|
|
45
|
+
* @returns Response object containing the list of albums
|
|
46
|
+
*/
|
|
30
47
|
export declare function getAlbumList(params: AudioStationAlbumListParams): Promise<AudioStationAlbumListResponse>;
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { AudioStationApi } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get the list of albums from AudioStation
|
|
4
|
+
*
|
|
5
|
+
* @param params - Parameters for retrieving the album list
|
|
6
|
+
* @param params.limit - Maximum number of results to return, defaults to 1000
|
|
7
|
+
* @param params.offset - Starting offset for results, defaults to 0
|
|
8
|
+
* @param params.library - Specify library type, can be 'all' or 'personal', defaults to 'all'
|
|
9
|
+
* @param params.additional - Array of additional information to retrieve, defaults to ['avg_rating']
|
|
10
|
+
* @param params.version - API version
|
|
11
|
+
* @param params.filter - Filter condition
|
|
12
|
+
* @param params.artist - Filter by artist name
|
|
13
|
+
* @param params.genre - Filter by genre
|
|
14
|
+
* @param params.sort_by - Field to sort by, can be 'time', 'random', 'year', 'name', 'display_artist', or 'avg_rating', defaults to 'name'
|
|
15
|
+
* @param params.sort_direction - Sort direction, can be 'ASC' or 'DESC', defaults to 'ASC'
|
|
16
|
+
*
|
|
17
|
+
* @returns Response object containing the list of albums
|
|
18
|
+
*/
|
|
2
19
|
export async function getAlbumList(params) {
|
|
3
20
|
const { additional = ["avg_rating"], library = "all", limit = 1000, offset = 0, sort_by = "name", sort_direction = "ASC", ...extraParams } = params;
|
|
4
21
|
const res = await this.run(AudioStationApi.Album, {
|
|
@@ -22,4 +22,20 @@ export type AudioStationArtistListResponse = SynologyApiResponse<{
|
|
|
22
22
|
name: string;
|
|
23
23
|
}>;
|
|
24
24
|
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Get the list of artists from AudioStation
|
|
27
|
+
*
|
|
28
|
+
* @param params - Parameters for retrieving the artist list
|
|
29
|
+
* @param params.limit - Maximum number of results to return, defaults to 1000
|
|
30
|
+
* @param params.offset - Starting offset for results, defaults to 0
|
|
31
|
+
* @param params.library - Specify library type, can be 'all' or 'personal', defaults to 'all'
|
|
32
|
+
* @param params.additional - Array of additional information to retrieve, defaults to ['avg_rating']
|
|
33
|
+
* @param params.filter - Filter condition
|
|
34
|
+
* @param params.artist - Filter by artist name
|
|
35
|
+
* @param params.genre - Filter by genre
|
|
36
|
+
* @param params.sort_by - Field to sort by, currently only supports 'name'
|
|
37
|
+
* @param params.sort_direction - Sort direction, can be 'ASC' or 'DESC', defaults to 'ASC'
|
|
38
|
+
*
|
|
39
|
+
* @returns Response object containing the list of artists
|
|
40
|
+
*/
|
|
25
41
|
export declare function getArtistList(params: AudioStationArtistListParams): Promise<AudioStationArtistListResponse>;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { AudioStationApi } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get the list of artists from AudioStation
|
|
4
|
+
*
|
|
5
|
+
* @param params - Parameters for retrieving the artist list
|
|
6
|
+
* @param params.limit - Maximum number of results to return, defaults to 1000
|
|
7
|
+
* @param params.offset - Starting offset for results, defaults to 0
|
|
8
|
+
* @param params.library - Specify library type, can be 'all' or 'personal', defaults to 'all'
|
|
9
|
+
* @param params.additional - Array of additional information to retrieve, defaults to ['avg_rating']
|
|
10
|
+
* @param params.filter - Filter condition
|
|
11
|
+
* @param params.artist - Filter by artist name
|
|
12
|
+
* @param params.genre - Filter by genre
|
|
13
|
+
* @param params.sort_by - Field to sort by, currently only supports 'name'
|
|
14
|
+
* @param params.sort_direction - Sort direction, can be 'ASC' or 'DESC', defaults to 'ASC'
|
|
15
|
+
*
|
|
16
|
+
* @returns Response object containing the list of artists
|
|
17
|
+
*/
|
|
2
18
|
export async function getArtistList(params) {
|
|
3
19
|
const { additional = ["avg_rating"], library = "all", limit = 1000, offset = 0, sort_by = "name", sort_direction = "ASC", ...extraParams } = params;
|
|
4
20
|
const res = await this.run(AudioStationApi.Artist, {
|
|
@@ -21,4 +21,18 @@ export type AudioStationFolderListResponse = SynologyApiResponse<{
|
|
|
21
21
|
offset: number;
|
|
22
22
|
total: number;
|
|
23
23
|
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Get the list of folders from AudioStation
|
|
26
|
+
*
|
|
27
|
+
* @param params - Parameters for retrieving the folder list
|
|
28
|
+
* @param params.limit - Maximum number of results to return, defaults to 1000
|
|
29
|
+
* @param params.offset - Starting offset for results, defaults to 0
|
|
30
|
+
* @param params.library - Specify library type, currently only supports 'all'
|
|
31
|
+
* @param params.additional - Array of additional information to retrieve, defaults to ['song_tag', 'song_audio', 'song_rating']
|
|
32
|
+
* @param params.id - Folder ID to filter results
|
|
33
|
+
* @param params.sort_by - Field to sort by, can be 'song_rating', 'title', 'album', 'artist', 'duration', or 'track', defaults to 'title'
|
|
34
|
+
* @param params.sort_direction - Sort direction, can be 'ASC' or 'DESC', defaults to 'ASC'
|
|
35
|
+
*
|
|
36
|
+
* @returns Response object containing the list of folders and related information
|
|
37
|
+
*/
|
|
24
38
|
export declare function getFolderList(params: AudioStationFolderListParams): Promise<AudioStationFolderListResponse>;
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { AudioStationApi } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get the list of folders from AudioStation
|
|
4
|
+
*
|
|
5
|
+
* @param params - Parameters for retrieving the folder list
|
|
6
|
+
* @param params.limit - Maximum number of results to return, defaults to 1000
|
|
7
|
+
* @param params.offset - Starting offset for results, defaults to 0
|
|
8
|
+
* @param params.library - Specify library type, currently only supports 'all'
|
|
9
|
+
* @param params.additional - Array of additional information to retrieve, defaults to ['song_tag', 'song_audio', 'song_rating']
|
|
10
|
+
* @param params.id - Folder ID to filter results
|
|
11
|
+
* @param params.sort_by - Field to sort by, can be 'song_rating', 'title', 'album', 'artist', 'duration', or 'track', defaults to 'title'
|
|
12
|
+
* @param params.sort_direction - Sort direction, can be 'ASC' or 'DESC', defaults to 'ASC'
|
|
13
|
+
*
|
|
14
|
+
* @returns Response object containing the list of folders and related information
|
|
15
|
+
*/
|
|
2
16
|
export async function getFolderList(params) {
|
|
3
17
|
const { additional = ["song_tag", "song_audio", "song_rating"], library = "all", limit = 1000, offset = 0, sort_by = "title", sort_direction = "ASC", ...extraParams } = params;
|
|
4
18
|
const res = await this.run(AudioStationApi.Folder, {
|
|
@@ -5,6 +5,7 @@ import { getPlaylist, createPlaylist, deletePlaylist } from "./Playlist.js";
|
|
|
5
5
|
import { getFolderList } from "./Folder.js";
|
|
6
6
|
import { getLyrics, searchLyrics } from "./Lyrics.js";
|
|
7
7
|
import { getInfo } from "./Info.js";
|
|
8
|
+
// methods
|
|
8
9
|
export const METHODS = {
|
|
9
10
|
getSongList,
|
|
10
11
|
setSongRating,
|
|
@@ -21,3 +22,8 @@ export const METHODS = {
|
|
|
21
22
|
// name space
|
|
22
23
|
export const KEY = "AudioStation";
|
|
23
24
|
export const ALIAS_KEY = "as";
|
|
25
|
+
export var EnumKeys;
|
|
26
|
+
(function (EnumKeys) {
|
|
27
|
+
EnumKeys["AudioStation"] = "AudioStation";
|
|
28
|
+
EnumKeys["as"] = "as";
|
|
29
|
+
})(EnumKeys || (EnumKeys = {}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SynoApi } from "../../types/index.js";
|
|
2
2
|
export async function getAuthKeyGrant(params) {
|
|
3
3
|
const { allow_methods, allow_api } = params;
|
|
4
|
-
const result = await this.run(
|
|
4
|
+
const result = await this.run(SynoApi.AuthKey, {
|
|
5
5
|
params: {
|
|
6
6
|
method: "grant",
|
|
7
7
|
allow_api: allow_api,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SynologyApiResponse } from "../../types/index.js";
|
|
2
|
+
export type EncryptionInfoResponse = SynologyApiResponse<{
|
|
3
|
+
cipherkey: string;
|
|
4
|
+
ciphertoken: string;
|
|
5
|
+
public_key: string;
|
|
6
|
+
server_time: number;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function getEncryptionInfo(): Promise<EncryptionInfoResponse>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getAuthKeyGrant } from "./AuthKey.js";
|
|
2
|
+
import { getEncryptionInfo } from "./Encryption.js";
|
|
2
3
|
export declare const METHODS: {
|
|
3
4
|
getAuthKeyGrant: typeof getAuthKeyGrant;
|
|
5
|
+
getEncryptionInfo: typeof getEncryptionInfo;
|
|
4
6
|
};
|
|
5
7
|
export declare const KEY = "Auth";
|
|
6
8
|
export declare const ALIAS_KEY = "au";
|