@fett/synology-api 0.0.1-beta.7 → 0.0.1-beta.9
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/cjs/index.js +31 -36
- package/lib/esm/cli/index.js +1 -1
- package/lib/esm/core.js +4 -4
- package/lib/esm/helpers.js +13 -12
- package/lib/esm/modules/Api/Auth.js +8 -8
- package/lib/esm/modules/Api/Info.js +5 -5
- package/lib/esm/modules/AudioStation/Song.js +1 -1
- package/lib/esm/modules/FileStation/Info.js +1 -1
- package/lib/esm/modules/FileStation/List.js +2 -2
- package/lib/types/helpers.d.ts +17 -0
- package/lib/types/modules/Api/Auth.d.ts +2 -1
- package/lib/types/modules/Api/Info.d.ts +2 -1
- package/package.json +4 -3
package/lib/cjs/index.js
CHANGED
|
@@ -76,7 +76,7 @@ __export(index_exports, {
|
|
|
76
76
|
module.exports = __toCommonJS(index_exports);
|
|
77
77
|
|
|
78
78
|
// src/core.ts
|
|
79
|
-
var
|
|
79
|
+
var import_ky4 = __toESM(require("ky"));
|
|
80
80
|
|
|
81
81
|
// src/types/apiInfo.ts
|
|
82
82
|
var SynologyApiInfo = /* @__PURE__ */ ((SynologyApiInfo2) => {
|
|
@@ -122,7 +122,7 @@ function getSongList(params) {
|
|
|
122
122
|
library: "all"
|
|
123
123
|
}, params)
|
|
124
124
|
});
|
|
125
|
-
return res
|
|
125
|
+
return res;
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -141,7 +141,7 @@ function getInfo() {
|
|
|
141
141
|
method: "get"
|
|
142
142
|
}
|
|
143
143
|
});
|
|
144
|
-
return res
|
|
144
|
+
return res;
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
|
|
@@ -171,7 +171,7 @@ function getFileList() {
|
|
|
171
171
|
folder_path: params.folder_path
|
|
172
172
|
}, params)
|
|
173
173
|
});
|
|
174
|
-
return res
|
|
174
|
+
return res;
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
function getFileListShare() {
|
|
@@ -184,7 +184,7 @@ function getFileListShare() {
|
|
|
184
184
|
onlywritable
|
|
185
185
|
}, params)
|
|
186
186
|
});
|
|
187
|
-
return res
|
|
187
|
+
return res;
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -242,7 +242,7 @@ Object.defineProperties(BaseSynologyApi.prototype, {
|
|
|
242
242
|
});
|
|
243
243
|
|
|
244
244
|
// src/helpers.ts
|
|
245
|
-
var
|
|
245
|
+
var import_ky = __toESM(require("ky"));
|
|
246
246
|
|
|
247
247
|
// src/constants.ts
|
|
248
248
|
var GLOBAL_QUICK_CONNECT_URL = "https://global.quickconnect.cn/Serv.php";
|
|
@@ -272,7 +272,7 @@ var getServersFromServerInfo = (serverInfo) => __async(null, null, function* ()
|
|
|
272
272
|
}
|
|
273
273
|
});
|
|
274
274
|
var getServerInfo = (quickConnectId) => __async(null, null, function* () {
|
|
275
|
-
var _a, _b
|
|
275
|
+
var _a, _b;
|
|
276
276
|
const params = {
|
|
277
277
|
version: 1,
|
|
278
278
|
id: "dsm",
|
|
@@ -280,8 +280,8 @@ var getServerInfo = (quickConnectId) => __async(null, null, function* () {
|
|
|
280
280
|
get_ca_fingerprints: true,
|
|
281
281
|
command: "get_server_info"
|
|
282
282
|
};
|
|
283
|
-
const serverInfo = yield
|
|
284
|
-
if (!((
|
|
283
|
+
const serverInfo = yield import_ky.default.post(GLOBAL_QUICK_CONNECT_URL, { json: params }).json();
|
|
284
|
+
if (!((_a = serverInfo == null ? void 0 : serverInfo.service) == null ? void 0 : _a.relay_ip) && !((_b = serverInfo == null ? void 0 : serverInfo.service) == null ? void 0 : _b.relay_port)) {
|
|
285
285
|
const relayRequestParams = {
|
|
286
286
|
version: 1,
|
|
287
287
|
id: "dsm",
|
|
@@ -289,21 +289,16 @@ var getServerInfo = (quickConnectId) => __async(null, null, function* () {
|
|
|
289
289
|
platform: "web",
|
|
290
290
|
command: "request_tunnel"
|
|
291
291
|
};
|
|
292
|
-
const result = yield
|
|
293
|
-
|
|
294
|
-
relayRequestParams
|
|
295
|
-
);
|
|
296
|
-
return getServersFromServerInfo(result.data);
|
|
292
|
+
const result = yield import_ky.default.post(`https://${serverInfo.env.control_host}/Serv.php`, { json: relayRequestParams }).json();
|
|
293
|
+
return getServersFromServerInfo(result);
|
|
297
294
|
} else {
|
|
298
|
-
return getServersFromServerInfo(serverInfo
|
|
295
|
+
return getServersFromServerInfo(serverInfo);
|
|
299
296
|
}
|
|
300
297
|
});
|
|
301
298
|
var pingpang = (server) => __async(null, null, function* () {
|
|
302
299
|
try {
|
|
303
|
-
const result = yield
|
|
304
|
-
|
|
305
|
-
});
|
|
306
|
-
if (result.data.success) {
|
|
300
|
+
const result = yield import_ky.default.get(`${server}/${QUICK_CONNECT_PINGPANG_API}`).json();
|
|
301
|
+
if (result.success) {
|
|
307
302
|
return true;
|
|
308
303
|
} else {
|
|
309
304
|
return false;
|
|
@@ -314,7 +309,7 @@ var pingpang = (server) => __async(null, null, function* () {
|
|
|
314
309
|
});
|
|
315
310
|
|
|
316
311
|
// src/modules/Api/Auth.ts
|
|
317
|
-
var
|
|
312
|
+
var import_ky2 = __toESM(require("ky"));
|
|
318
313
|
function login(core) {
|
|
319
314
|
return __async(this, null, function* () {
|
|
320
315
|
const params = {
|
|
@@ -326,11 +321,11 @@ function login(core) {
|
|
|
326
321
|
format: "sid"
|
|
327
322
|
};
|
|
328
323
|
const url = `${core.baseUrl}entry.cgi`;
|
|
329
|
-
const result = yield
|
|
330
|
-
if (!result.
|
|
331
|
-
throw new Error(result.
|
|
324
|
+
const result = yield import_ky2.default.get(url, { searchParams: params }).json();
|
|
325
|
+
if (!result.success) {
|
|
326
|
+
throw new Error(result.error.message);
|
|
332
327
|
}
|
|
333
|
-
return result
|
|
328
|
+
return result;
|
|
334
329
|
});
|
|
335
330
|
}
|
|
336
331
|
function logout(core) {
|
|
@@ -341,15 +336,15 @@ function logout(core) {
|
|
|
341
336
|
method: "logout"
|
|
342
337
|
};
|
|
343
338
|
const url = `${core.baseUrl}entry.cgi`;
|
|
344
|
-
const result = yield
|
|
345
|
-
if (!result.
|
|
346
|
-
throw new Error(result.
|
|
339
|
+
const result = yield import_ky2.default.get(url, { searchParams: params }).json();
|
|
340
|
+
if (!result.success) {
|
|
341
|
+
throw new Error(result.error.message);
|
|
347
342
|
}
|
|
348
343
|
});
|
|
349
344
|
}
|
|
350
345
|
|
|
351
346
|
// src/modules/Api/Info.ts
|
|
352
|
-
var
|
|
347
|
+
var import_ky3 = __toESM(require("ky"));
|
|
353
348
|
function getApiInfo(core) {
|
|
354
349
|
return __async(this, null, function* () {
|
|
355
350
|
const params = {
|
|
@@ -358,11 +353,11 @@ function getApiInfo(core) {
|
|
|
358
353
|
method: "query"
|
|
359
354
|
};
|
|
360
355
|
const url = `${core.baseUrl}entry.cgi`;
|
|
361
|
-
const result = yield
|
|
362
|
-
if (!result.
|
|
363
|
-
throw new Error(result.
|
|
356
|
+
const result = yield import_ky3.default.get(url, { searchParams: params }).json();
|
|
357
|
+
if (!result.success) {
|
|
358
|
+
throw new Error(result.error.message);
|
|
364
359
|
}
|
|
365
|
-
return result
|
|
360
|
+
return result;
|
|
366
361
|
});
|
|
367
362
|
}
|
|
368
363
|
|
|
@@ -547,14 +542,14 @@ var SynologyApi = class extends BaseSynologyApi {
|
|
|
547
542
|
}, params);
|
|
548
543
|
let result = null;
|
|
549
544
|
if (method === "get") {
|
|
550
|
-
result = yield
|
|
545
|
+
result = yield import_ky4.default.get(url, { searchParams: externalParams, headers }).json();
|
|
551
546
|
}
|
|
552
547
|
if (method === "post") {
|
|
553
|
-
result = yield
|
|
548
|
+
result = yield import_ky4.default.post(url, { searchParams: externalParams, json: data, headers }).json();
|
|
554
549
|
}
|
|
555
550
|
const apiKey = getApiKey(apiName);
|
|
556
551
|
if (!isUndfined(apiKey)) {
|
|
557
|
-
result
|
|
552
|
+
result = resWithErrorCode(apiKey, result);
|
|
558
553
|
}
|
|
559
554
|
return result;
|
|
560
555
|
});
|
|
@@ -714,7 +709,7 @@ var apiCmdRegister = () => {
|
|
|
714
709
|
function loadCli() {
|
|
715
710
|
return __async(this, null, function* () {
|
|
716
711
|
const pkg = yield import_fs_extra2.default.readJSON(import_path2.default.join(__dirname, "../../package.json"));
|
|
717
|
-
import_commander3.program.name("synology").usage("<command> [options]").description("synology api cli tool").version(pkg.version);
|
|
712
|
+
import_commander3.program.name("synology").usage("<command> [options]").description("synology api cli tool").version(pkg.version, "-v, --version", "output the version number");
|
|
718
713
|
configCmdRegister();
|
|
719
714
|
apiCmdRegister();
|
|
720
715
|
import_commander3.program.parse(process.argv);
|
package/lib/esm/cli/index.js
CHANGED
|
@@ -21,7 +21,7 @@ export function loadCli() {
|
|
|
21
21
|
.name("synology")
|
|
22
22
|
.usage("<command> [options]")
|
|
23
23
|
.description("synology api cli tool")
|
|
24
|
-
.version(pkg.version);
|
|
24
|
+
.version(pkg.version, "-v, --version", "output the version number");
|
|
25
25
|
// register commands
|
|
26
26
|
configCmdRegister();
|
|
27
27
|
apiCmdRegister();
|
package/lib/esm/core.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
// reference: https://kb.synology.com/zh-tw/DSM/tutorial/What_websites_does_Synology_NAS_connect_to_when_running_services_or_updating_software
|
|
11
|
-
import
|
|
11
|
+
import ky from "ky";
|
|
12
12
|
import { BaseSynologyApi } from "./modules";
|
|
13
13
|
import { isHttpUrl, getApiKey, isUndfined } from "./utils";
|
|
14
14
|
import { getServerInfo } from "./helpers";
|
|
@@ -95,15 +95,15 @@ export class SynologyApi extends BaseSynologyApi {
|
|
|
95
95
|
const externalParams = Object.assign({ api: apiName, version: api.maxVersion, _sid: this.authInfo.sid }, params);
|
|
96
96
|
let result = null;
|
|
97
97
|
if (method === "get") {
|
|
98
|
-
result = yield
|
|
98
|
+
result = yield ky.get(url, { searchParams: externalParams, headers }).json();
|
|
99
99
|
}
|
|
100
100
|
if (method === "post") {
|
|
101
|
-
result = yield
|
|
101
|
+
result = yield ky.post(url, { searchParams: externalParams, json: data, headers }).json();
|
|
102
102
|
}
|
|
103
103
|
// match error code msg
|
|
104
104
|
const apiKey = getApiKey(apiName);
|
|
105
105
|
if (!isUndfined(apiKey)) {
|
|
106
|
-
result
|
|
106
|
+
result = resWithErrorCode(apiKey, result);
|
|
107
107
|
}
|
|
108
108
|
return result;
|
|
109
109
|
});
|
package/lib/esm/helpers.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
10
|
+
import ky from "ky";
|
|
11
11
|
import { GLOBAL_QUICK_CONNECT_URL, QUICK_CONNECT_PINGPANG_API } from "./constants";
|
|
12
12
|
const getServersFromServerInfo = (serverInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
13
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -34,9 +34,8 @@ const getServersFromServerInfo = (serverInfo) => __awaiter(void 0, void 0, void
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
-
// get server ip
|
|
38
37
|
export const getServerInfo = (quickConnectId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
var _a, _b
|
|
38
|
+
var _a, _b;
|
|
40
39
|
const params = {
|
|
41
40
|
version: 1,
|
|
42
41
|
id: "dsm",
|
|
@@ -44,8 +43,8 @@ export const getServerInfo = (quickConnectId) => __awaiter(void 0, void 0, void
|
|
|
44
43
|
get_ca_fingerprints: true,
|
|
45
44
|
command: "get_server_info",
|
|
46
45
|
};
|
|
47
|
-
const serverInfo = yield
|
|
48
|
-
if (!((
|
|
46
|
+
const serverInfo = yield ky.post(GLOBAL_QUICK_CONNECT_URL, { json: params }).json();
|
|
47
|
+
if (!((_a = serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.service) === null || _a === void 0 ? void 0 : _a.relay_ip) && !((_b = serverInfo === null || serverInfo === void 0 ? void 0 : serverInfo.service) === null || _b === void 0 ? void 0 : _b.relay_port)) {
|
|
49
48
|
const relayRequestParams = {
|
|
50
49
|
version: 1,
|
|
51
50
|
id: "dsm",
|
|
@@ -53,20 +52,22 @@ export const getServerInfo = (quickConnectId) => __awaiter(void 0, void 0, void
|
|
|
53
52
|
platform: "web",
|
|
54
53
|
command: "request_tunnel",
|
|
55
54
|
};
|
|
56
|
-
const result = yield
|
|
57
|
-
|
|
55
|
+
const result = yield ky
|
|
56
|
+
.post(`https://${serverInfo.env.control_host}/Serv.php`, { json: relayRequestParams })
|
|
57
|
+
.json();
|
|
58
|
+
return getServersFromServerInfo(result);
|
|
58
59
|
}
|
|
59
60
|
else {
|
|
60
|
-
return getServersFromServerInfo(serverInfo
|
|
61
|
+
return getServersFromServerInfo(serverInfo);
|
|
61
62
|
}
|
|
62
63
|
});
|
|
63
64
|
// pingpang
|
|
64
65
|
export const pingpang = (server) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
66
|
try {
|
|
66
|
-
const result = yield
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (result.
|
|
67
|
+
const result = yield ky
|
|
68
|
+
.get(`${server}/${QUICK_CONNECT_PINGPANG_API}`)
|
|
69
|
+
.json();
|
|
70
|
+
if (result.success) {
|
|
70
71
|
return true;
|
|
71
72
|
}
|
|
72
73
|
else {
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
10
|
+
import ky from "ky";
|
|
11
11
|
import { SynologyApiInfo } from "../../types";
|
|
12
12
|
export function login(core) {
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -20,11 +20,11 @@ export function login(core) {
|
|
|
20
20
|
format: "sid",
|
|
21
21
|
};
|
|
22
22
|
const url = `${core.baseUrl}entry.cgi`;
|
|
23
|
-
const result = yield
|
|
24
|
-
if (!result.
|
|
25
|
-
throw new Error(result.
|
|
23
|
+
const result = yield ky.get(url, { searchParams: params }).json();
|
|
24
|
+
if (!result.success) {
|
|
25
|
+
throw new Error(result.error.message);
|
|
26
26
|
}
|
|
27
|
-
return result
|
|
27
|
+
return result;
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
export function logout(core) {
|
|
@@ -35,9 +35,9 @@ export function logout(core) {
|
|
|
35
35
|
method: "logout",
|
|
36
36
|
};
|
|
37
37
|
const url = `${core.baseUrl}entry.cgi`;
|
|
38
|
-
const result = yield
|
|
39
|
-
if (!result.
|
|
40
|
-
throw new Error(result.
|
|
38
|
+
const result = yield ky.get(url, { searchParams: params }).json();
|
|
39
|
+
if (!result.success) {
|
|
40
|
+
throw new Error(result.error.message);
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
}
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
10
|
+
import ky from "ky";
|
|
11
11
|
import { SynologyApiInfo } from "../../types";
|
|
12
12
|
export function getApiInfo(core) {
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -17,10 +17,10 @@ export function getApiInfo(core) {
|
|
|
17
17
|
method: "query",
|
|
18
18
|
};
|
|
19
19
|
const url = `${core.baseUrl}entry.cgi`;
|
|
20
|
-
const result = yield
|
|
21
|
-
if (!result.
|
|
22
|
-
throw new Error(result.
|
|
20
|
+
const result = yield ky.get(url, { searchParams: params }).json();
|
|
21
|
+
if (!result.success) {
|
|
22
|
+
throw new Error(result.error.message);
|
|
23
23
|
}
|
|
24
|
-
return result
|
|
24
|
+
return result;
|
|
25
25
|
});
|
|
26
26
|
}
|
|
@@ -18,7 +18,7 @@ export function getFileList() {
|
|
|
18
18
|
const res = yield this.run(FileStationApi.List, {
|
|
19
19
|
params: Object.assign({ method: "list", additional: JSON.stringify(additional), filetype: filetype, folder_path: params.folder_path }, params),
|
|
20
20
|
});
|
|
21
|
-
return res
|
|
21
|
+
return res;
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
export function getFileListShare() {
|
|
@@ -27,6 +27,6 @@ export function getFileListShare() {
|
|
|
27
27
|
const res = yield this.run(FileStationApi.List, {
|
|
28
28
|
params: Object.assign({ method: "list_share", additional: JSON.stringify(additional), onlywritable: onlywritable }, params),
|
|
29
29
|
});
|
|
30
|
-
return res
|
|
30
|
+
return res;
|
|
31
31
|
});
|
|
32
32
|
}
|
package/lib/types/helpers.d.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
+
export type ServerInfo = {
|
|
2
|
+
env: {
|
|
3
|
+
control_host: string;
|
|
4
|
+
};
|
|
5
|
+
server: {
|
|
6
|
+
external: {
|
|
7
|
+
ip: string;
|
|
8
|
+
};
|
|
9
|
+
interface: {
|
|
10
|
+
ip: string;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
service: {
|
|
14
|
+
relay_ip: string;
|
|
15
|
+
relay_port: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
1
18
|
export declare const getServerInfo: (quickConnectId: string) => Promise<string>;
|
|
2
19
|
export declare const pingpang: (server: string) => Promise<boolean>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SynologyApiResponse } from "../../types";
|
|
1
2
|
import { SynologyApi } from "../../core";
|
|
2
|
-
export declare function login(core: SynologyApi): Promise<
|
|
3
|
+
export declare function login(core: SynologyApi): Promise<SynologyApiResponse>;
|
|
3
4
|
export declare function logout(core: SynologyApi): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fett/synology-api",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.9",
|
|
4
4
|
"description": "synology api for nodejs",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"require": "./lib/cjs/index.js",
|
|
11
11
|
"import": "./lib/esm/index.js"
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
"./browser": "./lib/esm/core.js"
|
|
13
14
|
},
|
|
14
15
|
"bin": {
|
|
15
16
|
"synology": "./bin/syno",
|
|
@@ -64,10 +65,10 @@
|
|
|
64
65
|
"vitest": "^3.1.3"
|
|
65
66
|
},
|
|
66
67
|
"dependencies": {
|
|
67
|
-
"axios": "^1.9.0",
|
|
68
68
|
"chalk": "^5.4.1",
|
|
69
69
|
"commander": "^14.0.0",
|
|
70
70
|
"fs-extra": "^11.3.0",
|
|
71
|
+
"ky": "^1.8.1",
|
|
71
72
|
"ora": "^8.2.0"
|
|
72
73
|
}
|
|
73
74
|
}
|