Spaces:
Configuration error
Configuration error
Update index.html
Browse files- index.html +32 -9
index.html
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>
|
7 |
<style>
|
8 |
body {
|
9 |
font-family: Arial, sans-serif;
|
@@ -24,24 +24,47 @@
|
|
24 |
</head>
|
25 |
<body>
|
26 |
<div class="container">
|
27 |
-
<h1>
|
28 |
<form id="dataForm">
|
29 |
-
<label for="
|
30 |
-
<input type="text" id="userId" name="user_id" required>
|
31 |
-
|
32 |
-
<label for="title">Title:</label>
|
33 |
<input type="text" id="title" name="title" required>
|
34 |
|
35 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
</form>
|
37 |
<p id="responseMessage"></p>
|
38 |
</div>
|
39 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
document.getElementById('dataForm').addEventListener('submit', async (e) => {
|
41 |
e.preventDefault();
|
42 |
|
43 |
-
const userId =
|
|
|
|
|
|
|
|
|
|
|
44 |
const title = document.getElementById('title').value;
|
|
|
|
|
45 |
const apiUrl = 'https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/users'; // API Gateway URL'nizi buraya koyun
|
46 |
|
47 |
try {
|
@@ -50,7 +73,7 @@
|
|
50 |
headers: {
|
51 |
'Content-Type': 'application/json'
|
52 |
},
|
53 |
-
body: JSON.stringify({ user_id: userId, title: title })
|
54 |
});
|
55 |
|
56 |
const result = await response.json();
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Makale Chatbot</title>
|
7 |
<style>
|
8 |
body {
|
9 |
font-family: Arial, sans-serif;
|
|
|
24 |
</head>
|
25 |
<body>
|
26 |
<div class="container">
|
27 |
+
<h1>Bilgileri Doldurunuz!</h1>
|
28 |
<form id="dataForm">
|
29 |
+
<label for="title">Başlık:</label>
|
|
|
|
|
|
|
30 |
<input type="text" id="title" name="title" required>
|
31 |
|
32 |
+
<label for="text">Metin:</label>
|
33 |
+
<textarea id="text" name="text" rows="4" required></textarea>
|
34 |
+
|
35 |
+
<label for="keywords">Anahtar Kelimeler:</label>
|
36 |
+
<input type="text" id="keywords" name="keywords" required>
|
37 |
+
|
38 |
+
<button type="submit">Sonuç</button>
|
39 |
</form>
|
40 |
<p id="responseMessage"></p>
|
41 |
</div>
|
42 |
<script>
|
43 |
+
// Kullanıcı ID'sini almak için GET isteği
|
44 |
+
async function getUserId() {
|
45 |
+
const apiUrl = 'https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/user'; // Kullanıcı ID'si almak için API Gateway URL'nizi buraya koyun
|
46 |
+
try {
|
47 |
+
const response = await fetch(apiUrl);
|
48 |
+
const result = await response.json();
|
49 |
+
return result.user_id; // API'nin döndürdüğü kullanıcı ID'sini döndürün
|
50 |
+
} catch (error) {
|
51 |
+
console.error('Error fetching user ID:', error);
|
52 |
+
return null;
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
document.getElementById('dataForm').addEventListener('submit', async (e) => {
|
57 |
e.preventDefault();
|
58 |
|
59 |
+
const userId = await getUserId();
|
60 |
+
if (!userId) {
|
61 |
+
document.getElementById('responseMessage').textContent = 'Unable to get user ID.';
|
62 |
+
return;
|
63 |
+
}
|
64 |
+
|
65 |
const title = document.getElementById('title').value;
|
66 |
+
const text = document.getElementById('text').value;
|
67 |
+
const keywords = document.getElementById('keywords').value;
|
68 |
const apiUrl = 'https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/users'; // API Gateway URL'nizi buraya koyun
|
69 |
|
70 |
try {
|
|
|
73 |
headers: {
|
74 |
'Content-Type': 'application/json'
|
75 |
},
|
76 |
+
body: JSON.stringify({ user_id: userId, title: title, text: text, keywords: keywords })
|
77 |
});
|
78 |
|
79 |
const result = await response.json();
|