Repository navigation
Expand file tree
/
Copy pathactionsProxy.ts
More file actions
212 lines (196 loc) · 7.45 KB
/
Copy pathactionsProxy.ts
File metadata and controls
212 lines (196 loc) · 7.45 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
* OpenAI Actions용 공통 GET 프록시 정의
*/
export interface ActionQueryDefinition {
action: string;
summary: string;
targetPath: string;
pathParam?: string;
}
export const ACTION_QUERY_DEFINITIONS: ActionQueryDefinition[] = [
{ action: 'dtryxListCinemas', summary: '디트릭스 극장 목록', targetPath: '/api/dtryx/cinemas' },
{ action: 'dtryxListNowShowing', summary: '디트릭스 상영작', targetPath: '/api/dtryx/movies' },
{ action: 'dtryxGetRemainingSeats', summary: '디트릭스 잔여 좌석', targetPath: '/api/dtryx/seats' },
{ action: 'daisoSearchProducts', summary: '다이소 제품 검색', targetPath: '/api/daiso/products' },
{
action: 'daisoGetProduct',
summary: '다이소 제품 상세 조회',
targetPath: '/api/daiso/products/:productId',
pathParam: 'productId',
},
{ action: 'daisoFindStores', summary: '다이소 매장 검색', targetPath: '/api/daiso/stores' },
{ action: 'daisoJpSearchProducts', summary: '일본 다이소 상품 검색', targetPath: '/api/daiso-jp/products' },
{ action: 'daisoJpGetProduct', summary: '일본 다이소 상품 상세', targetPath: '/api/daiso-jp/products/:productId', pathParam: 'productId' },
{ action: 'daisoJpFindStores', summary: '일본 다이소 매장 검색 (매장 재고 미지원)', targetPath: '/api/daiso-jp/stores' },
{ action: 'opinetGetAveragePrices', summary: '오피넷 전국 평균 유가', targetPath: '/api/opinet/average' },
{ action: 'opinetGetLowestPriceStations', summary: '오피넷 최저가 주유소', targetPath: '/api/opinet/lowest' },
{ action: 'opinetSearchStationsAround', summary: '오피넷 주변 주유소', targetPath: '/api/opinet/stations/around' },
{ action: 'opinetGetStationDetail', summary: '오피넷 주유소 상세', targetPath: '/api/opinet/station' },
{
action: 'daisoCheckInventory',
summary: '다이소 재고 조회',
targetPath: '/api/daiso/inventory',
},
{
action: 'daisoGetDisplayLocation',
summary: '다이소 진열 위치 조회',
targetPath: '/api/daiso/display-location',
},
{
action: 'oliveyoungSearchProducts',
summary: '올리브영 상품 검색',
targetPath: '/api/oliveyoung/products',
},
{
action: 'oliveyoungFindStores',
summary: '올리브영 매장 검색',
targetPath: '/api/oliveyoung/stores',
},
{
action: 'oliveyoungCheckInventory',
summary: '올리브영 재고 조회',
targetPath: '/api/oliveyoung/inventory',
},
{
action: 'oliveyoungGetTodayDeals',
summary: '올리브영 오특(오늘의 특가) 조회',
targetPath: '/api/oliveyoung/today-deals',
},
{ action: 'cuFindStores', summary: 'CU 매장 검색', targetPath: '/api/cu/stores' },
{ action: 'cuCheckInventory', summary: 'CU 재고 조회', targetPath: '/api/cu/inventory' },
{ action: 'emart24FindStores', summary: '이마트24 매장 검색', targetPath: '/api/emart24/stores' },
{
action: 'emart24SearchProducts',
summary: '이마트24 상품 검색',
targetPath: '/api/emart24/products',
},
{
action: 'emart24CheckInventory',
summary: '이마트24 재고 조회',
targetPath: '/api/emart24/inventory',
},
{ action: 'gs25FindStores', summary: 'GS25 매장 검색', targetPath: '/api/gs25/stores' },
{ action: 'gs25SearchProducts', summary: 'GS25 상품 검색', targetPath: '/api/gs25/products' },
{ action: 'gs25CheckInventory', summary: 'GS25 재고 조회', targetPath: '/api/gs25/inventory' },
{
action: 'sevenelevenSearchProducts',
summary: '세븐일레븐 상품 검색',
targetPath: '/api/seveneleven/products',
},
{
action: 'sevenelevenSearchStores',
summary: '세븐일레븐 매장 검색',
targetPath: '/api/seveneleven/stores',
},
{
action: 'sevenelevenCheckInventory',
summary: '세븐일레븐 재고 조회',
targetPath: '/api/seveneleven/inventory',
},
{
action: 'sevenelevenGetPopwords',
summary: '세븐일레븐 인기 검색어 조회',
targetPath: '/api/seveneleven/popwords',
},
{
action: 'sevenelevenGetCatalog',
summary: '세븐일레븐 카탈로그 조회',
targetPath: '/api/seveneleven/catalog',
},
{
action: 'compareProducts',
summary: '키 없는 통합 상품 가격 후보 비교',
targetPath: '/api/compare/products',
},
{
action: 'placesSearchNearby',
summary: '음식점/카페 등 주변 장소 검색',
targetPath: '/api/places/search',
},
{
action: 'submitDeveloperRequest',
summary: '개발자 요청 제출',
targetPath: '/api/feedback/requests',
},
{
action: 'megaboxFindTheaters',
summary: '메가박스 지점 검색',
targetPath: '/api/megabox/theaters',
},
{
action: 'megaboxListMovies',
summary: '메가박스 영화 목록 조회',
targetPath: '/api/megabox/movies',
},
{
action: 'megaboxGetSeats',
summary: '메가박스 잔여 좌석 조회',
targetPath: '/api/megabox/seats',
},
{
action: 'lottecinemaFindTheaters',
summary: '롯데시네마 지점 검색',
targetPath: '/api/lottecinema/theaters',
},
{
action: 'lottecinemaListMovies',
summary: '롯데시네마 영화 목록 조회',
targetPath: '/api/lottecinema/movies',
},
{
action: 'lottecinemaGetSeats',
summary: '롯데시네마 잔여 좌석 조회',
targetPath: '/api/lottecinema/seats',
},
{ action: 'cgvFindTheaters', summary: 'CGV 극장 검색', targetPath: '/api/cgv/theaters' },
{ action: 'cgvSearchMovies', summary: 'CGV 영화 목록 조회', targetPath: '/api/cgv/movies' },
{ action: 'cgvGetTimetable', summary: 'CGV 시간표 조회', targetPath: '/api/cgv/timetable' },
] as const;
const ACTION_QUERY_MAP = new Map(
ACTION_QUERY_DEFINITIONS.map((definition) => [definition.action, definition]),
);
export const ACTION_QUERY_ACTIONS = ACTION_QUERY_DEFINITIONS.map((definition) => definition.action);
function toAbsoluteUrl(value: string): URL {
try {
return new URL(value);
} catch {
return new URL(value, 'https://actions-proxy.local');
}
}
export function getActionQueryDefinition(action: string): ActionQueryDefinition | undefined {
return ACTION_QUERY_MAP.get(action);
}
export function buildActionQueryTargetUrl(requestUrl: string): URL {
const sourceUrl = toAbsoluteUrl(requestUrl);
const action = (sourceUrl.searchParams.get('action') || '').trim();
if (action.length === 0) {
throw new Error('action 파라미터를 입력해주세요.');
}
const definition = getActionQueryDefinition(action);
if (!definition) {
throw new Error(`지원하지 않는 action 입니다: ${action}`);
}
let pathname = definition.targetPath;
const consumedParams = new Set(['action']);
if (definition.pathParam) {
const pathValue = (sourceUrl.searchParams.get(definition.pathParam) || '').trim();
if (pathValue.length === 0) {
throw new Error(`${definition.pathParam} 파라미터를 입력해주세요.`);
}
pathname = pathname.replace(`:${definition.pathParam}`, encodeURIComponent(pathValue));
consumedParams.add(definition.pathParam);
}
const targetUrl = new URL(pathname, sourceUrl.origin);
for (const [key, value] of sourceUrl.searchParams.entries()) {
if (consumedParams.has(key)) {
continue;
}
targetUrl.searchParams.append(key, value);
}
return targetUrl;
}
export function createActionQueryDescriptionList(): string {
return ACTION_QUERY_DEFINITIONS.map(
(definition) => `- \`${definition.action}\`: ${definition.summary}`,
).join('\n');
}