Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit requests per hour #96

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Django>=1.11.18,<1.12
jpype1==0.6.3
numpy==1.15.2
djangorestframework==3.6.4
django-ratelimit==2.0.0
bs4==0.0.1
requests==2.20.1
lxml==4.2.5
Expand Down
10 changes: 5 additions & 5 deletions src/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ def convert(request):
message = jpype.JavaException.message(ex)
returnstatus = status.HTTP_400_BAD_REQUEST
httpstatus = 400
jpype.detachThreadFromJVM()
jpype.detachThreadFromJVM()
except :
message = format_exc()
returnstatus = status.HTTP_400_BAD_REQUEST
httpstatus = 400
jpype.detachThreadFromJVM()
jpype.detachThreadFromJVM()
query.tagToRdfFormat=tagToRdfFormat
query.message=message
query.status = httpstatus
Expand Down Expand Up @@ -473,10 +473,10 @@ def check_license(request):
returnstatus = status.HTTP_400_BAD_REQUEST
httpstatus = 400
jpype.detachThreadFromJVM()

except jpype.JavaException as ex :
""" Java exception raised without exiting the application """
result = jpype.JavaException.message(ex)
result = jpype.JavaException.message(ex)
returnstatus = status.HTTP_400_BAD_REQUEST
httpstatus = 400
jpype.detachThreadFromJVM()
Expand All @@ -496,4 +496,4 @@ def check_license(request):
else:
return Response(
serializer.errors, status=status.HTTP_400_BAD_REQUEST
)
)
20 changes: 14 additions & 6 deletions src/app/templates/app/check_license.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<textarea id="licensetext" name="licensetext" rows="18" style="width: 100%"></textarea>
<button id="checklicensebutton" class=" btn btn-md btn-info" type="submit">Check License</button>
</form>
{% include "app/modal.html" %}
{% include "app/modal.html" %}
</div>
{% endblock %}
{% block script_block %}
Expand Down Expand Up @@ -59,7 +59,7 @@
$("#modal-body").html("<h3>"+data.data+"</h3>");
$("#myModal").modal({
backdrop: 'static',
keyboard: true,
keyboard: true,
show: true
});
$("#checklicensebutton").text("Check License");
Expand All @@ -70,9 +70,17 @@
$("#modal-header").removeClass("green-modal");
try {
var obj = JSON.parse(e.responseText);
$("#modal-header").addClass("red-modal");
$("#modal-title").html("Error!");
$("#modal-body").text(obj.data);
if (obj.type=="warning" || obj.type=="rate_limit"){
$("#modal-header").removeClass("red-modal");
$("#modal-header").addClass("yellow-modal");
$("#modal-title").html("Warning!");
}
else if (obj.type=="error"){
$("#modal-header").removeClass("yellow-modal");
$("#modal-header").addClass("red-modal");
$("#modal-title").html("Error!");
}
$("#modal-body").text(obj.data);
}
catch (e){
$("#modal-header").addClass("red-modal");
Expand All @@ -81,7 +89,7 @@
}
$("#myModal").modal({
backdrop: 'static',
keyboard: true,
keyboard: true,
show: true
});
$("#checklicensebutton").text("Check License");
Expand Down
28 changes: 17 additions & 11 deletions src/app/templates/app/compare.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ <h4 id="doclabel">Upload SPDX Documents using the button or by dragging and drop
<div class = "form-group">
<div class="col-sm-12">
<label class="control-label col-sm-3" >Result File Name</label>
<div class="col-sm-6">
<div class="col-sm-6">
<input type="text" id="rfilename" placeholder="" name = "rfilename">
<label class="control-label" id="convertdoclabel">.xlsx</label>
</div>
</div>
</div>
</div>
<hr>
<button class=" btn btn-md btn-info" type="submit" id="comparebutton" name="compare">Compare</button>
Expand All @@ -50,7 +50,7 @@ <h4 id="doclabel">Upload SPDX Documents using the button or by dragging and drop
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false)
});

function preventDefaults (e) {
e.preventDefault()
e.stopPropagation()
Expand All @@ -59,19 +59,19 @@ <h4 id="doclabel">Upload SPDX Documents using the button or by dragging and drop
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false)
});

['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false)
});

