-
Notifications
You must be signed in to change notification settings - Fork 0
/
name.ts
34 lines (31 loc) · 940 Bytes
/
name.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
import axios from "axios";
import { ClientError } from "../types/client-error";
import { INamePublishResult } from "../types/types";
export class Name {
private url: string;
constructor(url: string) {
this.url = url;
}
public async publish(params: {
cid: string;
key: string;
resolve: boolean;
ttl?: string;
lifetime?: string;
}): Promise<INamePublishResult> {
let urlParameters = ``;
urlParameters += params.key ? `&key=${params.key}` : "&key=self";
urlParameters += params.resolve ? `&resolve=true` : "&resolve=false";
urlParameters += params.ttl ? `&ttl=${params.ttl}` : "";
urlParameters += params.lifetime ? `&ttl=${params.lifetime}` : "";
try {
const res = await axios.post(
`${this.url}/name/publish?arg=${params.cid}${urlParameters}`
);
console.info(res);
return res.data;
} catch (err) {
throw new ClientError(err);
}
}
}