mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-27 14:57:25 -05:00
find path for onionshare dir in cross-platform way
This commit is contained in:
parent
464567121e
commit
1f0fd734fa
@ -1,4 +1,4 @@
|
|||||||
import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue
|
import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect
|
||||||
from random import randint
|
from random import randint
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@ -13,8 +13,7 @@ class NoTor(Exception):
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
strings = {}
|
strings = {}
|
||||||
|
onionshare_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||||
# generate an unguessable string
|
|
||||||
slug = os.urandom(16).encode('hex')
|
slug = os.urandom(16).encode('hex')
|
||||||
|
|
||||||
# information about the file
|
# information about the file
|
||||||
@ -45,7 +44,7 @@ def add_request(type, path, data=None):
|
|||||||
def index():
|
def index():
|
||||||
global filename, filesize, filehash, slug, strings, REQUEST_LOAD
|
global filename, filesize, filehash, slug, strings, REQUEST_LOAD
|
||||||
add_request(REQUEST_LOAD, request.path)
|
add_request(REQUEST_LOAD, request.path)
|
||||||
return render_template_string(open('{0}/index.html'.format(os.path.dirname(__file__))).read(),
|
return render_template_string(open('{0}/index.html'.format(onionshare_dir)).read(),
|
||||||
slug=slug, filename=os.path.basename(filename), filehash=filehash, filesize=filesize, strings=strings)
|
slug=slug, filename=os.path.basename(filename), filehash=filehash, filesize=filesize, strings=strings)
|
||||||
|
|
||||||
@app.route("/{0}/download".format(slug))
|
@app.route("/{0}/download".format(slug))
|
||||||
@ -89,7 +88,7 @@ def download():
|
|||||||
def page_not_found(e):
|
def page_not_found(e):
|
||||||
global REQUEST_OTHER
|
global REQUEST_OTHER
|
||||||
add_request(REQUEST_OTHER)
|
add_request(REQUEST_OTHER)
|
||||||
return render_template_string(open('{0}/404.html'.format(os.path.dirname(__file__))).read())
|
return render_template_string(open('{0}/404.html'.format(onionshare_dir)).read())
|
||||||
|
|
||||||
def get_platform():
|
def get_platform():
|
||||||
p = platform.system()
|
p = platform.system()
|
||||||
@ -129,7 +128,7 @@ def load_strings(default="en"):
|
|||||||
try:
|
try:
|
||||||
translated = json.loads(open('{0}/strings.json'.format(os.getcwd())).read())
|
translated = json.loads(open('{0}/strings.json'.format(os.getcwd())).read())
|
||||||
except IOError:
|
except IOError:
|
||||||
translated = json.loads(open('{0}/strings.json'.format(os.path.dirname(__file__))).read())
|
translated = json.loads(open('{0}/strings.json'.format(onionshare_dir)).read())
|
||||||
strings = translated[default]
|
strings = translated[default]
|
||||||
lc, enc = locale.getdefaultlocale()
|
lc, enc = locale.getdefaultlocale()
|
||||||
if lc:
|
if lc:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user