Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- src/public/index.html +28 -0
- src/public/script.js +50 -0
- src/public/styles.css +58 -0
src/public/index.html
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Soundgasm Search</title>
|
| 7 |
+
<link rel="stylesheet" href="styles.css">
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<div class="container">
|
| 11 |
+
<h1>Soundgasm Search</h1>
|
| 12 |
+
|
| 13 |
+
<div class="search-container">
|
| 14 |
+
<input type="text" id="searchInput" placeholder="Search for audio...">
|
| 15 |
+
<button onclick="performSearch()">Search</button>
|
| 16 |
+
</div>
|
| 17 |
+
|
| 18 |
+
<div id="results" class="results-container"></div>
|
| 19 |
+
|
| 20 |
+
<div id="player" class="player-container">
|
| 21 |
+
<audio id="audioPlayer" controls style="display: none;">
|
| 22 |
+
Your browser does not support the audio element.
|
| 23 |
+
</audio>
|
| 24 |
+
</div>
|
| 25 |
+
</div>
|
| 26 |
+
<script src="script.js"></script>
|
| 27 |
+
</body>
|
| 28 |
+
</html>
|
src/public/script.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
async function performSearch() {
|
| 2 |
+
const searchInput = document.getElementById('searchInput');
|
| 3 |
+
const query = searchInput.value.trim();
|
| 4 |
+
|
| 5 |
+
if (!query) return;
|
| 6 |
+
|
| 7 |
+
try {
|
| 8 |
+
const response = await fetch(`/api/search?query=${encodeURIComponent(query)}`);
|
| 9 |
+
const results = await response.json();
|
| 10 |
+
displayResults(results);
|
| 11 |
+
} catch (error) {
|
| 12 |
+
console.error('Search failed:', error);
|
| 13 |
+
alert('Failed to perform search');
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
function displayResults(results) {
|
| 18 |
+
const resultsContainer = document.getElementById('results');
|
| 19 |
+
resultsContainer.innerHTML = '';
|
| 20 |
+
|
| 21 |
+
results.forEach(result => {
|
| 22 |
+
const resultElement = document.createElement('div');
|
| 23 |
+
resultElement.className = 'result-item';
|
| 24 |
+
resultElement.textContent = result.title;
|
| 25 |
+
resultElement.onclick = () => playAudio(result.id);
|
| 26 |
+
resultsContainer.appendChild(resultElement);
|
| 27 |
+
});
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
async function playAudio(id) {
|
| 31 |
+
try {
|
| 32 |
+
const response = await fetch(`/api/audio/${id}`);
|
| 33 |
+
const { audioUrl, title } = await response.json();
|
| 34 |
+
|
| 35 |
+
const audioPlayer = document.getElementById('audioPlayer');
|
| 36 |
+
audioPlayer.src = audioUrl;
|
| 37 |
+
audioPlayer.style.display = 'block';
|
| 38 |
+
audioPlayer.play();
|
| 39 |
+
} catch (error) {
|
| 40 |
+
console.error('Failed to play audio:', error);
|
| 41 |
+
alert('Failed to play audio');
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
// Add enter key support for search
|
| 46 |
+
document.getElementById('searchInput').addEventListener('keypress', (e) => {
|
| 47 |
+
if (e.key === 'Enter') {
|
| 48 |
+
performSearch();
|
| 49 |
+
}
|
| 50 |
+
});
|
src/public/styles.css
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.container {
|
| 2 |
+
max-width: 800px;
|
| 3 |
+
margin: 0 auto;
|
| 4 |
+
padding: 20px;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
.search-container {
|
| 8 |
+
display: flex;
|
| 9 |
+
gap: 10px;
|
| 10 |
+
margin-bottom: 20px;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
#searchInput {
|
| 14 |
+
flex-grow: 1;
|
| 15 |
+
padding: 10px;
|
| 16 |
+
font-size: 16px;
|
| 17 |
+
border: 1px solid #ccc;
|
| 18 |
+
border-radius: 4px;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
button {
|
| 22 |
+
padding: 10px 20px;
|
| 23 |
+
font-size: 16px;
|
| 24 |
+
background-color: #007bff;
|
| 25 |
+
color: white;
|
| 26 |
+
border: none;
|
| 27 |
+
border-radius: 4px;
|
| 28 |
+
cursor: pointer;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
button:hover {
|
| 32 |
+
background-color: #0056b3;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.results-container {
|
| 36 |
+
margin-top: 20px;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.result-item {
|
| 40 |
+
padding: 10px;
|
| 41 |
+
margin-bottom: 10px;
|
| 42 |
+
border: 1px solid #ccc;
|
| 43 |
+
border-radius: 4px;
|
| 44 |
+
cursor: pointer;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.result-item:hover {
|
| 48 |
+
background-color: #f0f0f0;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.player-container {
|
| 52 |
+
margin-top: 20px;
|
| 53 |
+
width: 100%;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
#audioPlayer {
|
| 57 |
+
width: 100%;
|
| 58 |
+
}
|