Slots can be updated without removing & adding

This commit is contained in:
Simon 2018-06-24 09:39:44 -04:00
parent 348914aba9
commit 1ac510ff53
5 changed files with 59 additions and 15 deletions

26
app.py
View File

@ -447,10 +447,24 @@ def admin_delete_crawl_server(server_id):
abort(403) abort(403)
@app.route("/crawl_server/<int:server_id>/update", methods=["POST"])
def admin_update_crawl_server(server_id):
crawl_servers = db.get_crawl_servers()
for server in crawl_servers:
if server.id == server_id:
new_slots = request.form.get("slots") if "slots" in request.form else server.slots
new_name = request.form.get("name") if "name" in request.form else server.name
new_url = request.form.get("url") if "url" in request.form else server.url
db.update_crawl_server(server_id, new_url, new_name, new_slots)
flash("Updated crawl server", "success")
return redirect("/dashboard")
flash("Couldn't find crawl server with this id: " + str(server_id), "danger")
return redirect("/dashboard")
if __name__ == '__main__': if __name__ == '__main__':
if config.USE_SSL: app.run("0.0.0.0", port=12345, threaded=True)
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.load_cert_chain('certificates/cert.pem', 'certificates/privkey.pem')
app.run("0.0.0.0", port=12345, ssl_context=context, threaded=True)
else:
app.run("0.0.0.0", port=12345, threaded=True)

View File

@ -163,14 +163,6 @@ class RemoteDirectoryCrawler:
directory.close() directory.close()
in_q.put(path) in_q.put(path)
break break
except TimeoutError:
if timeout_retries > 0:
timeout_retries -= 1
# TODO: Remove debug info
print("TIMEOUT, " + str(timeout_retries) + " retries left")
in_q.put(path)
else:
print("Dropping listing for " + path)
finally: finally:
in_q.task_done() in_q.task_done()

View File

@ -64,7 +64,9 @@ class HttpDirectory(RemoteDirectory):
"?C=D&O=A", "?C=D&O=A",
"?C=N;O=D", "?C=N;O=D",
"?C=M;O=A", "?C=M;O=A",
"?C=M&O=D",
"?C=S;O=A", "?C=S;O=A",
"?C=S&O=D",
"?C=D;O=A", "?C=D;O=A",
"?MA", "?MA",
"?SA", "?SA",

View File

@ -304,6 +304,14 @@ class Database:
return [task.CrawlServer(r[0], r[1], r[2], r[3], r[4]) for r in cursor.fetchall()] return [task.CrawlServer(r[0], r[1], r[2], r[3], r[4]) for r in cursor.fetchall()]
def update_crawl_server(self, server_id, url, name, slots):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("UPDATE CrawlServer SET url=?, name=?, slots=? WHERE id=?", (url, name, slots, server_id))
conn.commit()

View File

@ -22,7 +22,7 @@
<tr> <tr>
<td>{{ server.url }}</td> <td>{{ server.url }}</td>
<td>{{ server.name }}</td> <td>{{ server.name }}</td>
<td>{{ server.slots }}</td> <td id="slots-{{ server.id }}" onclick="changeSlots({{ server.id }})">{{ server.slots }}</td>
<td><a class="btn btn-danger" href="/crawl_server/{{ server.id }}/delete">Delete</a></td> <td><a class="btn btn-danger" href="/crawl_server/{{ server.id }}/delete">Delete</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
@ -127,4 +127,32 @@
</div> </div>
</div> </div>
</div> </div>
<script>
function changeSlots(id) {
let slotsElem = document.getElementById("slots-" + id);
let parent = slotsElem.parentNode;
let td = document.createElement("td");
let form = document.createElement("form");
form.setAttribute("action", "/crawl_server/" + id + "/update");
form.setAttribute("method", "post");
let slotsInput = document.createElement("input");
slotsInput.setAttribute("class", "form-control");
slotsInput.setAttribute("name", "slots");
form.appendChild(slotsInput);
td.appendChild(form);
parent.insertBefore(td, slotsElem);
slotsElem.remove();
slotsInput.focus();
slotsInput.addEventListener("focusout", function () {
form.submit();
});
}
</script>
{% endblock body %} {% endblock body %}