-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
373 lines (305 loc) · 16.5 KB
/
index.html
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<!DOCTYPE html>
<html lang="pt-br">
<head class="animation">
<!-- Primary Meta Tags -->
<link rel="shortcut icon" href="imgs/icon.png" type="image/x-icon">
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="theme-color" content="#f5f9fa">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- APP MOBILE -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<!-- META TAGS GERAL -->
<title>dyAPI Test</title>
<meta name="title" content="dyAPI Test">
<meta name="description" content="FERRAMENTA, PARA TESTAR E DOCUMENTAR APIs ☕">
<meta name="keywords" content="dyAPI Test, dypier, teste, api, json, editor, json editor">
<meta name="robots" content="index, follow">
<meta name="language" content="Portuguese">
<meta name="author" content="dyAPI Test">
<meta name="thumbnail" content="https://dyapitest.vercel.app/.github/preview.png">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://dyapitest.vercel.app/">
<meta property="og:title" content="dyAPI Test">
<meta property="og:description" content="FERRAMENTA, PARA TESTAR E DOCUMENTAR APIs ☕">
<meta property="og:image" content="https://dyapitest.vercel.app/.github/preview.png">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://dyapitest.vercel.app/">
<meta property="twitter:title" content="dyAPI Test">
<meta property="twitter:description" content="FERRAMENTA, PARA TESTAR E DOCUMENTAR APIs ☕">
<meta property="twitter:image" content="https://dyapitest.vercel.app/.github/preview.png">
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-BNH8X40C6H"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-BNH8X40C6H');
</script>
<!-- Hotjar Tracking Code for https://dyapitest.vercel.app/ -->
<script>
(function (h, o, t, j, a, r) {
h.hj = h.hj || function () { (h.hj.q = h.hj.q || []).push(arguments) };
h._hjSettings = { hjid: 3593495, hjsv: 6 };
a = o.getElementsByTagName('head')[0];
r = o.createElement('script'); r.async = 1;
r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
a.appendChild(r);
})(window, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=');
</script>
<!-- LOCAL -->
<link rel="icon" type="image/x-icon" href="imgs/icon.png">
<link id="styleTema" rel="stylesheet" href="css/light.css">
<link id="styleHighlight" href="highlight/styles/base16/google-light.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/index.css">
<script src="js/cookies.js"></script>
<script src="js/formatadorJSON.js"></script>
<script src="js/geradorCodigo.js"></script>
<script src="js/sistemaLinks.js"></script>
<script src="js/style.js"></script>
<script src="js/statusCode.js"></script>
<script src="js/modals.js"></script>
<script src="js/submit.js"></script>
<!-- REACT UNPKG -->
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- ALERTA MODAL -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- COMPRESSOR -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/libs/lz-string.min.js"></script>
<!-- CODE -->
<script src="highlight/highlight.min.js"></script>
</head>
<body class="col center animation">
<header class="row center" style="justify-content: space-between;">
<span style="width: 100px; margin: 10px"></span>
<nav class="center logo">
<img src="imgs/icon.png" width="24px" height="24px" />
<h1 style="font-style: italic; font-weight: 24px; color: var(--font-color-logo);">dyAPITest</h1>
</nav>
<select style="width: 100px; margin: 10px;" id="select-tema" onchange="handleSelectionTemaChange()"></select>
<script>optionsSelectTema();</script>
</header>
<section>
<div id="root"></div>
</section>
<script type="text/babel">
const { useState, useEffect, useRef } = React;
function App(props) {
const [url, setUrl] = useState(null);
const [method, setMethod] = useState('GET');
const [headers, setHeaders] = useState('{ "Content-Type": "application/json" }');
const [mode, setMode] = useState(null);
const [body, setBody] = useState(null);
const [arquivo, setArquivo] = useState({ titulo: null, arquivo: null });
const [consoleLog, setConsoleLog] = useState(null);
const [codigo, setCodigo] = useState(null);
const [linguagemCodigo, setLinguagemCodigo] = useState('javascript');
const [selectCodigo, setSelectCodigo] = useState(tagAbrirExemploCodigo);
const [statusCode, setStatusCode] = useState(0);
useEffect(() => {
let dadosDoLink = lerLink();
try {
if (dadosDoLink !== null) {
setMethod(dadosDoLink?.method);
setHeaders(JSON.stringify(JSON.parse(dadosDoLink?.headers), null, 2) || dadosDoLink?.headers);
setMode(dadosDoLink?.mode);
setUrl(dadosDoLink?.url);
setBody(JSON.stringify(JSON.parse(dadosDoLink?.body), null, 2) || dadosDoLink?.body);
setStatusCode(dadosDoLink?.statusCode);
try {
setConsoleLog(JSON.stringify(JSON.parse(dadosDoLink?.consoleLog, null, 2)));
} catch (error) {
setConsoleLog(dadosDoLink?.consoleLog);
}
dadosDoLink = null;
}
} catch (error) {
console.log(error);
}
document.onkeydown = handleKeyDown;
// onKeyDown={handleKeyDown}
}, []);
const handleInputChange = (event) => {
const { name, value, files } = event.target;
switch (name) {
case 'url':
setUrl(value);
break;
case 'method':
setMethod(value);
break;
case 'headers':
setHeaders(value);
break;
case 'mode':
setMode(value);
break;
case 'body':
setBody(value);
break;
case 'arquivoTitulo':
setArquivo({ titulo: value, arquivo: arquivo?.arquivo });
break;
case 'arquivo':
setArquivo({ titulo: arquivo?.titulo, arquivo: files[0] });
break;
default:
break;
}
};
const handleSubmit = async () => {
if (url !== '' && url !== null) {
const dados = { url, method, headers, mode, body, arquivo }
const log = await submit(dados);
setStatusCode(log?.status);
let text = await log;
try {
text = await log?.text();
} catch (error) { }
try {
setConsoleLog(JSON.stringify(JSON.parse(text), null, 2));
} catch (error) {
setConsoleLog(text);
}
} else {
modalErro(mensagens.erroSemURL)
}
};
const submitButtonRef = useRef(null);
const handleKeyDown = (event) => {
if (event.key === 'Enter' && event.ctrlKey) {
console.log('oi');
event.preventDefault();
submitButtonRef.current.focus();
// submitButtonRef.current.click();
}
};
const handleCompartilhar = async () => {
if (url !== '' && url !== null) {
let newConsoleLog = consoleLog;
try {
newConsoleLog = JSON.stringify(JSON.parse(consoleLog));
} catch (error) { }
const dados = {
url,
method,
headers: JSON.stringify(JSON.parse(headers)),
mode,
body: JSON.stringify(JSON.parse(body)),
consoleLog: newConsoleLog,
statusCode,
}
gerarLink(dados);
} else {
modalErro(mensagens.erroSemURL)
}
}
const handleGerarCodigoExemplo = () => {
const codigo = gerarCodigoExemplo(selectCodigo, {
url,
method,
headers: JSON.stringify(JSON.parse(headers)),
mode,
body: JSON.stringify(JSON.parse(body)),
});
if (codigo?.linguagem !== undefined) {
let html = hljs.highlight(codigo?.codigo, { language: codigo?.linguagem }).value;
setLinguagemCodigo(codigo?.linguagem);
setCodigo(html);
}
}
const handlePainelCodigoExemplo = () => {
if (selectCodigo !== tagAbrirExemploCodigo && selectCodigo !== 'null') handleGerarCodigoExemplo();
}
const handleOnBlurConsole = () => {
try {
setConsoleLog(JSON.stringify(JSON.parse(consoleLog), null, 2))
} catch (error) { }
}
return (
<div className="row center animation"
style={{ gap: 15 + 'px', alignItems: 'flex-start' }}>
<form className="col center animation" style={{ gap: 15 + 'px' }}>
<span className="row" style={{ gap: 0 + 'px', width: 454 + 'px' }}>
<select value={method} name="method"
style={{ width: 'auto', flexGrow: 0, borderRadius: '6px 0px 0px 6px' }}
onChange={handleInputChange}
title="Selecione o 'Method' de transmissão da API">
<option>GET</option>
<option>POST</option>
<option>PUT</option>
<option>DELETE</option>
{/* <option>OPTIONS</option> */}
{/* <option>HEAD</option> */}
</select>
<input placeholder="URL"
type="text"
name="url"
value={url}
onChange={handleInputChange}
title="Link da API"
style={{ width: 'auto', flexGrow: 4, borderRadius: '0px' }} />
<button type="button" onClick={handleSubmit} ref={submitButtonRef} onFocus={() => console.log('oi')}
className={"animation botao"} style={{ width: 'auto', flexGrow: 0, borderRadius: '0px 6px 6px 0px' }}
title="Enviar API">submit</button>
</span>
{/*<input placeholder="mode" type="text" name="mode" value={mode} style={{ width: 450 + 'px' }} onChange={handleInputChange} /> */}
<span className="col" style={{ gap: 10 + 'px' }}>
<textarea placeholder="headers" value={headers} name="headers" onChange={handleInputChange} title={`Headers:`}
onBlur={() => { setHeaders(JSON.stringify(formatarJson(headers), null, 2)) }} />
<textarea placeholder="body" value={body} name="body" onChange={handleInputChange} title={`Body:`}
onBlur={() => { setBody(JSON.stringify(formatarJson(body), null, 2)) }} />
<span className="row" style={{ gap: 0 + 'px', width: 454 + 'px' }}>
<input placeholder="nome do arquivo" type="text" name="arquivoTitulo"
style={{ width: 'auto', flexGrow: 0, borderRadius: '6px 0px 0px 6px' }}
value={arquivo?.titulo} onChange={handleInputChange} title="Nome de entrada do arquivo" />
<input type="file" name="arquivo" onChange={handleInputChange}
style={{ width: 'auto', flexGrow: 4, borderRadius: '0px 6px 6px 0px' }} />
</span>
</span>
<span className="row" style={{ justifyContent: 'space-between', gap: 10 + 'px', width: 454 + 'px', padding: 0 }}>
<button type="button" onClick={handleCompartilhar} className={"animation botao"} style={{ width: 'auto', flexGrow: 1 }}
title="Gerar um link com todos os dados para compartilhar">Compartilhar Link</button>
</span>
</form>
<section className="col" style={{ gap: 10 + 'px' }}>
{statusCode !== 0 &&
<p className={`status_${statusCodeParaTexto(statusCode)?.ok} `}>{statusCode || ' -'} {statusCodeParaTexto(statusCode)?.msg}</p>
}
<textarea placeholder="Console:" value={consoleLog} readonly title={`Resultados do console:`}
onBlur={handleOnBlurConsole} />
<span>
<select style={{ width: 454 + 'px', textTransform: 'Capitalize' }} onChange={(e) => setSelectCodigo(e.target.value)}
onClick={handlePainelCodigoExemplo} title={`Abra um campo com exemplo de como\nprogramar essa API, na linguagem escolhida`}>
{Object.keys(codigoExemploTags).map((key) => (<option key={key} value={key}>{codigoExemploTags[key]}</option>))}
</select>
<pre className="codeView" title={`Código exemplo, na linguagem ${linguagemCodigo}\nEsse modelo de código, pode conter falhas`}
style={{
display: selectCodigo !== tagAbrirExemploCodigo && selectCodigo !== 'null' ? 'flex' : 'none',
borderRadius: '0px 0px 6px 6px', marginTop: '-6px'
}}
onMouseEnter={handlePainelCodigoExemplo}>
<code contenteditable="true" className={`language-${linguagemCodigo}`} dangerouslySetInnerHTML={{ __html: codigo }} />
</pre>
</span>
</section>
</div>
);
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
</script>
<BotaoVisitaGithub model="modelo3" link="https://github.com/LucasATS/dyApiTest"></BotaoVisitaGithub>
<script
src="https://cdn.jsdelivr.net/gh/LucasATS/BotaoVisitaGithub@5543a67f6227cb9bdb380625b51983b56a10c9ba/BotaoVisitaGithub.js"></script>
<footer class="footer">
<p style="background-color: var(--bg-color); border-radius: 6px; padding: 6px;">29230723-5v</p>
<p onclick="window.location.href = './sobre.html'"
style="cursor: pointer; background-color: var(--bg-color-logo); border-radius: 6px; padding: 6px;">sobre</p>
</footer>
</body>
</html>