diff --git a/Makefile b/Makefile
index ff04c0a..51a825b 100644
--- a/Makefile
+++ b/Makefile
@@ -4,11 +4,16 @@ SRC = ${SRCDIR}/main.go \
${SRCDIR}/paypal.go \
${SRCDIR}/db.go \
${SRCDIR}/auth.go \
+ ${SRCDIR}/bucket.go \
GOFILES = ${SRCDIR}/go.sum ${SRCDIR}/go.mod
GOMODS = github.com/joho/godotenv \
github.com/lib/pq \
gopkg.in/gomail.v2 \
+ github.com/aws/aws-sdk-go-v2/aws \
+ github.com/aws/aws-sdk-go-v2/config \
+ github.com/aws/aws-sdk-go-v2/credentials \
+ github.com/aws/aws-sdk-go-v2/service/s3 \
all: ${BIN} fmt
diff --git a/README.org b/README.org
index de91e99..a80b3a0 100644
--- a/README.org
+++ b/README.org
@@ -34,7 +34,7 @@ CREATE TABLE sites (
phone VARCHAR(20),
code VARCHAR(2),
title VARCHAR(35) NOT NULL,
- slogan VARCHAR(100) NOT NULL,
+ slogan VARCHAR(100),
banner TEXT,
raw JSONB NOT NULL,
auth INTEGER,
diff --git a/public/client.js b/public/client.js
index a2a01c6..9453258 100644
--- a/public/client.js
+++ b/public/client.js
@@ -1,5 +1,5 @@
document.addEventListener("DOMContentLoaded", function() {
- const savedData = localStorage.getItem('editor_data');
+ const savedData = localStorage.getItem('conex_data');
if (savedData) {
const parsedData = JSON.parse(savedData);
console.log('Loaded parsedData:', parsedData);
@@ -11,14 +11,17 @@ document.addEventListener("DOMContentLoaded", function() {
const dialog = document.getElementById("dialog");
const overlay = document.getElementById("overlay");
const menu = document.getElementById("floatingButtons");
+ const checkoutErrorMessage = document.getElementById("checkout-error-message");
function openDialog() {
+ checkoutErrorMessage.style.display = "none";
dialog.style.display = "block";
overlay.style.display = "block";
menu.style.display = "none";
}
function closeDialog() {
+ checkoutErrorMessage.style.display = "none";
dialog.style.display = "none";
overlay.style.display = "none";
menu.style.display = "block";
@@ -37,56 +40,60 @@ function saveEditorData() {
editor.save().then((editor_data) => {
const dataToSave = {
- banner: banner,
+ directory: sanitizeDirectoryTitle(title),
+ banner: banner || '/static/svg/banner.svg',
title: title,
slogan: slogan,
editor_data: editor_data
};
- localStorage.setItem('editor_data', JSON.stringify(dataToSave));
+ localStorage.setItem('conex_data', JSON.stringify(dataToSave));
console.log('Editor data saved to localStorage');
}).catch((error) => {
console.error('Saving failed:', error);
});
}
-const directoryInput = document.getElementById('title');
-const statusPopup = document.getElementById('status-popup');
-const statusMessage = document.getElementById('status-message');
let typingTimeout;
let hideTimeout;
-
+const directoryInput = document.getElementById('title');
directoryInput.addEventListener('input', () => {
clearTimeout(typingTimeout);
typingTimeout = setTimeout(() => {
- const directoryName = directoryInput.value.trim();
- if (directoryName.length > 0) {
- const sanitizedDirectoryName = sanitizeDirectoryName(directoryName);
- checkDirectory(sanitizedDirectoryName);
+ const directoryTitle = directoryInput.value.trim();
+ if (directoryTitle.length > 0) {
+ const directory = sanitizeDirectoryTitle(directoryTitle);
+ checkDirectory(directory);
} else {
hidePopup();
}
}, 500); // Debounce
});
-function sanitizeDirectoryName(name) {
- return name
+function sanitizeDirectoryTitle(title) {
+ return title
.toLowerCase()
.replace(/\s+/g, '-')
+ .normalize('NFD')
+ .replace(/[\u0300-\u036f]/g, '')
.replace(/[^a-z0-9\-]/g, '');
}
-function checkDirectory(name) {
- if (name.length < 4) {
+function checkDirectory(directory) {
+ if (directory.length < 4) {
return;
}
- fetch(`/api/directory/${encodeURIComponent(name)}`)
+ if (directory.length > 35) {
+ showPopup(`El título no puede exceder los 35 caracteres`, 'exists');
+ return;
+ }
+ fetch(`/api/directory/${encodeURIComponent(directory)}`)
.then(response => response.json())
.then(data => {
if (data.exists) {
- showPopup(`El sitio web conex.one/${name} ya existe`, 'exists');
+ showPopup(`El sitio web conex.one/${directory} ya existe`, 'exists');
} else {
- showPopup(`Se publicará en conex.one/${name}`, 'available');
+ showPopup(`Se publicará en conex.one/${directory}`, 'available');
}
})
.catch(error => {
@@ -133,16 +140,28 @@ function hidePopup(popup, status) {
}
document.getElementById('imageUpload').addEventListener('change', function (event) {
+ const savedData = localStorage.getItem('conex_data');
+ const parsedData = savedData ? JSON.parse(savedData) : null;
+ const directory = parsedData?.directory || "temp";
const file = event.target.files[0];
- const reader = new FileReader();
-
- reader.onload = function (e) {
- const base64Image = e.target.result;
- document.getElementById('banner').src = base64Image;
- saveEditorData();
- };
if (file) {
- reader.readAsDataURL(file);
+ const formData = new FormData();
+ formData.append('file', file);
+ formData.append('directory', directory);
+
+ fetch('/api/upload', {
+ method: 'POST',
+ body: formData,
+ }).then(response => response.json()).then(data => {
+ if (data && data.file && data.file.url) {
+ document.getElementById('banner').src = data.file.url;
+ saveEditorData();
+ } else {
+ console.error('Error: Invalid response format', data);
+ }
+ }).catch(error => {
+ console.error('Error uploading the image:', error);
+ });
}
});
diff --git a/public/index.html b/public/index.html
index 41dcd28..aaca9d5 100644
--- a/public/index.html
+++ b/public/index.html
@@ -18,8 +18,8 @@
Gracias por elegir nuestro servicio para la compra de sitios web. Luego de ser aprobado, su sitio será publicado en menos de 24 horas a partir de la confirmación de tu compra. Utilizaremos los medios de contacto que proporcione para comunicarnos en caso de cualquier inconveniente con la publicación. Si experimenta algún problema, no dude en ponerte en contacto con nosotros a través de los canales: