Skip to content

Commit

Permalink
add auth header to index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
robatipoor committed Mar 19, 2024
1 parent b4801e4 commit 12bfde3
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions api/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
margin-bottom: 20px;
border: 3px solid rgb(255, 255, 255);
margin: auto;

&.is-active {
display: block;
}
Expand Down Expand Up @@ -127,9 +128,22 @@ <h2>Paste File</h2>
<script>
$("#ajaxForm").submit(function (e) {
e.preventDefault();
var username = $("#username").val();
var password = $("#password").val();
var headers = { "Accept": "application/json" };
if (username && password) {
headers['Authorization'] = createBasicAuthHeader(username, password);
} else if (username && !password) {
alert('Please set password');
return;
} else if (!username && password) {
alert('Please set username');
return;
}
$('.progress-bar').addClass('is-active');
var action = $(this).attr("action");
var uploadUrl = createUploadURL(action);

$.ajax({
xhr: function () {
var xhr = new window.XMLHttpRequest();
Expand All @@ -150,9 +164,7 @@ <h2>Paste File</h2>
contentType: "multipart/form-data",
processData: false,
contentType: false,
headers: {
"Accept": "application/json"
},
headers: headers,
success: function (response) {
$('.success').addClass('is-active');
$('#result-url').empty();
Expand All @@ -161,15 +173,20 @@ <h2>Paste File</h2>
$('#qrcode').qrcode({ width: 256, height: 256, text: response.url });
},
}).fail(function () {
alert('An error occurred please try again later.')
alert('An error occurred please try again later.');
});
});

$("#copyButton").click(function (event) {
event.preventDefault();
navigator.clipboard.writeText($('#result-url').text()).then(() => { });
alert('URL copied to clipboard!');
});

function createBasicAuthHeader(username, password) {
return "Basic " + btoa(username + ':' + password);
}

function createUploadURL(base_url) {
var result = base_url;
var codeLength = $('#codeLength').val();
Expand Down Expand Up @@ -201,9 +218,7 @@ <h2>Paste File</h2>
}
return result;
}

</script>

</body>

</html>

0 comments on commit 12bfde3

Please sign in to comment.