forked from coaidev/chatnio-api-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
105 lines (105 loc) · 4.18 KB
/
Copy pathapi.js
File metadata and controls
105 lines (105 loc) · 4.18 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buySubscription = exports.getSubscription = exports.getPackage = exports.buyQuota = exports.getQuota = exports.deleteConversation = exports.getConversation = exports.getConversations = void 0;
const index_1 = require("./index");
function getConversations() {
return __awaiter(this, void 0, void 0, function* () {
const resp = yield index_1.client.get("/conversation/list");
if (resp.status !== 200 || resp.data.status !== true) {
throw new Error("Failed to get conversations");
}
return resp.data.data;
});
}
exports.getConversations = getConversations;
function getConversation(id) {
return __awaiter(this, void 0, void 0, function* () {
const resp = yield index_1.client.get(`/conversation/load?id=${id}`);
if (resp.status !== 200 || resp.data.status !== true) {
throw new Error("Failed to get conversation");
}
return resp.data.data;
});
}
exports.getConversation = getConversation;
function deleteConversation(id) {
return __awaiter(this, void 0, void 0, function* () {
const resp = yield index_1.client.get(`/conversation/delete?id=${id}`);
if (resp.status !== 200) {
throw new Error("Failed to delete conversation");
}
return resp.data.status === true;
});
}
exports.deleteConversation = deleteConversation;
function getQuota() {
return __awaiter(this, void 0, void 0, function* () {
const resp = yield index_1.client.get("/quota");
if (resp.status !== 200 || resp.data.status !== true) {
throw new Error("Failed to get quota");
}
return resp.data.quota;
});
}
exports.getQuota = getQuota;
function buyQuota(quota) {
return __awaiter(this, void 0, void 0, function* () {
if (quota <= 0 || quota > 99999) {
throw new Error("Invalid quota");
}
else if (quota % 1 !== 0) {
throw new Error("Quota must be an integer");
}
const resp = yield index_1.client.post("/buy", { quota });
if (resp.status !== 200) {
throw new Error("Failed to buy quota");
}
return resp.data.status === true;
});
}
exports.buyQuota = buyQuota;
function getPackage() {
return __awaiter(this, void 0, void 0, function* () {
const resp = yield index_1.client.get("/package");
if (resp.status !== 200 || resp.data.status !== true) {
throw new Error("Failed to get package");
}
return resp.data.data;
});
}
exports.getPackage = getPackage;
function getSubscription() {
return __awaiter(this, void 0, void 0, function* () {
const resp = yield index_1.client.get("/subscription");
if (resp.status !== 200 || resp.data.status !== true) {
throw new Error("Failed to get subscription");
}
return resp.data.data;
});
}
exports.getSubscription = getSubscription;
function buySubscription(level, month) {
return __awaiter(this, void 0, void 0, function* () {
if (month <= 0 || month > 999) {
throw new Error("Invalid month");
}
else if (month % 1 !== 0) {
throw new Error("Month must be an integer");
}
const resp = yield index_1.client.post("/subscribe", { month, level });
if (resp.status !== 200) {
throw new Error("Failed to subscribe");
}
return resp.data.status === true;
});
}
exports.buySubscription = buySubscription;