dnf-api 1.1.0 → 1.1.1
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/api/auction.d.ts +5 -5
- package/dist/api/multi.d.ts +2 -2
- package/dist/index.d.ts +7 -14
- package/dist/index.js +13 -13
- package/dist/model/auction.d.ts +47 -0
- package/dist/model/index.d.ts +2 -48
- package/dist/src/api/auction.d.ts +5 -5
- package/dist/src/api/multi.d.ts +2 -2
- package/dist/src/index.d.ts +7 -14
- package/dist/src/model/auction.d.ts +47 -0
- package/dist/src/model/index.d.ts +2 -48
- package/package.json +1 -1
- package/src/api/auction.ts +67 -67
- package/src/api/characters.equip.ts +81 -81
- package/src/api/characters.skill.ts +86 -86
- package/src/api/characters.ts +91 -91
- package/src/api/index.ts +10 -10
- package/src/api/items.ts +49 -49
- package/src/api/multi.ts +17 -17
- package/src/api/server.ts +9 -9
- package/src/api/setitems.ts +29 -29
- package/src/index.ts +28 -35
- package/src/model/auction.ts +48 -0
- package/src/model/character.ts +98 -98
- package/src/model/index.ts +47 -95
- package/src/model/item.ts +117 -117
- package/src/model/setitem.ts +33 -33
- package/src/util/config.ts +43 -43
- package/src/util/index.ts +17 -17
- package/src/util/params.ts +95 -95
- package/src/util/query.ts +147 -144
- package/src/util/queue.ts +104 -104
- package/src/util/request-helper.ts +19 -19
- package/src/util/static.ts +52 -52
package/src/util/queue.ts
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import config from "./config";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Rate limiting 요청 큐
|
|
5
|
-
* 1초당 최대 요청 수를 제한합니다.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
interface QueueItem<T> {
|
|
9
|
-
task: () => Promise<T>;
|
|
10
|
-
resolve: (value: T) => void;
|
|
11
|
-
reject: (error: Error) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class RequestQueue {
|
|
15
|
-
private queue: QueueItem<unknown>[] = [];
|
|
16
|
-
private processing = false;
|
|
17
|
-
private requestCount = 0;
|
|
18
|
-
private lastResetTime = Date.now();
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 큐에 요청을 추가합니다.
|
|
22
|
-
* @param task 실행할 비동기 작업
|
|
23
|
-
* @returns 작업 결과 Promise
|
|
24
|
-
*/
|
|
25
|
-
async add<T>(task: () => Promise<T>): Promise<T> {
|
|
26
|
-
return new Promise<T>((resolve, reject) => {
|
|
27
|
-
this.queue.push({
|
|
28
|
-
task,
|
|
29
|
-
resolve: resolve as (value: unknown) => void,
|
|
30
|
-
reject,
|
|
31
|
-
});
|
|
32
|
-
this.processQueue();
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 큐를 처리합니다.
|
|
38
|
-
*/
|
|
39
|
-
private async processQueue(): Promise<void> {
|
|
40
|
-
if (this.processing) return;
|
|
41
|
-
this.processing = true;
|
|
42
|
-
|
|
43
|
-
while (this.queue.length > 0) {
|
|
44
|
-
// 1초마다 카운터 리셋
|
|
45
|
-
const now = Date.now();
|
|
46
|
-
if (now - this.lastResetTime >= 1000) {
|
|
47
|
-
this.requestCount = 0;
|
|
48
|
-
this.lastResetTime = now;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 제한에 도달하면 대기 (config에서 실시간으로 가져옴)
|
|
52
|
-
if (this.requestCount >= config.maxRequestsPerSecond) {
|
|
53
|
-
const waitTime = 1000 - (now - this.lastResetTime);
|
|
54
|
-
if (waitTime > 0) {
|
|
55
|
-
await this.sleep(waitTime);
|
|
56
|
-
}
|
|
57
|
-
this.requestCount = 0;
|
|
58
|
-
this.lastResetTime = Date.now();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const item = this.queue.shift();
|
|
62
|
-
if (!item) break;
|
|
63
|
-
|
|
64
|
-
this.requestCount++;
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const result = await item.task();
|
|
68
|
-
item.resolve(result);
|
|
69
|
-
} catch (error) {
|
|
70
|
-
item.reject(error as Error);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
this.processing = false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private sleep(ms: number): Promise<void> {
|
|
78
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 현재 큐 상태를 반환합니다.
|
|
83
|
-
*/
|
|
84
|
-
get status() {
|
|
85
|
-
return {
|
|
86
|
-
queueLength: this.queue.length,
|
|
87
|
-
requestCount: this.requestCount,
|
|
88
|
-
maxRequestsPerSecond: config.maxRequestsPerSecond,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 큐를 초기화합니다.
|
|
94
|
-
*/
|
|
95
|
-
clear(): void {
|
|
96
|
-
this.queue = [];
|
|
97
|
-
this.requestCount = 0;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 기본 큐 인스턴스 (제한 수치는 config를 따름)
|
|
102
|
-
export const requestQueue = new RequestQueue();
|
|
103
|
-
|
|
104
|
-
export default requestQueue;
|
|
1
|
+
import config from "./config";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Rate limiting 요청 큐
|
|
5
|
+
* 1초당 최대 요청 수를 제한합니다.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface QueueItem<T> {
|
|
9
|
+
task: () => Promise<T>;
|
|
10
|
+
resolve: (value: T) => void;
|
|
11
|
+
reject: (error: Error) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class RequestQueue {
|
|
15
|
+
private queue: QueueItem<unknown>[] = [];
|
|
16
|
+
private processing = false;
|
|
17
|
+
private requestCount = 0;
|
|
18
|
+
private lastResetTime = Date.now();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 큐에 요청을 추가합니다.
|
|
22
|
+
* @param task 실행할 비동기 작업
|
|
23
|
+
* @returns 작업 결과 Promise
|
|
24
|
+
*/
|
|
25
|
+
async add<T>(task: () => Promise<T>): Promise<T> {
|
|
26
|
+
return new Promise<T>((resolve, reject) => {
|
|
27
|
+
this.queue.push({
|
|
28
|
+
task,
|
|
29
|
+
resolve: resolve as (value: unknown) => void,
|
|
30
|
+
reject,
|
|
31
|
+
});
|
|
32
|
+
this.processQueue();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 큐를 처리합니다.
|
|
38
|
+
*/
|
|
39
|
+
private async processQueue(): Promise<void> {
|
|
40
|
+
if (this.processing) return;
|
|
41
|
+
this.processing = true;
|
|
42
|
+
|
|
43
|
+
while (this.queue.length > 0) {
|
|
44
|
+
// 1초마다 카운터 리셋
|
|
45
|
+
const now = Date.now();
|
|
46
|
+
if (now - this.lastResetTime >= 1000) {
|
|
47
|
+
this.requestCount = 0;
|
|
48
|
+
this.lastResetTime = now;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 제한에 도달하면 대기 (config에서 실시간으로 가져옴)
|
|
52
|
+
if (this.requestCount >= config.maxRequestsPerSecond) {
|
|
53
|
+
const waitTime = 1000 - (now - this.lastResetTime);
|
|
54
|
+
if (waitTime > 0) {
|
|
55
|
+
await this.sleep(waitTime);
|
|
56
|
+
}
|
|
57
|
+
this.requestCount = 0;
|
|
58
|
+
this.lastResetTime = Date.now();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const item = this.queue.shift();
|
|
62
|
+
if (!item) break;
|
|
63
|
+
|
|
64
|
+
this.requestCount++;
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const result = await item.task();
|
|
68
|
+
item.resolve(result);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
item.reject(error as Error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.processing = false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private sleep(ms: number): Promise<void> {
|
|
78
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 현재 큐 상태를 반환합니다.
|
|
83
|
+
*/
|
|
84
|
+
get status() {
|
|
85
|
+
return {
|
|
86
|
+
queueLength: this.queue.length,
|
|
87
|
+
requestCount: this.requestCount,
|
|
88
|
+
maxRequestsPerSecond: config.maxRequestsPerSecond,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 큐를 초기화합니다.
|
|
94
|
+
*/
|
|
95
|
+
clear(): void {
|
|
96
|
+
this.queue = [];
|
|
97
|
+
this.requestCount = 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 기본 큐 인스턴스 (제한 수치는 config를 따름)
|
|
102
|
+
export const requestQueue = new RequestQueue();
|
|
103
|
+
|
|
104
|
+
export default requestQueue;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type * as model from "../model";
|
|
2
|
-
import type { BaseParams } from "./params";
|
|
3
|
-
import { Request, UriBuilder } from "./query";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* API 요청을 생성하는 헬퍼 함수
|
|
7
|
-
* @param baseParts URI 경로 세그먼트들
|
|
8
|
-
* @param params 요청 파라미터
|
|
9
|
-
* @returns API 응답 Promise
|
|
10
|
-
*/
|
|
11
|
-
export function createRequest<T>(
|
|
12
|
-
baseParts: (string | number)[],
|
|
13
|
-
params?: BaseParams,
|
|
14
|
-
): Promise<model.IDnfResponse<T>> {
|
|
15
|
-
return Request<T>({
|
|
16
|
-
base: UriBuilder(...baseParts),
|
|
17
|
-
params,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
1
|
+
import type * as model from "../model";
|
|
2
|
+
import type { BaseParams } from "./params";
|
|
3
|
+
import { Request, UriBuilder } from "./query";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* API 요청을 생성하는 헬퍼 함수
|
|
7
|
+
* @param baseParts URI 경로 세그먼트들
|
|
8
|
+
* @param params 요청 파라미터
|
|
9
|
+
* @returns API 응답 Promise
|
|
10
|
+
*/
|
|
11
|
+
export function createRequest<T>(
|
|
12
|
+
baseParts: (string | number)[],
|
|
13
|
+
params?: BaseParams,
|
|
14
|
+
): Promise<model.IDnfResponse<T>> {
|
|
15
|
+
return Request<T>({
|
|
16
|
+
base: UriBuilder(...baseParts),
|
|
17
|
+
params,
|
|
18
|
+
});
|
|
19
|
+
}
|
package/src/util/static.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
export enum server {
|
|
2
|
-
Cain = "cain",
|
|
3
|
-
Diregie = "diregie",
|
|
4
|
-
Siroco = "siroco",
|
|
5
|
-
Prey = "prey",
|
|
6
|
-
Casillas = "casillas",
|
|
7
|
-
Hilder = "hilder",
|
|
8
|
-
Anton = "anton",
|
|
9
|
-
Bakal = "bakal",
|
|
10
|
-
}
|
|
11
|
-
export enum sort {
|
|
12
|
-
Asc = "asc",
|
|
13
|
-
Desc = "desc",
|
|
14
|
-
}
|
|
15
|
-
export enum rarity {
|
|
16
|
-
Common = "커먼",
|
|
17
|
-
Uncommon = "언커먼",
|
|
18
|
-
Rare = "레어",
|
|
19
|
-
Unique = "유니크",
|
|
20
|
-
Eqic = "에픽",
|
|
21
|
-
Chronicle = "크로니클",
|
|
22
|
-
Legendary = "레전더리",
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export enum auctionWordType {
|
|
26
|
-
Match = "match",
|
|
27
|
-
Front = "front",
|
|
28
|
-
Full = "full",
|
|
29
|
-
}
|
|
30
|
-
export enum wordType {
|
|
31
|
-
Match = "match",
|
|
32
|
-
Front = "front",
|
|
33
|
-
Full = "full",
|
|
34
|
-
}
|
|
35
|
-
export enum charactersWordType {
|
|
36
|
-
Match = "match",
|
|
37
|
-
Full = "full",
|
|
38
|
-
}
|
|
39
|
-
export enum baseUri {
|
|
40
|
-
Servers = "df/servers",
|
|
41
|
-
Auction = "df/auction",
|
|
42
|
-
AuctionSold = "df/auction-sold",
|
|
43
|
-
Item = "df/items",
|
|
44
|
-
SetItem = "df/setitems",
|
|
45
|
-
Multi = "df/multi",
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export enum reinforceType {
|
|
49
|
-
reinforce = "강화",
|
|
50
|
-
minRefine = "증폭",
|
|
51
|
-
modify = "개조",
|
|
52
|
-
}
|
|
1
|
+
export enum server {
|
|
2
|
+
Cain = "cain",
|
|
3
|
+
Diregie = "diregie",
|
|
4
|
+
Siroco = "siroco",
|
|
5
|
+
Prey = "prey",
|
|
6
|
+
Casillas = "casillas",
|
|
7
|
+
Hilder = "hilder",
|
|
8
|
+
Anton = "anton",
|
|
9
|
+
Bakal = "bakal",
|
|
10
|
+
}
|
|
11
|
+
export enum sort {
|
|
12
|
+
Asc = "asc",
|
|
13
|
+
Desc = "desc",
|
|
14
|
+
}
|
|
15
|
+
export enum rarity {
|
|
16
|
+
Common = "커먼",
|
|
17
|
+
Uncommon = "언커먼",
|
|
18
|
+
Rare = "레어",
|
|
19
|
+
Unique = "유니크",
|
|
20
|
+
Eqic = "에픽",
|
|
21
|
+
Chronicle = "크로니클",
|
|
22
|
+
Legendary = "레전더리",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export enum auctionWordType {
|
|
26
|
+
Match = "match",
|
|
27
|
+
Front = "front",
|
|
28
|
+
Full = "full",
|
|
29
|
+
}
|
|
30
|
+
export enum wordType {
|
|
31
|
+
Match = "match",
|
|
32
|
+
Front = "front",
|
|
33
|
+
Full = "full",
|
|
34
|
+
}
|
|
35
|
+
export enum charactersWordType {
|
|
36
|
+
Match = "match",
|
|
37
|
+
Full = "full",
|
|
38
|
+
}
|
|
39
|
+
export enum baseUri {
|
|
40
|
+
Servers = "df/servers",
|
|
41
|
+
Auction = "df/auction",
|
|
42
|
+
AuctionSold = "df/auction-sold",
|
|
43
|
+
Item = "df/items",
|
|
44
|
+
SetItem = "df/setitems",
|
|
45
|
+
Multi = "df/multi",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export enum reinforceType {
|
|
49
|
+
reinforce = "강화",
|
|
50
|
+
minRefine = "증폭",
|
|
51
|
+
modify = "개조",
|
|
52
|
+
}
|