function highlight(e) {
dropArea.classList.add('highlight')
}

function unhighlight(e) {
dropArea.classList.remove('highlight')
}

dropArea.addEventListener('drop', handleDrop, false)

function handleDrop(e) {
Expand All @@ -83,7 +83,7 @@ <h4 id="doclabel">Upload SPDX Documents using the button or by dragging and drop
function handleFiles(files) {
([...files]).forEach(checkFile)
}

function checkFile(file){
if(file && selected_files.length<13){
if ($(".file-name").text() == "No file selected"){
Expand Down Expand Up @@ -153,7 +153,7 @@ <h4 id="doclabel">Upload SPDX Documents using the button or by dragging and drop
$("#modal-body").html('<h3><a href="'+data.medialink+'"><span class="glyphicon glyphicon-save-file"></span> Download file now</a></h3>');
$("#myModal").modal({
backdrop: 'static',
keyboard: true,
keyboard: true,
show: true
});
$("#comparebutton").text("Compare");
Expand All @@ -165,6 +165,12 @@ <h4 id="doclabel">Upload SPDX Documents using the button or by dragging and drop
$("#modal-header").removeClass("green-modal");
try{
var obj = JSON.parse(e.responseText);
if (obj.type=="rate_limit"){
$("#modal-header").removeClass("red-modal");
$("#modal-header").addClass("yellow-modal");
$("#modal-title").html("Warning!");
$("#modal-body").text(obj.data);
}
if (obj.type=="warning"){
$("#modal-header").removeClass("red-modal");
$("#modal-header").addClass("yellow-modal");
Expand Down Expand Up @@ -208,7 +214,7 @@ <h4 id="doclabel">Upload SPDX Documents using the button or by dragging and drop

$("#myModal").modal({
backdrop: 'static',
keyboard: true,
keyboard: true,
show: true
});
$("#comparebutton").text("Compare");
Expand All @@ -231,4 +237,4 @@ <h4 id="doclabel">Upload SPDX Documents using the button or by dragging and drop
});
</script>

{% endblock %}
{% endblock %}
34 changes: 20 additions & 14 deletions src/app/templates/app/convert.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ <h4 id="doclabel">Upload SPDX Document using the button or by dragging and dropp
<div class = "form-group">
<div class="col-sm-12">
<label class="control-label col-sm-3" id="doclabel" >SPDX Document</label>
<div class="col-sm-3">
<div class="col-sm-3">
<input type="file" id="file" placeholder="" name = "file" >
</div>
</div>
</div>
</div>
-->
<div class = "form-group">
<div class="col-sm-12">
<label class="control-label col-sm-3" >Converted File Name</label>
<div class="col-sm-3">
<div class="col-sm-3">
<input type="text" id="cfilename" placeholder="" name = "cfilename" >
<label class="control-label" id="convertdoclabel" ></label>
</div>
</div>
</div>
</div>
<hr>
<input type="hidden" id="cfileformat" name="cfileformat" value="">
Expand All @@ -88,7 +88,7 @@ <h4 id="doclabel">Upload SPDX Document using the button or by dragging and dropp
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false)
});

function preventDefaults (e) {
e.preventDefault()
e.stopPropagation()
Expand All @@ -97,19 +97,19 @@ <h4 id="doclabel">Upload SPDX Document using the button or by dragging and dropp
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false)
});

['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false)
});

function highlight(e) {
dropArea.classList.add('highlight')
}

function unhighlight(e) {
dropArea.classList.remove('highlight')
}

dropArea.addEventListener('drop', handleDrop, false)

