@fett/synology-api 0.0.4 → 0.1.0
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 +3 -3
- package/lib/cli/apis.d.ts +2 -1
- package/lib/cli/apis.js +21 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
</p>
|
|
6
6
|
<h1 align="center">Javascript Synology Api</h1>
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
   
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
👉🏻 [API Document ](https://chrissong1994.github.io/synology-api)
|
|
11
11
|
|
|
12
12
|
Synology Api Javascript wrapper can be used in Browser、CLI or Nodejs to interact with Synology NAS.
|
|
13
13
|
You can use domain or ip address, also supports Synology Quick Connect connect Synology server.
|
|
@@ -117,7 +117,7 @@ then you can use it and exec command
|
|
|
117
117
|
```bash
|
|
118
118
|
syno config use ConnetionName
|
|
119
119
|
|
|
120
|
-
syno fs getInfo --
|
|
120
|
+
syno fs getInfo --beautify # print file system info
|
|
121
121
|
|
|
122
122
|
```
|
|
123
123
|
|
package/lib/cli/apis.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export type MethodOptions = {
|
|
2
2
|
params?: string;
|
|
3
|
-
|
|
3
|
+
beautify?: boolean;
|
|
4
4
|
list?: boolean;
|
|
5
|
+
output?: string;
|
|
5
6
|
};
|
|
6
7
|
export declare const onMethodCall: (module: string) => (method: string, options: MethodOptions) => Promise<void>;
|
|
7
8
|
export declare const apiCmdRegister: () => void;
|
package/lib/cli/apis.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { program } from "commander";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import ora from "ora";
|
|
4
|
+
import fse from "fs-extra";
|
|
5
|
+
import path from "path";
|
|
4
6
|
import { loadConfig } from "./config.js";
|
|
5
7
|
import { SynologyApi } from "../core.js";
|
|
6
8
|
import { SynologyApiModules, SynologyApiMethods } from "../modules/index.js";
|
|
@@ -8,7 +10,7 @@ import { printMessages } from "./helper.js";
|
|
|
8
10
|
export const onMethodCall = (module) => async (method, options) => {
|
|
9
11
|
const config = await loadConfig();
|
|
10
12
|
const params = JSON.parse(options.params || "{}");
|
|
11
|
-
const
|
|
13
|
+
const beautify = options.beautify ?? false;
|
|
12
14
|
const connection = config.connections?.[config.used];
|
|
13
15
|
if (!connection) {
|
|
14
16
|
throw new Error("Connection undefined");
|
|
@@ -32,12 +34,26 @@ export const onMethodCall = (module) => async (method, options) => {
|
|
|
32
34
|
const spinner = ora("waiting...").start();
|
|
33
35
|
const result = await synologyApi[module]?.[method](params);
|
|
34
36
|
spinner.stop();
|
|
35
|
-
if (
|
|
37
|
+
if (beautify) {
|
|
36
38
|
console.log(JSON.stringify(result, null, 2));
|
|
37
39
|
}
|
|
38
40
|
else {
|
|
39
41
|
console.log(JSON.stringify(result));
|
|
40
42
|
}
|
|
43
|
+
if (options.output) {
|
|
44
|
+
try {
|
|
45
|
+
let out_path = path.resolve(options.output);
|
|
46
|
+
if (!fse.existsSync(out_path)) {
|
|
47
|
+
fse.ensureFileSync(out_path);
|
|
48
|
+
console.log(chalk.yellowBright(`Output file created: ${out_path}`));
|
|
49
|
+
}
|
|
50
|
+
await fse.writeFile(out_path, JSON.stringify(result, null, 2));
|
|
51
|
+
console.log(chalk.greenBright(`Output file written: ${out_path}`));
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.error(e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
41
57
|
synologyApi.disconnect();
|
|
42
58
|
process.exit(0);
|
|
43
59
|
};
|
|
@@ -52,8 +68,9 @@ export const apiCmdRegister = () => {
|
|
|
52
68
|
.command(`${info.cmd} [method]`)
|
|
53
69
|
.alias(info.alias)
|
|
54
70
|
.option("-p,--params <params>", `${info.cmd} method params`)
|
|
55
|
-
.option("
|
|
56
|
-
.option("-l,--list", `
|
|
71
|
+
.option("-b,--beautify", "Print beautify JSON data output")
|
|
72
|
+
.option("-l,--list", `List all ${info.cmd} methods`)
|
|
73
|
+
.option("-o,--output <output>", "Specify the output file, no file will be created in the current folder")
|
|
57
74
|
.description(`Synology ${info.cmd} method call`)
|
|
58
75
|
.action(onMethodCall(info.cmd));
|
|
59
76
|
});
|