@fett/synology-api 0.1.0 → 0.1.1
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 +2 -1
- package/lib/core.d.ts +2 -0
- package/lib/core.js +2 -1
- package/lib/helpers.d.ts +1 -1
- package/lib/helpers.js +11 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
   
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
📖 [中文 README](./README_zh.md)
|
|
11
|
+
🔎 [API Document ](https://chrissong1994.github.io/synology-api)
|
|
11
12
|
|
|
12
13
|
Synology Api Javascript wrapper can be used in Browser、CLI or Nodejs to interact with Synology NAS.
|
|
13
14
|
You can use domain or ip address, also supports Synology Quick Connect connect Synology server.
|
package/lib/core.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface SynologyApiOptions {
|
|
|
17
17
|
password: string;
|
|
18
18
|
quickConnectServerType?: QuickConnectServerType;
|
|
19
19
|
agent?: Agent;
|
|
20
|
+
lanPriority?: boolean;
|
|
20
21
|
}
|
|
21
22
|
export interface SynologyApiInfoData {
|
|
22
23
|
maxVersion: number;
|
|
@@ -38,6 +39,7 @@ export declare class SynologyApi extends BaseModuleSynologyApi {
|
|
|
38
39
|
baseUrl: string;
|
|
39
40
|
isConnecting: boolean;
|
|
40
41
|
quickConnectServerType?: QuickConnectServerType;
|
|
42
|
+
lanPriority?: boolean;
|
|
41
43
|
private authInfo;
|
|
42
44
|
private apiInfo;
|
|
43
45
|
constructor(options: SynologyApiOptions);
|
package/lib/core.js
CHANGED
|
@@ -17,13 +17,14 @@ export class SynologyApi extends BaseModuleSynologyApi {
|
|
|
17
17
|
this.username = options.username;
|
|
18
18
|
this.password = options.password;
|
|
19
19
|
this.quickConnectServerType = options.quickConnectServerType ?? QuickConnectServerType.proxy;
|
|
20
|
+
this.lanPriority = options.lanPriority ?? false;
|
|
20
21
|
this.baseUrl = `${this.server}/webapi/`;
|
|
21
22
|
this.agent = options.agent ?? undefined;
|
|
22
23
|
}
|
|
23
24
|
async connect() {
|
|
24
25
|
// if quickconnect id
|
|
25
26
|
if (!isHttpUrl(this.server)) {
|
|
26
|
-
this.server = await getServerInfo(this.server, this.quickConnectServerType);
|
|
27
|
+
this.server = await getServerInfo(this.server, this.quickConnectServerType, this.lanPriority);
|
|
27
28
|
this.baseUrl = `${this.server}/webapi/`;
|
|
28
29
|
}
|
|
29
30
|
try {
|
package/lib/helpers.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export type ServerInfo = {
|
|
|
16
16
|
relay_port: number;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
export declare const getServerInfo: (quickConnectId: string, quickConnectServerType: QuickConnectServerType) => Promise<any>;
|
|
19
|
+
export declare const getServerInfo: (quickConnectId: string, quickConnectServerType: QuickConnectServerType, lanPriority?: boolean) => Promise<any>;
|
|
20
20
|
export declare const pingpang: (server: string) => Promise<boolean>;
|
package/lib/helpers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Axios from "axios";
|
|
2
2
|
import { GLOBAL_QUICK_CONNECT_URL, QUICK_CONNECT_PINGPANG_API } from "./constants.js";
|
|
3
3
|
import { QuickConnectServerType } from "./types/index.js";
|
|
4
|
-
const getServersFromServerInfo = async (serverInfo, quickConnectServerType) => {
|
|
4
|
+
const getServersFromServerInfo = async (serverInfo, quickConnectServerType, lanPriority) => {
|
|
5
5
|
const serverMap = {
|
|
6
6
|
[QuickConnectServerType.proxy]: undefined,
|
|
7
7
|
[QuickConnectServerType.lan]: undefined,
|
|
@@ -22,7 +22,13 @@ const getServersFromServerInfo = async (serverInfo, quickConnectServerType) => {
|
|
|
22
22
|
serverMap[QuickConnectServerType.lan] =
|
|
23
23
|
`http://${serverInfo.server.interface?.[0].ip}:${serverInfo.service.port}`;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
let server = serverMap[quickConnectServerType];
|
|
26
|
+
if (lanPriority && serverMap[QuickConnectServerType.lan]) {
|
|
27
|
+
const lanServer = serverMap[QuickConnectServerType.lan];
|
|
28
|
+
if (lanServer && (await pingpang(lanServer))) {
|
|
29
|
+
return lanServer;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
26
32
|
if (!server) {
|
|
27
33
|
return Promise.reject(`${quickConnectServerType} server not found`);
|
|
28
34
|
}
|
|
@@ -34,7 +40,7 @@ const getServersFromServerInfo = async (serverInfo, quickConnectServerType) => {
|
|
|
34
40
|
return server;
|
|
35
41
|
}
|
|
36
42
|
};
|
|
37
|
-
export const getServerInfo = async (quickConnectId, quickConnectServerType) => {
|
|
43
|
+
export const getServerInfo = async (quickConnectId, quickConnectServerType, lanPriority) => {
|
|
38
44
|
const params = {
|
|
39
45
|
version: 1,
|
|
40
46
|
id: "dsm",
|
|
@@ -53,10 +59,10 @@ export const getServerInfo = async (quickConnectId, quickConnectServerType) => {
|
|
|
53
59
|
};
|
|
54
60
|
// get replay tunnel
|
|
55
61
|
const result = (await Axios.post(`https://${serverInfo.env.control_host}/Serv.php`, relayRequestParams)).data;
|
|
56
|
-
return getServersFromServerInfo(result, quickConnectServerType);
|
|
62
|
+
return getServersFromServerInfo(result, quickConnectServerType, lanPriority);
|
|
57
63
|
}
|
|
58
64
|
else {
|
|
59
|
-
return getServersFromServerInfo(serverInfo, quickConnectServerType);
|
|
65
|
+
return getServersFromServerInfo(serverInfo, quickConnectServerType, lanPriority);
|
|
60
66
|
}
|
|
61
67
|
};
|
|
62
68
|
// pingpang
|