-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkey.ts
38 lines (35 loc) · 857 Bytes
/
key.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import axios from "axios";
import FormData from "form-data";
import {
IAddResult,
IEntry,
IKeyGenResult,
INamePublishResult,
IStat,
} from "../types/types";
import { ClientError } from "../types/client-error";
import { Files } from "./files";
export class Key {
private url: string;
constructor(url: string) {
this.url = url;
}
public async gen(params: {
name: string;
type?: string;
size?: number;
}): Promise<IKeyGenResult> {
let urlParameters = "";
urlParameters += params.type ? `&type=${params.type}` : "";
urlParameters += params.size ? `&size=${params.size}` : "";
try {
const res = await axios.post(
`${this.url}/key/gen?arg=${params.name}${urlParameters}`
);
console.info(res);
return res.data;
} catch (err) {
throw new ClientError(err);
}
}
}