From 29e26aa64763c58a156cf42d016f374d2da37920 Mon Sep 17 00:00:00 2001 From: spitkov Date: Sun, 15 Sep 2024 17:03:38 -0400 Subject: [PATCH] ctrl + v when file modal is open and drag file to instantly upload --- app.py | 12 +++- templates/404.html | 8 ++- templates/index.html | 143 ++++++++++++++++++++++++++++++++++++++-- templates/login.html | 72 ++++++++++++++------ templates/pastebin.html | 23 +++++++ templates/register.html | 64 +++++++++++++----- 6 files changed, 278 insertions(+), 44 deletions(-) diff --git a/app.py b/app.py index 4a1eb22..060d0e0 100644 --- a/app.py +++ b/app.py @@ -668,17 +668,23 @@ def shorten_url(): return jsonify({'success': False, 'error': 'URL is required'}), 400 long_url = data['url'] + password = data.get('password') # Get the password if provided vanity = shortuuid.uuid()[:8] user_id = current_user.id if current_user.is_authenticated else None db = get_db() cursor = db.cursor() - cursor.execute("INSERT INTO content (vanity, type, data, created_at, user_id) VALUES (?, ?, ?, ?, ?)", - (vanity, 'url', long_url, datetime.now(), user_id)) + + is_private = 1 if password else 0 + + cursor.execute(""" + INSERT INTO content (vanity, type, data, created_at, user_id, is_private, password) + VALUES (?, ?, ?, ?, ?, ?, ?) + """, (vanity, 'url', long_url, datetime.now(), user_id, is_private, password)) + db.commit() - # Return only the vanity code, not the full URL return jsonify({'success': True, 'vanity': vanity}), 200 except Exception as e: print("Exception occurred:", str(e)) diff --git a/templates/404.html b/templates/404.html index bc73bec..fa995ab 100644 --- a/templates/404.html +++ b/templates/404.html @@ -66,7 +66,13 @@


-

Source code on:

GitHub | Spitkov's Git + diff --git a/templates/index.html b/templates/index.html index e49a49a..4a398c2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -258,6 +258,40 @@ .other-links.show { display: block; } + + .global-drop-area { + display: none; + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: rgba(0, 0, 0, 0.5); + z-index: 9999; + justify-content: center; + align-items: center; + } + + .global-drop-box { + border: 3px dashed #4CAF50; + border-radius: 20px; + padding: 50px; + text-align: center; + background-color: rgba(0, 0, 0, 0.7); + color: white; + } + + .instant-upload-result { + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + background-color: #2a2a2a; + padding: 20px; + border-radius: 10px; + z-index: 10000; + display: none; + } @@ -329,15 +363,37 @@ ×

Shorten URL

+
+ + +
+
+
+
+

Drop file to instantly upload

+
+
+ +
+

File Uploaded

+

Direct download URL:

+

Normal URL:

