From ef746039148dfc359d222422bca1896f56adece7 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 29 Sep 2017 10:11:19 +0200 Subject: [PATCH] update --- server.py | 25 +++++++++++++++++-------- static/css/style.css | 41 +++++++++++++++++++++++++++++++++++++++++ templates/index.html | 39 ++++++++++++++++++++++++--------------- templates/repo.html | 34 ++++++++++++++++++++++------------ 4 files changed, 104 insertions(+), 35 deletions(-) create mode 100644 static/css/style.css diff --git a/server.py b/server.py index 37e6eba..9191c76 100644 --- a/server.py +++ b/server.py @@ -3,7 +3,7 @@ import uuid import json import socket import os - +import urllib # non standards, in requirements.txt from flask import Flask, request, Markup, render_template, redirect, url_for @@ -48,12 +48,12 @@ class Anonymous_Github: content = content.replace(term, "XXX") return content if ".md" in file.name: - return "
%s
" % removeTerms(Markup(self.github.render_markdown(file.decoded_content)), terms) + return Markup("
%s
" % removeTerms(self.github.render_markdown(file.decoded_content), terms)) if ".jpg" in file.name or ".png" in file.name or ".png" in file.name or ".gif" in file.name: return Markup("%s" % (file.url, file.name)) if ".html" in file.name: return removeTerms(Markup(file.decoded_content), terms) - if ".txt" in file.name or ".java" in file.name or ".py" in file.name: + if ".txt" in file.name or ".log" in file.name or ".xml" in file.name or ".java" in file.name or ".py" in file.name: return removeTerms(Markup("
" + file.decoded_content + "
"), terms) return Markup("Download %s" % (file.url, file.name)) @@ -78,17 +78,24 @@ class Anonymous_Github: if repo[-1] == '/': repo = repo[:-1] g_repo = self.github.get_repo(repo) - current_folder = g_repo.get_contents(path) + current_folder = g_repo.get_contents(urllib.quote(path)) current_file = None if type(current_folder) is github.ContentFile.ContentFile: current_file = current_folder - current_folder = g_repo.get_contents(os.path.dirname(path)) + current_folder = g_repo.get_contents(urllib.quote(os.path.dirname(path))) else: for f in current_folder: if f.name.lower() == "readme.md" or f.name.lower() == "index.html": current_file = f break - return render_template('repo.html', terms=data["terms"], current_repository=id, current_file=current_file, current_folder=current_folder) + + return render_template('repo.html', + name=data['name'], + terms=data["terms"], + current_repository=id, + current_file=current_file, + current_folder=current_folder, + path=path.split("/") if path != '' else []) @application.route('/', methods=['GET']) def index(): @@ -98,15 +105,17 @@ class Anonymous_Github: def add_repository(): id = str(uuid.uuid4()) repo = request.form['githubRepository'] - terms = request.form['terms'] + terms = request.form['terms'], + repo_name = request.form['name'] config_path = self.config_dir + "/" + str(id) os.mkdir(config_path) with open(config_path + "/config.json", 'w') as outfile: json.dump({ "id": id, + "name": repo_name, "repository": repo, - "terms": terms.split("\n") + "terms": terms.split() }, outfile) return redirect(url_for('repository', id=id)) diff --git a/static/css/style.css b/static/css/style.css new file mode 100644 index 0000000..6958f8e --- /dev/null +++ b/static/css/style.css @@ -0,0 +1,41 @@ +.main { + width: 80%; + margin: auto; +} + +.files { + border: 1px solid #dddddd; + border-bottom: initial; + margin: 15px; + border-radius: 5px; +} + +.files a { + display: block; + padding: 9px; +} + +.files .file, .files .dir, .files .parent_folder { + border-bottom: 1px solid #dddddd; +} + +.files .file.active, .files .file:hover, .files .dir:hover, .files .parent_folder:hover { + background: #f0f0f0; +} + +.paths { + margin: 15px; + border: 1px solid #dddddd; + border-radius: 5px; + padding: 8px +} + +.paths a { + color: #000000; +} + +.paths .path::after { + content: '/'; + color: #dddddd; + padding-left: 4px; +} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 11536f0..9227cbf 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,23 +7,32 @@ + + -
-

GihHub Anonymous

-
-
- - - The github url to the repository that you want to anonymous. -
-
- - - One term per line. -
- -
+
+
+

GihHub Anonymous

+
+
+ + + The anonymous name of the repository. +
+
+ + + The github url to the repository that you want to anonymous. +
+
+ + + One term per line. +
+ +
+
diff --git a/templates/repo.html b/templates/repo.html index a68cb06..fde0b03 100644 --- a/templates/repo.html +++ b/templates/repo.html @@ -9,21 +9,31 @@ + + -
- - - {% for item in current_folder %} - - - +
+
+
+ {% set current_path = '/repository/' + current_repository %} + {{ name }} + {% for item in path %} + {% set current_path = current_path + "/" + item %} + {{ item }} {% endfor %} -
-
{{ item.name }}
- {% if current_file %} - {{ current_file|file_render(terms) }} - {% endif %} +
+
+ {% for item in current_folder %} + + {% endfor %} +
+ {% if current_file %} + {{ current_file|file_render(terms) }} + {% endif %} +