@fett/synology-api 0.0.1-beta.2 → 0.0.1-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/dist/cjs/index.js CHANGED
@@ -1,19 +1,341 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
+ // If the importer is in node compatibility mode or this is not an ESM
35
+ // file that has been converted to a CommonJS file using a Babel-
36
+ // compatible transform (i.e. "__esModule" has not been set), then set
37
+ // "default" to the CommonJS "module.exports" for node compatibility.
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
+ mod
40
+ ));
41
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
+ var __async = (__this, __arguments, generator) => {
43
+ return new Promise((resolve, reject) => {
44
+ var fulfilled = (value) => {
45
+ try {
46
+ step(generator.next(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var rejected = (value) => {
52
+ try {
53
+ step(generator.throw(value));
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+ };
58
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
59
+ step((generator = generator.apply(__this, __arguments)).next());
60
+ });
61
+ };
62
+
63
+ // src/index.ts
64
+ var index_exports = {};
65
+ __export(index_exports, {
66
+ SynologyApi: () => SynologyApi,
67
+ default: () => index_default
68
+ });
69
+ module.exports = __toCommonJS(index_exports);
70
+
71
+ // src/core.ts
72
+ var import_axios4 = __toESM(require("axios"));
73
+
74
+ // src/modules/AudioStation/Song/index.ts
75
+ function getSongList(params) {
76
+ return __async(this, null, function* () {
77
+ const res = yield this.run("SYNO.AudioStation.Song", {
78
+ params: {
79
+ method: "list",
80
+ library: "all",
81
+ limit: params.limit,
82
+ offset: params.offset
83
+ }
84
+ });
85
+ return res.data;
86
+ });
87
+ }
88
+
89
+ // src/modules/AudioStation/index.ts
90
+ var AudioStationMethods = {
91
+ getSongList
92
+ };
93
+ var AudioStationKey = "AudioStation";
94
+
95
+ // src/modules/index.ts
96
+ function methodsBundler(instance, methods) {
97
+ const output = {};
98
+ for (const key in methods) {
99
+ output[key] = methods[key].bind(instance);
100
+ }
101
+ return output;
102
+ }
103
+ AudioStationKey;
104
+ var BaseSynologyApi = class {
105
+ constructor() {
106
+ }
107
+ };
108
+ Object.defineProperties(BaseSynologyApi.prototype, {
109
+ [AudioStationKey]: {
110
+ get() {
111
+ return methodsBundler(this, AudioStationMethods);
112
+ }
113
+ }
114
+ });
115
+
116
+ // src/utils.ts
117
+ function isHttpUrl(url) {
118
+ return /^https?:\/\//.test(url);
119
+ }
120
+
121
+ // src/helpers.ts
122
+ var import_axios = __toESM(require("axios"));
123
+
124
+ // src/constants.ts
125
+ var SYNOLOGY_API_AUTH = "SYNO.API.Auth";
126
+ var SYNOLOGY_API_INFO = "SYNO.API.Info";
127
+ var GLOBAL_QUICK_CONNECT_URL = "https://global.quickconnect.cn/Serv.php";
128
+ var QUICK_CONNECT_PINGPANG_API = "/webman/pingpong.cgi?action=cors&quickconnect=true";
129
+
130
+ // src/helpers.ts
131
+ var getServersFromServerInfo = (serverInfo) => __async(null, null, function* () {
132
+ var _a, _b;
133
+ if (serverInfo.service.relay_ip) {
134
+ const server = `http://${serverInfo.service.relay_ip}:${serverInfo.service.relay_port}`;
135
+ const res = yield pingpang(server);
136
+ if (res) {
137
+ return server;
138
+ }
139
+ }
140
+ if (serverInfo.server.external.ip) {
141
+ const server = `http://${serverInfo.server.external.ip}:${serverInfo.service.port}`;
142
+ if (yield pingpang(server)) {
143
+ return server;
144
+ }
145
+ }
146
+ if ((_a = serverInfo.server.interface) == null ? void 0 : _a[0]) {
147
+ const server = `http://${(_b = serverInfo.server.interface) == null ? void 0 : _b[0].ip}:${serverInfo.service.port}`;
148
+ if (yield pingpang(server)) {
149
+ return server;
150
+ }
151
+ }
152
+ });
153
+ var getServerInfo = (quickConnectId) => __async(null, null, function* () {
154
+ var _a, _b, _c, _d;
155
+ const params = {
156
+ version: 1,
157
+ id: "dsm",
158
+ serverID: quickConnectId,
159
+ get_ca_fingerprints: true,
160
+ command: "get_server_info"
161
+ };
162
+ const serverInfo = yield import_axios.default.post(GLOBAL_QUICK_CONNECT_URL, params);
163
+ if (!((_b = (_a = serverInfo.data) == null ? void 0 : _a.service) == null ? void 0 : _b.relay_ip) && !((_d = (_c = serverInfo.data) == null ? void 0 : _c.service) == null ? void 0 : _d.relay_port)) {
164
+ const relayRequestParams = {
165
+ version: 1,
166
+ id: "dsm",
167
+ serverID: quickConnectId,
168
+ platform: "web",
169
+ command: "request_tunnel"
170
+ };
171
+ const result = yield import_axios.default.post(
172
+ `https://${serverInfo.data.env.control_host}/Serv.php`,
173
+ relayRequestParams
174
+ );
175
+ return getServersFromServerInfo(result.data);
176
+ } else {
177
+ return getServersFromServerInfo(serverInfo.data);
178
+ }
179
+ });
180
+ var pingpang = (server) => __async(null, null, function* () {
181
+ try {
182
+ const result = yield import_axios.default.get(`${server}/${QUICK_CONNECT_PINGPANG_API}`, {
183
+ timeout: 3e3
184
+ });
185
+ if (result.data.success) {
186
+ return true;
187
+ } else {
188
+ return false;
189
+ }
190
+ } catch (_err) {
191
+ return false;
192
+ }
193
+ });
194
+
195
+ // src/modules/Api/Auth.ts
196
+ var import_axios2 = __toESM(require("axios"));
197
+ function login(core) {
198
+ return __async(this, null, function* () {
199
+ const params = {
200
+ api: SYNOLOGY_API_AUTH,
201
+ version: 6,
202
+ method: "login",
203
+ account: core.username,
204
+ passwd: core.password,
205
+ format: "sid"
206
+ };
207
+ const url = `${core.baseUrl}entry.cgi`;
208
+ const result = yield import_axios2.default.get(url, { params });
209
+ if (!result.data.success) {
210
+ throw new Error(result.data.error.message);
211
+ }
212
+ return result.data;
213
+ });
214
+ }
215
+ function logout(core) {
216
+ return __async(this, null, function* () {
217
+ const params = {
218
+ api: SYNOLOGY_API_AUTH,
219
+ version: 6,
220
+ method: "logout"
221
+ };
222
+ const url = `${core.baseUrl}entry.cgi`;
223
+ const result = yield import_axios2.default.get(url, { params });
224
+ if (!result.data.success) {
225
+ throw new Error(result.data.error.message);
226
+ }
227
+ });
228
+ }
229
+
230
+ // src/modules/Api/Info.ts
231
+ var import_axios3 = __toESM(require("axios"));
232
+ function getApiInfo(core) {
233
+ return __async(this, null, function* () {
234
+ const params = {
235
+ api: SYNOLOGY_API_INFO,
236
+ version: 1,
237
+ method: "query"
238
+ };
239
+ const url = `${core.baseUrl}entry.cgi`;
240
+ const result = yield import_axios3.default.get(url, { params });
241
+ if (!result.data.success) {
242
+ throw new Error(result.data.error.message);
243
+ }
244
+ return result.data;
245
+ });
246
+ }
247
+
248
+ // src/core.ts
249
+ var SynologyApi = class extends BaseSynologyApi {
250
+ constructor(options) {
251
+ super();
252
+ this.isConnecting = false;
253
+ this.authInfo = null;
254
+ this.apiInfo = {};
255
+ this.server = options.server;
256
+ this.username = options.username;
257
+ this.password = options.password;
258
+ this.baseUrl = `${this.server}/webapi/`;
259
+ }
260
+ connect() {
261
+ return __async(this, null, function* () {
262
+ if (!isHttpUrl(this.server)) {
263
+ this.server = yield getServerInfo(this.server);
264
+ this.baseUrl = `${this.server}/webapi/`;
265
+ }
266
+ try {
267
+ const result = yield login(this);
268
+ this.authInfo = result.data;
269
+ this.isConnecting = true;
270
+ yield this._getApiInfo();
271
+ return true;
272
+ } catch (err) {
273
+ console.error(err);
274
+ return false;
275
+ }
276
+ });
277
+ }
278
+ disconnect() {
279
+ return __async(this, null, function* () {
280
+ try {
281
+ yield logout(this);
282
+ this.authInfo = null;
283
+ this.apiInfo = {};
284
+ this.isConnecting = false;
285
+ return true;
286
+ } catch (err) {
287
+ console.error(err);
288
+ return false;
289
+ }
290
+ });
291
+ }
292
+ _getApiInfo() {
293
+ return __async(this, null, function* () {
294
+ try {
295
+ const result = yield getApiInfo(this);
296
+ this.apiInfo = result.data;
297
+ } catch (err) {
298
+ console.error(err);
299
+ }
300
+ });
301
+ }
302
+ hasApi(apiName) {
303
+ if (!this.isConnecting) {
304
+ throw new Error("Not connected");
305
+ }
306
+ return Object.prototype.hasOwnProperty.call(this.apiInfo, apiName);
307
+ }
308
+ run(apiName, options) {
309
+ return __async(this, null, function* () {
310
+ if (!this.isConnecting) {
311
+ throw new Error("Not connected");
312
+ }
313
+ if (!this.hasApi(apiName)) {
314
+ throw new Error(`${apiName} not found`);
315
+ }
316
+ const { method = "get", params, data, headers } = options;
317
+ const api = this.apiInfo[apiName];
318
+ const url = `${this.baseUrl}${api.path}`;
319
+ const externalParams = __spreadValues({
320
+ api: apiName,
321
+ version: api.maxVersion,
322
+ _sid: this.authInfo.sid
323
+ }, params);
324
+ let result = null;
325
+ if (method === "get") {
326
+ result = yield import_axios4.default.get(url, { params: externalParams, data, headers });
327
+ }
328
+ if (method === "post") {
329
+ result = yield import_axios4.default.post(url, { params: externalParams, data, headers });
330
+ }
331
+ return result;
332
+ });
333
+ }
15
334
  };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- const core_1 = require("./core");
18
- __exportStar(require("./core"), exports);
19
- exports.default = core_1.SynologyApi;
335
+
336
+ // src/index.ts
337
+ var index_default = SynologyApi;
338
+ // Annotate the CommonJS export names for ESM import in node:
339
+ 0 && (module.exports = {
340
+ SynologyApi
341
+ });
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@fett/synology-api",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.3",
4
4
  "description": "synology api for nodejs",
5
5
  "module": "./dist/esm/index.js",
6
6
  "main": "./dist/cjs/index.js",
7
7
  "types": "./dist/types/index.d.ts",
8
- "type": "module",
9
8
  "exports": {
10
9
  ".": {
11
10
  "require": "./dist/cjs/index.js",
@@ -28,8 +27,8 @@
28
27
  ],
29
28
  "scripts": {
30
29
  "dev": "tsc --sourceMap --watch && tsc-alias",
31
- "build:cjs": "tsc --module commonjs --outDir dist/cjs && tsc-alias",
32
- "build:esm": "tsc --module esnext --outDir dist/esm && tsc-alias",
30
+ "build:cjs": "tsup --config tsup.config.ts",
31
+ "build:esm": "tsc && tsc-alias",
33
32
  "build": "npm run clean && npm run build:cjs && npm run build:esm",
34
33
  "clean": "rimraf dist",
35
34
  "lint": "eslint src --ext .ts --fix",
@@ -50,6 +49,7 @@
50
49
  "rimraf": "^6.0.1",
51
50
  "ts-node": "^10.9.2",
52
51
  "tsc-alias": "^1.8.16",
52
+ "tsup": "^8.5.0",
53
53
  "typescript": "~5.8.3",
54
54
  "typescript-eslint": "^8.32.0",
55
55
  "vite": "^6.3.5",
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QUICK_CONNECT_PINGPANG_API = exports.GLOBAL_QUICK_CONNECT_URL = exports.SYNOLOGY_API_INFO = exports.SYNOLOGY_API_AUTH = void 0;
4
- exports.SYNOLOGY_API_AUTH = "SYNO.API.Auth";
5
- exports.SYNOLOGY_API_INFO = "SYNO.API.Info";
6
- exports.GLOBAL_QUICK_CONNECT_URL = "https://global.quickconnect.cn/Serv.php";
7
- exports.QUICK_CONNECT_PINGPANG_API = "/webman/pingpong.cgi?action=cors&quickconnect=true";
package/dist/cjs/core.js DELETED
@@ -1,109 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.SynologyApi = void 0;
16
- // reference: https://kb.synology.com/zh-tw/DSM/tutorial/What_websites_does_Synology_NAS_connect_to_when_running_services_or_updating_software
17
- const axios_1 = __importDefault(require("axios"));
18
- const modules_1 = require("./modules");
19
- const utils_1 = require("./utils");
20
- const helpers_1 = require("./helpers");
21
- const Api_1 = require("./modules/Api");
22
- class SynologyApi extends modules_1.BaseSynologyApi {
23
- constructor(options) {
24
- super();
25
- this.isConnecting = false;
26
- this.authInfo = null;
27
- this.apiInfo = {};
28
- this.server = options.server;
29
- this.username = options.username;
30
- this.password = options.password;
31
- this.baseUrl = `${this.server}/webapi/`;
32
- }
33
- connect() {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- // if quickconnect id
36
- if (!(0, utils_1.isHttpUrl)(this.server)) {
37
- this.server = yield (0, helpers_1.getServerInfo)(this.server);
38
- // reset base url
39
- this.baseUrl = `${this.server}/webapi/`;
40
- }
41
- try {
42
- const result = yield (0, Api_1.login)(this);
43
- this.authInfo = result.data;
44
- this.isConnecting = true;
45
- yield this._getApiInfo();
46
- return true;
47
- }
48
- catch (err) {
49
- console.error(err);
50
- return false;
51
- }
52
- });
53
- }
54
- disconnect() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- try {
57
- yield (0, Api_1.logout)(this);
58
- this.authInfo = null;
59
- this.apiInfo = {};
60
- this.isConnecting = false;
61
- return true;
62
- }
63
- catch (err) {
64
- console.error(err);
65
- return false;
66
- }
67
- });
68
- }
69
- _getApiInfo() {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- try {
72
- const result = yield (0, Api_1.getApiInfo)(this);
73
- this.apiInfo = result.data;
74
- }
75
- catch (err) {
76
- console.error(err);
77
- }
78
- });
79
- }
80
- hasApi(apiName) {
81
- if (!this.isConnecting) {
82
- throw new Error("Not connected");
83
- }
84
- return Object.prototype.hasOwnProperty.call(this.apiInfo, apiName);
85
- }
86
- run(apiName, options) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- if (!this.isConnecting) {
89
- throw new Error("Not connected");
90
- }
91
- if (!this.hasApi(apiName)) {
92
- throw new Error(`${apiName} not found`);
93
- }
94
- const { method = "get", params, data, headers } = options;
95
- const api = this.apiInfo[apiName];
96
- const url = `${this.baseUrl}${api.path}`;
97
- const externalParams = Object.assign({ api: apiName, version: api.maxVersion, _sid: this.authInfo.sid }, params);
98
- let result = null;
99
- if (method === "get") {
100
- result = yield axios_1.default.get(url, { params: externalParams, data, headers });
101
- }
102
- if (method === "post") {
103
- result = yield axios_1.default.post(url, { params: externalParams, data, headers });
104
- }
105
- return result;
106
- });
107
- }
108
- }
109
- exports.SynologyApi = SynologyApi;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.pingpang = exports.getServerInfo = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const constants_1 = require("./constants");
18
- const getServersFromServerInfo = (serverInfo) => __awaiter(void 0, void 0, void 0, function* () {
19
- var _a, _b;
20
- // proxy server
21
- if (serverInfo.service.relay_ip) {
22
- const server = `http://${serverInfo.service.relay_ip}:${serverInfo.service.relay_port}`;
23
- const res = yield (0, exports.pingpang)(server);
24
- if (res) {
25
- return server;
26
- }
27
- }
28
- // WAN IP
29
- if (serverInfo.server.external.ip) {
30
- const server = `http://${serverInfo.server.external.ip}:${serverInfo.service.port}`;
31
- if (yield (0, exports.pingpang)(server)) {
32
- return server;
33
- }
34
- }
35
- // lan ip
36
- if ((_a = serverInfo.server.interface) === null || _a === void 0 ? void 0 : _a[0]) {
37
- const server = `http://${(_b = serverInfo.server.interface) === null || _b === void 0 ? void 0 : _b[0].ip}:${serverInfo.service.port}`;
38
- if (yield (0, exports.pingpang)(server)) {
39
- return server;
40
- }
41
- }
42
- });
43
- // get server ip
44
- const getServerInfo = (quickConnectId) => __awaiter(void 0, void 0, void 0, function* () {
45
- var _a, _b, _c, _d;
46
- const params = {
47
- version: 1,
48
- id: "dsm",
49
- serverID: quickConnectId,
50
- get_ca_fingerprints: true,
51
- command: "get_server_info",
52
- };
53
- const serverInfo = yield axios_1.default.post(constants_1.GLOBAL_QUICK_CONNECT_URL, params);
54
- if (!((_b = (_a = serverInfo.data) === null || _a === void 0 ? void 0 : _a.service) === null || _b === void 0 ? void 0 : _b.relay_ip) && !((_d = (_c = serverInfo.data) === null || _c === void 0 ? void 0 : _c.service) === null || _d === void 0 ? void 0 : _d.relay_port)) {
55
- const relayRequestParams = {
56
- version: 1,
57
- id: "dsm",
58
- serverID: quickConnectId,
59
- platform: "web",
60
- command: "request_tunnel",
61
- };
62
- const result = yield axios_1.default.post(`https://${serverInfo.data.env.control_host}/Serv.php`, relayRequestParams);
63
- return getServersFromServerInfo(result.data);
64
- }
65
- else {
66
- return getServersFromServerInfo(serverInfo.data);
67
- }
68
- });
69
- exports.getServerInfo = getServerInfo;
70
- // pingpang
71
- const pingpang = (server) => __awaiter(void 0, void 0, void 0, function* () {
72
- try {
73
- const result = yield axios_1.default.get(`${server}/${constants_1.QUICK_CONNECT_PINGPANG_API}`, {
74
- timeout: 3000,
75
- });
76
- if (result.data.success) {
77
- return true;
78
- }
79
- else {
80
- return false;
81
- }
82
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
83
- }
84
- catch (_err) {
85
- return false;
86
- }
87
- });
88
- exports.pingpang = pingpang;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.login = login;
16
- exports.logout = logout;
17
- const axios_1 = __importDefault(require("axios"));
18
- const constants_1 = require("@/constants");
19
- function login(core) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const params = {
22
- api: constants_1.SYNOLOGY_API_AUTH,
23
- version: 6,
24
- method: "login",
25
- account: core.username,
26
- passwd: core.password,
27
- format: "sid",
28
- };
29
- const url = `${core.baseUrl}entry.cgi`;
30
- const result = yield axios_1.default.get(url, { params });
31
- if (!result.data.success) {
32
- throw new Error(result.data.error.message);
33
- }
34
- return result.data;
35
- });
36
- }
37
- function logout(core) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const params = {
40
- api: constants_1.SYNOLOGY_API_AUTH,
41
- version: 6,
42
- method: "logout",
43
- };
44
- const url = `${core.baseUrl}entry.cgi`;
45
- const result = yield axios_1.default.get(url, { params });
46
- if (!result.data.success) {
47
- throw new Error(result.data.error.message);
48
- }
49
- });
50
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getApiInfo = getApiInfo;
16
- const axios_1 = __importDefault(require("axios"));
17
- const constants_1 = require("@/constants");
18
- function getApiInfo(core) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const params = {
21
- api: constants_1.SYNOLOGY_API_INFO,
22
- version: 1,
23
- method: "query",
24
- };
25
- const url = `${core.baseUrl}entry.cgi`;
26
- const result = yield axios_1.default.get(url, { params });
27
- if (!result.data.success) {
28
- throw new Error(result.data.error.message);
29
- }
30
- return result.data;
31
- });
32
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Auth"), exports);
18
- __exportStar(require("./Info"), exports);
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getSongList = getSongList;
13
- /**
14
- * fetch song list
15
- * */
16
- function getSongList(params) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const res = yield this.run("SYNO.AudioStation.Song", {
19
- params: {
20
- method: "list",
21
- library: "all",
22
- limit: params.limit,
23
- offset: params.offset,
24
- },
25
- });
26
- return res.data;
27
- });
28
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AudioStationKey = exports.AudioStationMethods = void 0;
4
- const Song_1 = require("./Song");
5
- exports.AudioStationMethods = {
6
- getSongList: Song_1.getSongList,
7
- };
8
- exports.AudioStationKey = "AudioStation";
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseSynologyApi = void 0;
4
- const AudioStation_1 = require("./AudioStation");
5
- // bind methods to BaseSynologyApi instance
6
- function methodsBundler(instance, methods) {
7
- const output = {};
8
- for (const key in methods) {
9
- output[key] = methods[key].bind(instance);
10
- }
11
- return output;
12
- }
13
- class BaseSynologyApi {
14
- constructor() { }
15
- }
16
- exports.BaseSynologyApi = BaseSynologyApi;
17
- // proxy methods namespace to BaseSynologyApi instance
18
- Object.defineProperties(BaseSynologyApi.prototype, {
19
- [AudioStation_1.AudioStationKey]: {
20
- get() {
21
- return methodsBundler(this, AudioStation_1.AudioStationMethods);
22
- },
23
- },
24
- });
@@ -1,3 +0,0 @@
1
- "use strict";
2
- // export response
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./API"), exports);
package/dist/cjs/utils.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isObjEmpty = isObjEmpty;
4
- exports.queryObjToString = queryObjToString;
5
- exports.isHttpUrl = isHttpUrl;
6
- function isObjEmpty(obj) {
7
- return obj && typeof obj === "object" && Object.keys(obj).length === 0;
8
- }
9
- function queryObjToString(params) {
10
- if (isObjEmpty(params)) {
11
- return "";
12
- }
13
- return Object.keys(params)
14
- .map((key) => encodeURIComponent(key) + "=" + encodeURIComponent(params[key]))
15
- .join("&");
16
- }
17
- function isHttpUrl(url) {
18
- return /^https?:\/\//.test(url);
19
- }