dnf-api 1.0.0 → 1.0.2
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/index.js +8 -8
- package/dist/src/api/items.d.ts +2 -2
- package/package.json +39 -39
- package/src/api/characters.ts +2 -2
- package/src/api/items.ts +49 -49
- package/src/api/server.ts +1 -1
- package/src/api/setitems.ts +2 -7
- package/src/model/character.ts +98 -98
- package/src/model/item.ts +117 -117
- package/src/util/params.ts +81 -81
- package/src/util/query.ts +93 -103
package/src/util/query.ts
CHANGED
|
@@ -1,103 +1,93 @@
|
|
|
1
|
-
import consola from "consola";
|
|
2
|
-
import querystring from "query-string";
|
|
3
|
-
import { request } from "undici";
|
|
4
|
-
|
|
5
|
-
import type * as model from "../model";
|
|
6
|
-
import * as Util from "./";
|
|
7
|
-
|
|
8
|
-
const apiUrl = new URL("https://api.neople.co.kr");
|
|
9
|
-
// const client = new Client("https://api.neople.co.kr", {
|
|
10
|
-
// connectTimeout: Util.Config.timeout,
|
|
11
|
-
// // allowH2: true,
|
|
12
|
-
// });
|
|
13
|
-
|
|
14
|
-
const sender = async <T>(path: string, method: "GET" | "POST", query: any) => {
|
|
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
|
-
const resBody = (await res.body.json()) as
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
data: resBody,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public static makeItemQuery(query: any) {
|
|
100
|
-
// return JSON.stringify(query).replace(/\"|\{|\}/gi, "");
|
|
101
|
-
return encodeURI(query);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
1
|
+
import consola from "consola";
|
|
2
|
+
import querystring from "query-string";
|
|
3
|
+
import { request } from "undici";
|
|
4
|
+
|
|
5
|
+
import type * as model from "../model";
|
|
6
|
+
import * as Util from "./";
|
|
7
|
+
|
|
8
|
+
const apiUrl = new URL("https://api.neople.co.kr");
|
|
9
|
+
// const client = new Client("https://api.neople.co.kr", {
|
|
10
|
+
// connectTimeout: Util.Config.timeout,
|
|
11
|
+
// // allowH2: true,
|
|
12
|
+
// });
|
|
13
|
+
|
|
14
|
+
const sender = async <T>(path: string, method: "GET" | "POST", query: any) => {
|
|
15
|
+
apiUrl.pathname = path;
|
|
16
|
+
apiUrl.search = querystring.stringify(query);
|
|
17
|
+
const res = await request<model.IDnfResponse<T>>(apiUrl.href, {
|
|
18
|
+
method,
|
|
19
|
+
});
|
|
20
|
+
return res;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const showUrl = (url: string): string => {
|
|
24
|
+
if (Util.config.key) {
|
|
25
|
+
return url?.replace(Util.config.key, Util.config.hideKeyText);
|
|
26
|
+
} else {
|
|
27
|
+
return url;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
|
|
32
|
+
export default class Request {
|
|
33
|
+
public static UriBuilder(...args: any[]): string {
|
|
34
|
+
return args.join("/");
|
|
35
|
+
}
|
|
36
|
+
public static QueryBuilder(query: string[] | number[]): string {
|
|
37
|
+
const qString: string[] = [];
|
|
38
|
+
for (const key in query) {
|
|
39
|
+
qString.push(`${key}:${query[key]},`);
|
|
40
|
+
}
|
|
41
|
+
return qString.join(",");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 던전앤파이터 API 서버에 응답을 요청하는 함수 입니다.
|
|
46
|
+
* 해당 함수를 직접 호출 하는것을 권장하지 않습니다.
|
|
47
|
+
*
|
|
48
|
+
* @param {object} opt (요청을 보낼 Parameter값)
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
public static async Request<T>(
|
|
52
|
+
opt: any = {},
|
|
53
|
+
method: "GET" | "POST" = "GET"
|
|
54
|
+
): Promise<model.IDnfResponse<T>> {
|
|
55
|
+
if (!Util.config.key || Util.config.key === "") {
|
|
56
|
+
consola.error("Please change to your api key. ");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (opt.params === undefined) opt.params = {};
|
|
60
|
+
if (opt.params.q) opt.params.q = Request.QueryBuilder(opt.params.q);
|
|
61
|
+
|
|
62
|
+
opt.params.apikey = Util.config.key;
|
|
63
|
+
|
|
64
|
+
if (Util.config.showURL)
|
|
65
|
+
consola.log(
|
|
66
|
+
"request url:",
|
|
67
|
+
showUrl(`${opt.base}?${querystring.stringify(opt.params)}`)
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const res = await sender<T>(opt.base, method, opt.params);
|
|
71
|
+
if (res.statusCode !== 200) {
|
|
72
|
+
const resBody = (await res.body.json()) as model.IDnfResponse<T>;
|
|
73
|
+
const error: model.IDnfErrorResponse = {
|
|
74
|
+
url: showUrl(opt.url ?? ""),
|
|
75
|
+
status: res.statusCode || 0,
|
|
76
|
+
statusText: "",
|
|
77
|
+
code: resBody.error?.code || "",
|
|
78
|
+
message: resBody.error?.message || "",
|
|
79
|
+
};
|
|
80
|
+
return { error };
|
|
81
|
+
} else {
|
|
82
|
+
const resBody = (await res.body.json()) as T;
|
|
83
|
+
return {
|
|
84
|
+
data: resBody,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public static makeItemQuery(query: any) {
|
|
90
|
+
// return JSON.stringify(query).replace(/\"|\{|\}/gi, "");
|
|
91
|
+
return encodeURI(query);
|
|
92
|
+
}
|
|
93
|
+
}
|