function handleDrop(e) {
Expand All @@ -121,7 +121,7 @@ <h4 id="doclabel">Upload SPDX Document using the button or by dragging and dropp
function handleFiles(files) {
([...files]).forEach(checkFile)
}

function checkFile(file){
if(file){
$(".file-name").html("<b>Selected File: </b>"+file.name);
Expand Down Expand Up @@ -264,7 +264,7 @@ <h4 id="doclabel">Upload SPDX Document using the button or by dragging and dropp
$("#modal-body").html('<h3><a href="'+data.medialink+'"><span class="glyphicon glyphicon-save-file"></span> Download file now</a></h3>');
$("#myModal").modal({
backdrop: 'static',
keyboard: true,
keyboard: true,
show: true
});
$("#convertbutton").text("Convert");
Expand All @@ -276,6 +276,12 @@ <h4 id="doclabel">Upload SPDX Document using the button or by dragging and dropp
$("#modal-body").text("");
try{
var obj = JSON.parse(e.responseText);
if (obj.type=="rate_limit"){
$("#modal-header").removeClass("red-modal");
$("#modal-header").addClass("yellow-modal");
$("#modal-title").html("Warning!");
$("#modal-body").text(obj.data);
}
if (obj.type=="warning"){
$("#modal-header").removeClass("red-modal");
$("#modal-header").addClass("yellow-modal");
Expand All @@ -297,10 +303,10 @@ <h4 id="doclabel">Upload SPDX Document using the button or by dragging and dropp
$("#modal-title").html("Error!");
$("#modal-body").text("The application could not be connected. Please try later.");
}

$("#myModal").modal({
backdrop: 'static',
keyboard: true,
keyboard: true,
show: true
});
$("#convertbutton").text("Convert");
Expand All @@ -319,4 +325,4 @@ <h4 id="doclabel">Upload SPDX Document using the button or by dragging and dropp

</script>

{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion src/app/templates/app/submit_new_license.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
$("#modal-header").removeClass("green-modal");
try {
var obj = JSON.parse(e.responseText);
if (obj.type=="warning"){
if (obj.type=="warning" || obj.type=="rate_limit"){
$("#modal-header").removeClass("red-modal");
$("#modal-header").addClass("yellow-modal");
$("#modal-title").html("Warning!");
Expand Down
22 changes: 11 additions & 11 deletions src/app/templates/app/validate.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h4>Upload file using the button or by dragging and dropping onto the dashed reg
</form>
</div> <hr>
<button id="validatebutton" name="validatebutton" class="btn btn-md btn-info" type="submit" disabled="true">Validate</button>
{% include "app/modal.html" %}
{% include "app/modal.html" %}
<!--
<output id="list"></output>
-->
Expand All @@ -40,7 +40,7 @@ <h4>Upload file using the button or by dragging and dropping onto the dashed reg
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false)
});

function preventDefaults (e) {
e.preventDefault()
e.stopPropagation()
Expand All @@ -49,19 +49,19 @@ <h4>Upload file using the button or by dragging and dropping onto the dashed reg
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false)
});

['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false)
});

function highlight(e) {
dropArea.classList.add('highlight')
}

function unhighlight(e) {
dropArea.classList.remove('highlight')
}

dropArea.addEventListener('drop', handleDrop, false)

function handleDrop(e) {
Expand All @@ -73,7 +73,7 @@ <h4>Upload file using the button or by dragging and dropping onto the dashed reg
function handleFiles(files) {
([...files]).forEach(checkFile)
}

function checkFile(file){
if(file){
$(".file-name").html("<b>Selected File: </b>"+file.name);
Expand Down Expand Up @@ -125,7 +125,7 @@ <h4>Upload file using the button or by dragging and dropping onto the dashed reg
$("#modal-body").html("<h3>"+data.data+"</h3>");
$("#myModal").modal({
backdrop: 'static',
keyboard: true,
keyboard: true,
show: true
});
$("#validatebutton").text("Validate");
Expand All @@ -136,7 +136,7 @@ <h4>Upload file using the button or by dragging and dropping onto the dashed reg
$("#modal-header").removeClass("green-modal");
try {
var obj = JSON.parse(e.responseText);
if (obj.type=="warning"){
if (obj.type=="warning" || obj.type=="rate_limit"){
$("#modal-header").removeClass("red-modal");
$("#modal-header").addClass("yellow-modal");
$("#modal-title").html("Warning!");
Expand All @@ -156,7 +156,7 @@ <h4>Upload file using the button or by dragging and dropping onto the dashed reg
}
$("#myModal").modal({
backdrop: 'static',
keyboard: true,
keyboard: true,
show: true
});
$("#validatebutton").text("Validate");
Expand Down Expand Up @@ -236,4 +236,4 @@ <h4>Upload file using the button or by dragging and dropping onto the dashed reg
</script>
-->

{% endblock %}
{% endblock %}