first commit

This commit is contained in:
2025-07-15 13:25:34 +03:00
commit d30d065f44
8 changed files with 1505 additions and 0 deletions

668
templates/index.html Normal file
View File

@@ -0,0 +1,668 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>QR Code Manager</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 15px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.header p {
font-size: 1.1em;
opacity: 0.9;
}
.main-content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
padding: 30px;
}
.form-section {
background: #f8f9fa;
padding: 25px;
border-radius: 10px;
border: 1px solid #e9ecef;
}
.form-section h2 {
color: #333;
margin-bottom: 20px;
font-size: 1.5em;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #555;
}
.form-group input,
.form-group select,
.form-group textarea {
width: 100%;
padding: 12px;
border: 2px solid #e9ecef;
border-radius: 8px;
font-size: 14px;
transition: border-color 0.3s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
outline: none;
border-color: #667eea;
}
.form-group textarea {
height: 100px;
resize: vertical;
}
.color-inputs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
}
.color-input-group {
display: flex;
align-items: center;
gap: 10px;
}
.color-input-group input[type="color"] {
width: 50px;
height: 40px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.style-selector {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
.style-option {
padding: 10px;
border: 2px solid #e9ecef;
border-radius: 8px;
text-align: center;
cursor: pointer;
transition: all 0.3s;
background: white;
}
.style-option:hover {
border-color: #667eea;
}
.style-option.active {
border-color: #667eea;
background: #667eea;
color: white;
}
.wifi-fields,
.email-fields,
.sms-fields,
.vcard-fields {
display: none;
}
.wifi-fields.active,
.email-fields.active,
.sms-fields.active,
.vcard-fields.active {
display: block;
}
.btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 12px 30px;
border: none;
border-radius: 8px;
font-size: 16px;
cursor: pointer;
transition: transform 0.2s;
width: 100%;
margin-top: 10px;
}
.btn:hover {
transform: translateY(-2px);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.result-section {
text-align: center;
}
.qr-preview {
background: white;
border: 2px dashed #ddd;
border-radius: 10px;
padding: 30px;
margin-bottom: 20px;
min-height: 300px;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.qr-preview img {
max-width: 100%;
max-height: 250px;
border-radius: 5px;
}
.qr-preview .placeholder {
color: #999;
font-size: 1.1em;
}
.download-section {
display: none;
gap: 10px;
}
.download-section.active {
display: flex;
}
.btn-secondary {
background: #6c757d;
flex: 1;
}
.btn-primary {
background: #28a745;
flex: 1;
}
.qr-history {
margin-top: 30px;
padding: 25px;
background: #f8f9fa;
border-radius: 10px;
border: 1px solid #e9ecef;
}
.qr-history h3 {
margin-bottom: 20px;
color: #333;
}
.qr-item {
display: flex;
align-items: center;
gap: 15px;
padding: 15px;
background: white;
border-radius: 8px;
margin-bottom: 10px;
border: 1px solid #e9ecef;
}
.qr-item img {
width: 50px;
height: 50px;
border-radius: 5px;
}
.qr-item-info {
flex: 1;
}
.qr-item-info h4 {
color: #333;
margin-bottom: 5px;
}
.qr-item-info p {
color: #666;
font-size: 0.9em;
}
.qr-item-actions {
display: flex;
gap: 10px;
}
.btn-small {
padding: 5px 15px;
font-size: 12px;
border-radius: 5px;
}
@media (max-width: 768px) {
.main-content {
grid-template-columns: 1fr;
}
.color-inputs {
grid-template-columns: 1fr;
}
.style-selector {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🎯 QR Code Manager</h1>
<p>Create, customize, and manage your QR codes with ease</p>
</div>
<div class="main-content">
<div class="form-section">
<h2>Generate QR Code</h2>
<div class="form-group">
<label for="qr-type">QR Code Type</label>
<select id="qr-type" onchange="toggleFields()">
<option value="text">Text</option>
<option value="url">URL/Website</option>
<option value="wifi">WiFi</option>
<option value="email">Email</option>
<option value="phone">Phone</option>
<option value="sms">SMS</option>
<option value="vcard">Contact Card</option>
</select>
</div>
<!-- Text/URL content -->
<div class="form-group" id="text-field">
<label for="content">Content</label>
<textarea id="content" placeholder="Enter your text or URL..."></textarea>
</div>
<!-- WiFi fields -->
<div class="wifi-fields" id="wifi-fields">
<div class="form-group">
<label for="wifi-ssid">Network Name (SSID)</label>
<input type="text" id="wifi-ssid" placeholder="My WiFi Network">
</div>
<div class="form-group">
<label for="wifi-password">Password</label>
<input type="password" id="wifi-password" placeholder="WiFi Password">
</div>
<div class="form-group">
<label for="wifi-security">Security Type</label>
<select id="wifi-security">
<option value="WPA">WPA/WPA2</option>
<option value="WEP">WEP</option>
<option value="nopass">No Password</option>
</select>
</div>
</div>
<!-- Email fields -->
<div class="email-fields" id="email-fields">
<div class="form-group">
<label for="email-address">Email Address</label>
<input type="email" id="email-address" placeholder="contact@example.com">
</div>
<div class="form-group">
<label for="email-subject">Subject</label>
<input type="text" id="email-subject" placeholder="Email subject">
</div>
<div class="form-group">
<label for="email-body">Message</label>
<textarea id="email-body" placeholder="Email message..."></textarea>
</div>
</div>
<!-- SMS fields -->
<div class="sms-fields" id="sms-fields">
<div class="form-group">
<label for="sms-phone">Phone Number</label>
<input type="tel" id="sms-phone" placeholder="+1234567890">
</div>
<div class="form-group">
<label for="sms-message">Message</label>
<textarea id="sms-message" placeholder="SMS message..."></textarea>
</div>
</div>
<!-- vCard fields -->
<div class="vcard-fields" id="vcard-fields">
<div class="form-group">
<label for="vcard-name">Full Name</label>
<input type="text" id="vcard-name" placeholder="John Doe">
</div>
<div class="form-group">
<label for="vcard-organization">Organization</label>
<input type="text" id="vcard-organization" placeholder="Company Name">
</div>
<div class="form-group">
<label for="vcard-phone">Phone</label>
<input type="tel" id="vcard-phone" placeholder="+1234567890">
</div>
<div class="form-group">
<label for="vcard-email">Email</label>
<input type="email" id="vcard-email" placeholder="john@example.com">
</div>
<div class="form-group">
<label for="vcard-website">Website</label>
<input type="url" id="vcard-website" placeholder="https://example.com">
</div>
</div>
<h3 style="margin: 25px 0 15px 0; color: #333;">Customization</h3>
<div class="form-group">
<label>Colors</label>
<div class="color-inputs">
<div class="color-input-group">
<input type="color" id="foreground-color" value="#000000">
<span>Foreground</span>
</div>
<div class="color-input-group">
<input type="color" id="background-color" value="#FFFFFF">
<span>Background</span>
</div>
</div>
</div>
<div class="form-group">
<label>Style</label>
<div class="style-selector">
<div class="style-option active" data-style="square">
<div></div>
<div>Square</div>
</div>
<div class="style-option" data-style="rounded">
<div></div>
<div>Rounded</div>
</div>
<div class="style-option" data-style="circle">
<div></div>
<div>Circle</div>
</div>
</div>
</div>
<div class="form-group">
<label for="size">Size</label>
<input type="range" id="size" min="5" max="15" value="10" oninput="updateSizeLabel()">
<small id="size-label">10px per module</small>
</div>
<button class="btn" onclick="generateQR()">Generate QR Code</button>
</div>
<div class="result-section">
<h2>Preview</h2>
<div class="qr-preview" id="qr-preview">
<div class="placeholder">
<div style="font-size: 3em; margin-bottom: 10px;">📱</div>
<div>Your QR code will appear here</div>
</div>
</div>
<div class="download-section" id="download-section">
<button class="btn btn-primary" onclick="downloadQR()">Download PNG</button>
<button class="btn btn-secondary" onclick="copyToClipboard()">Copy Image</button>
</div>
</div>
</div>
<div class="qr-history">
<h3>Recent QR Codes</h3>
<div id="qr-history-list">
<p style="color: #666; text-align: center;">No QR codes generated yet</p>
</div>
</div>
</div>
<script>
let currentQRId = null;
let currentQRData = null;
function toggleFields() {
const type = document.getElementById('qr-type').value;
// Hide all specific fields
document.getElementById('text-field').style.display = 'none';
document.querySelectorAll('.wifi-fields, .email-fields, .sms-fields, .vcard-fields').forEach(el => {
el.classList.remove('active');
});
// Show relevant fields
if (type === 'text' || type === 'url' || type === 'phone') {
document.getElementById('text-field').style.display = 'block';
const contentField = document.getElementById('content');
if (type === 'url') {
contentField.placeholder = 'https://example.com';
} else if (type === 'phone') {
contentField.placeholder = '+1234567890';
} else {
contentField.placeholder = 'Enter your text...';
}
} else {
document.getElementById(`${type}-fields`).classList.add('active');
}
}
function updateSizeLabel() {
const size = document.getElementById('size').value;
document.getElementById('size-label').textContent = `${size}px per module`;
}
// Style selector
document.querySelectorAll('.style-option').forEach(option => {
option.addEventListener('click', function() {
document.querySelectorAll('.style-option').forEach(opt => opt.classList.remove('active'));
this.classList.add('active');
});
});
async function generateQR() {
const type = document.getElementById('qr-type').value;
let content = '';
let additionalData = {};
// Get content based on type
if (type === 'text' || type === 'url' || type === 'phone') {
content = document.getElementById('content').value;
} else if (type === 'wifi') {
additionalData.wifi = {
ssid: document.getElementById('wifi-ssid').value,
password: document.getElementById('wifi-password').value,
security: document.getElementById('wifi-security').value
};
} else if (type === 'email') {
additionalData.email = {
email: document.getElementById('email-address').value,
subject: document.getElementById('email-subject').value,
body: document.getElementById('email-body').value
};
} else if (type === 'sms') {
additionalData.sms = {
phone: document.getElementById('sms-phone').value,
message: document.getElementById('sms-message').value
};
} else if (type === 'vcard') {
additionalData.vcard = {
name: document.getElementById('vcard-name').value,
organization: document.getElementById('vcard-organization').value,
phone: document.getElementById('vcard-phone').value,
email: document.getElementById('vcard-email').value,
website: document.getElementById('vcard-website').value
};
}
const requestData = {
type: type,
content: content,
...additionalData,
size: parseInt(document.getElementById('size').value),
foreground_color: document.getElementById('foreground-color').value,
background_color: document.getElementById('background-color').value,
style: document.querySelector('.style-option.active').dataset.style
};
try {
const response = await fetch('/api/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
});
const result = await response.json();
if (result.success) {
currentQRId = result.qr_id;
currentQRData = result.image_data;
// Show QR code
const preview = document.getElementById('qr-preview');
preview.innerHTML = `<img src="${result.image_data}" alt="Generated QR Code">`;
// Show download buttons
document.getElementById('download-section').classList.add('active');
// Refresh history
loadQRHistory();
} else {
alert('Error generating QR code: ' + result.error);
}
} catch (error) {
alert('Error: ' + error.message);
}
}
async function downloadQR() {
if (currentQRId) {
window.open(`/api/download/${currentQRId}`, '_blank');
}
}
async function copyToClipboard() {
if (currentQRData) {
try {
const response = await fetch(currentQRData);
const blob = await response.blob();
await navigator.clipboard.write([
new ClipboardItem({ [blob.type]: blob })
]);
alert('QR code copied to clipboard!');
} catch (error) {
alert('Failed to copy to clipboard');
}
}
}
async function loadQRHistory() {
try {
const response = await fetch('/api/qr_codes');
const qrCodes = await response.json();
const historyList = document.getElementById('qr-history-list');
if (qrCodes.length === 0) {
historyList.innerHTML = '<p style="color: #666; text-align: center;">No QR codes generated yet</p>';
return;
}
historyList.innerHTML = qrCodes.map(qr => `
<div class="qr-item">
<img src="${qr.preview}" alt="QR Code">
<div class="qr-item-info">
<h4>${qr.type.toUpperCase()}</h4>
<p>Created: ${new Date(qr.created_at).toLocaleDateString()}</p>
</div>
<div class="qr-item-actions">
<button class="btn btn-small btn-primary" onclick="downloadQRById('${qr.id}')">Download</button>
<button class="btn btn-small btn-secondary" onclick="deleteQR('${qr.id}')">Delete</button>
</div>
</div>
`).join('');
} catch (error) {
console.error('Failed to load QR history:', error);
}
}
async function downloadQRById(qrId) {
window.open(`/api/download/${qrId}`, '_blank');
}
async function deleteQR(qrId) {
if (confirm('Are you sure you want to delete this QR code?')) {
try {
const response = await fetch(`/api/qr_codes/${qrId}`, {
method: 'DELETE'
});
if (response.ok) {
loadQRHistory();
} else {
alert('Failed to delete QR code');
}
} catch (error) {
alert('Error deleting QR code: ' + error.message);
}
}
}
// Load history on page load
document.addEventListener('DOMContentLoaded', function() {
loadQRHistory();
});
</script>
</body>
</html>