Skip to content

Commit

Permalink
added link verification
Browse files Browse the repository at this point in the history
  • Loading branch information
asimonson1125 committed Aug 26, 2022
1 parent 84cd711 commit cdc3ef5
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 20 deletions.
16 changes: 15 additions & 1 deletion src/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import calc
import downloader
from help import *
import sys

socketio = SocketIO(app)

Expand Down Expand Up @@ -200,6 +199,17 @@ def getMembers(group):
socketio.emit('memberList', out, to=flask.request.sid)


@socketio.on('checkURL')
def checkURL(url):
message = downloader.check(url)
if message == "":
message = "urlCheck0A calendar was found at this link!"
else:
message = "urlCheck1" + message
socketio.emit('stringtype', message, to=flask.request.sid)



@app.route('/')
def get_in():
return flask.render_template('input.html')
Expand All @@ -215,6 +225,10 @@ def get_blank():
return flask.render_template('blank.html')


@app.route('/verifyURL')
def get_verifier():
return flask.render_template("verifyURL.html")

@app.errorhandler(Exception)
def page404(e):
try:
Expand Down
18 changes: 18 additions & 0 deletions src/downloader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import icalendar
import calc

from sanitizer import isCalendar


def local(start, end, path, calendars, i, socketio, sid):
"""
Expand All @@ -20,3 +22,19 @@ def run(start, end, path, calendars, i, socketio, sid):
calendar = calc.get_cal(path, start, end)
calendars[i] = calendar
socketio.emit('loadUpdate', i, to=sid)

def check(url):
"""
Checks validity of a url
"""
message = ""
try:
calendar = isCalendar(url) # downloads cal
if(calendar):
if calendar.get("CALSCALE", "GREGORIAN") != "GREGORIAN":
message = "Only gregorian calendars can be loaded!"
else:
message = "Calendar not found!"
except:
message = "Error on load!"
return message
2 changes: 1 addition & 1 deletion src/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ nav {
padding-right: 1rem;
}

#loadingMembers {
#loading {
width: 25px;
}

Expand Down
8 changes: 8 additions & 0 deletions src/static/images/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 10 additions & 13 deletions src/static/images/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/static/js/inputVisuals.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function loadMembers(members) {
member.id = 'member ' + i;
container.appendChild(member);
}
document.getElementById('loadingMembers').style.display = 'none';
document.getElementById('loading').style.display = 'none';
updateSearchScrollArrows();
}

Expand Down
15 changes: 14 additions & 1 deletion src/static/js/sock.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,23 @@ function emitData(event, data) {
socket.emit(event, data)
}

function ayylmao(string){
if(string.startsWith('urlCheck')){
checkResults(string.substring(8));
}
else{
alert(string);
}
}

socket.on('redirect', (dest) => {
window.location.href = dest;
});

socket.on('stringtype', (string) => {
ayylmao(string);
});

socket.on('loader', (status) => {
loadStatus(status);
});
Expand All @@ -34,4 +47,4 @@ socket.on('loaded', (output) => {
socket.on('loadUpdate', (index) => {
let list = document.getElementById('calendarStatus');
list.children[index].querySelector('.progressBar').style.backgroundColor = "lightgray";
});
});
18 changes: 18 additions & 0 deletions src/static/js/verifyURL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function checkURL(){
const url = document.querySelector('#urlVerify').value;
document.querySelector('#loading').classList.remove('hidden');
emitData('checkURL', url);
}

function checkResults(result){
let resultsDiv = document.querySelector('#checkResults');
if(result[0] == '0'){
resultsDiv.querySelector('img').src = "../static/images/check.svg"
}
else{
resultsDiv.querySelector('img').src = "../static/images/close.svg"
}
resultsDiv.querySelector('p').textContent = result.substring(1);
resultsDiv.classList.remove('hidden');
document.querySelector('#loading').classList.add('hidden');
}
2 changes: 1 addition & 1 deletion src/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h4>Slate will never reveal users' calendars or event details to users.</h4>
<p><a href="https://github.com/asimonson1125/Slate/releases/tag/1.0.0">The initial version of Slate</a> is the
2021-22 major project by Andrew
Simonson.</p>
<p>In <a href='https://www.slate.csh.rit.edu'>version 2.0</a> the project (now 2022-23 major project, also Andrew
<p>In <a href='https://slate.csh.rit.edu'>version 2.0</a> the project (now 2022-23 major project, also Andrew
Simonson) gained a much improved UX, large performance improvements, <a href='https://www.csh.rit.edu'>
Computer Science House</a> service integration, and basic analytics. This iteration is the first I consider
publishable (delivers on all base objectives and is user-friendly)</p>
Expand Down
6 changes: 5 additions & 1 deletion src/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<script src="../static/js/validateForm.js" type="text/javascript"></script>
<script src="../static/js/inputVisuals.js"></script>
<script src="../static/js/header.js"></script>
<script src="../static/js/verifyURL.js"></script>
<title>CSH Slate</title>
{% block headAdditions %}{% endblock %}
</head>
Expand All @@ -42,7 +43,10 @@
<a href="/about">
<p class="noMargin">About Slate</p>
</a>
<p class="eventable" onclick="emit('example')">Example usage</p>
<p class="eventable" onclick="emit('example')">Example Usage</p>
<a href="/verifyURL">
<p class="noMargin">Link Verifier</p>
</a>
{% if current_user.is_authenticated %}
<div>
<div class="dropdown-toggle" href="#" id="user01">
Expand Down
2 changes: 1 addition & 1 deletion src/templates/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h3>Select Participating Members</h3>
<input type="text" name="memberDirect" placeholder="search name or username" oninput="searchForMembers()"
id="searchMembers">
<button type="button" onclick="selectAll()">(De)Select All Displayed</button>
<img id='loadingMembers' src='../static/images/blue_spinner.gif' alt='loading members' />
<img id='loading' src='../static/images/blue_spinner.gif' alt='loading members' />
<script>emitData('getMembers', 'active')</script>
<br />
</div>
Expand Down
17 changes: 17 additions & 0 deletions src/templates/verifyURL.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "header.html" %}
{% block content %}
<div class="box">
<form action="javascript:checkURL()">
<h2>Verify your url points to a ics calendar</h2>
<p>Webservers can be picky when fufilling requests, links that work in your browser might still not work in Slate</p>
<input type="text" id="urlVerify" name="urlVerify" placeholder="URL">
<input type="submit" value="Submit">
<img id='loading' src='../static/images/blue_spinner.gif' alt='loading members' class="hidden" />
<br />
</form>
<div id="checkResults" class="hidden" style="display: flex">
<img alt="result" width="30px"/>
<p></p>
</div>
</div>
{% endblock %}

0 comments on commit cdc3ef5

Please sign in to comment.