Add qute://pdfjs/file to get files
Cross-origin requests aren't supported for qute:// URLs, and qute:// can't access file://, so we need to get the files that way.
This commit is contained in:
parent
8f19820a7a
commit
cb0c313404
@ -155,7 +155,13 @@ def should_use_pdfjs(mimetype):
|
||||
def get_main_url(filename):
|
||||
"""Get the URL to be opened to view a local PDF."""
|
||||
url = QUrl('qute://pdfjs/web/viewer.html')
|
||||
|
||||
file_url = QUrl('qute://pdfjs/file')
|
||||
file_url_query = QUrlQuery()
|
||||
file_url_query.addQueryItem('filename', filename)
|
||||
file_url.setQuery(file_url_query)
|
||||
|
||||
query = QUrlQuery()
|
||||
query.addQueryItem('file', QUrl.fromLocalFile(filename).toString())
|
||||
query.addQueryItem('file', file_url.toString())
|
||||
url.setQuery(query)
|
||||
return url
|
||||
|
@ -523,6 +523,16 @@ def qute_pastebin_version(_url):
|
||||
@add_handler('pdfjs')
|
||||
def qute_pdfjs(url):
|
||||
"""Handler for qute://pdfjs. Return the pdf.js viewer."""
|
||||
# FIXME be more strict about allowed files here
|
||||
if url.path() == '/file':
|
||||
filename = QUrlQuery(url).queryItemValue('filename')
|
||||
with open(filename, 'rb') as f:
|
||||
data = f.read()
|
||||
mimetype, _encoding = mimetypes.guess_type(filename)
|
||||
if mimetype is None:
|
||||
mimetype = 'application/octet-stream'
|
||||
return mimetype, data
|
||||
|
||||
try:
|
||||
data = pdfjs.get_pdfjs_res(url.path())
|
||||
except pdfjs.PDFJSNotFound as e:
|
||||
|
Loading…
Reference in New Issue
Block a user