This repository has been archived by the owner on Dec 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
64 lines (49 loc) · 1.42 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from flask import Flask, send_file
import time
import os.path
import pykpathsea
import re
import os
startup_time = time.time()
cache_db = {}
app = Flask(__name__)
regex = re.compile(r'[^a-zA-Z0-9 _\-\.]')
@app.route('/')
def index():
htmlString = "<iframe src='https://www.tug.org/texlive/' style='border:0;width: 100%; height: 95%'></iframe>"
for key in cache_db:
htmlString += "<div>%s</div>"%(key)
return htmlString
@app.route('/tex/<filename>')
def fetch_file(filename):
if len(cache_db) > 102400:
cache_db.clear()
if filename == "xmllatex.fmt" or filename == "pdflatexori.fmt": #Dont do kpathsea search
if os.path.exists(filename):
return send_file(filename)
else:
return "Format File not found", 301
if filename not in cache_db:
fast_search_file(filename)
if cache_db[filename] == "none":
return "File not found", 301
else:
urls = cache_db[filename]
return send_file(urls)
def san(name):
return regex.sub('', name)
def fast_search_file(name):
res = pykpathsea.find_file(san(name))
if res is None or not os.path.isfile(res):
cache_db[name] = "none"
return -1
else:
cache_db[name] = res
return 0
# @cross_origin()
# @app.route('/upload', methods=['POST'])
# def upload():
# f = open("test.fmt", "wb")
# f.write(request.data)
# f.close()
# return "/"