+ +
+ @@ -433,6 +489,10 @@ document.getElementById('filePasswordField').style.display = this.checked ? 'block' : 'none'; }); + document.getElementById('urlIsPrivate').addEventListener('change', function() { + document.getElementById('urlPasswordField').style.display = this.checked ? 'block' : 'none'; + }); + function uploadText() { const content = document.getElementById('textContent').value; const isPrivate = document.getElementById('isPrivate').checked; @@ -608,13 +668,20 @@ function shortenUrl() { const url = document.getElementById('urlInput').value; + const isPrivate = document.getElementById('urlIsPrivate').checked; + const password = isPrivate ? document.getElementById('urlPassword').value : null; + const data = { + url: url, + password: password + }; + fetch('/shorten', { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ url: url }), + body: JSON.stringify(data), }) .then(response => { if (!response.ok) { @@ -625,7 +692,11 @@ .then(data => { if (data.success) { const shortUrl = `${window.location.origin}/${data.vanity}`; - document.getElementById('urlResult').innerHTML = `URL shortened. Access it ${shortUrl}`; + let resultHtml = `URL shortened. Access it ${shortUrl}`; + if (isPrivate) { + resultHtml += `
Password-protected link: ${shortUrl}/${password}`; + } + document.getElementById('urlResult').innerHTML = resultHtml; } else { document.getElementById('urlResult').innerHTML = `Error: ${data.error}`; } @@ -635,6 +706,70 @@ document.getElementById('urlResult').innerHTML = `An error occurred: ${error.message}`; }); } + + // Global drag and drop + document.addEventListener('dragover', function(e) { + e.preventDefault(); + document.querySelector('.global-drop-area').style.display = 'flex'; + }); + + document.addEventListener('dragleave', function(e) { + if (e.clientX === 0 || e.clientY === 0) { + document.querySelector('.global-drop-area').style.display = 'none'; + } + }); + + document.addEventListener('drop', function(e) { + e.preventDefault(); + document.querySelector('.global-drop-area').style.display = 'none'; + if (e.dataTransfer.files.length > 0) { + instantUploadFile(e.dataTransfer.files[0]); + } + }); + + function instantUploadFile(file) { + const formData = new FormData(); + formData.append('file', file); + + fetch('/upload/file', { + method: 'POST', + body: formData + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + document.getElementById('directDownloadUrl').href = data.download_url; + document.getElementById('directDownloadUrl').textContent = data.download_url; + document.getElementById('normalUrl').href = data.url; + document.getElementById('normalUrl').textContent = data.url; + document.querySelector('.instant-upload-result').style.display = 'block'; + } else { + alert('Error uploading file: ' + data.error); + } + }) + .catch(error => { + console.error('Error:', error); + alert('An error occurred while uploading the file'); + }); + } + + function closeInstantUploadResult() { + document.querySelector('.instant-upload-result').style.display = 'none'; + } + + // Paste functionality for file upload + document.addEventListener('paste', function(e) { + if (document.getElementById('fileModal').style.display === 'block') { + const items = e.clipboardData.items; + for (let i = 0; i < items.length; i++) { + if (items[i].kind === 'file') { + const file = items[i].getAsFile(); + filesToUpload.push(file); + updateSelectedFilesList(); + } + } + } + }); diff --git a/templates/login.html b/templates/login.html index 2fdaed1..cb6ec5b 100644 --- a/templates/login.html +++ b/templates/login.html @@ -11,12 +11,17 @@ margin: 0; padding: 0; display: flex; - justify-content: center; - align-items: center; + flex-direction: column; min-height: 100vh; background-color: #1a1a1a; color: #f0f0f0; } + .content { + flex: 1; + display: flex; + justify-content: center; + align-items: center; + } .container { background-color: #2a2a2a; padding: 20px; @@ -75,27 +80,54 @@ a:hover { text-decoration: underline; } + .back-button { + position: absolute; + top: 20px; + left: 20px; + font-size: 24px; + color: #4CAF50; + text-decoration: none; + } + .back-button:hover { + color: #45a049; + } + .footer { + text-align: center; + padding: 10px; + background-color: #2a2a2a; + color: #f0f0f0; + } -
-

Login

-
-
- - -
-
- - -
-
- - -
- -
-

Don't have an account? Register here

+ +
+
+

Login

+
+
+ + +
+
+ + +
+
+ + +
+ +
+

Don't have an account? Register here

+
+ \ No newline at end of file diff --git a/templates/pastebin.html b/templates/pastebin.html index f0db0b2..e8050a1 100644 --- a/templates/pastebin.html +++ b/templates/pastebin.html @@ -185,10 +185,25 @@ color: white; } + .home-button { + position: fixed; + top: 20px; + left: 20px; + font-size: 24px; + color: var(--text-color); + text-decoration: none; + z-index: 1001; + } + + .home-button:hover { + color: #4CAF50; + } + {{ css|safe }} +

Content

Uploaded by: {{ content.username }}

@@ -229,6 +244,14 @@
+ +