1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

Reader mode param in URL

This commit is contained in:
ksamuel 2020-08-14 11:18:59 +02:00
parent d133494e9d
commit 6bf5333b14
2 changed files with 32 additions and 9 deletions

View File

@ -101,9 +101,9 @@ class Paste(object):
expiration = datetime.strptime(expiration, "%Y-%m-%d %H:%M:%S.%f")
except StopIteration:
raise TypeError(to_ascii("File %s is malformed" % path))
raise TypeError("File %s is malformed" % path)
except (IOError, OSError):
raise ValueError(to_ascii("Can not open paste from file %s" % path))
raise ValueError("Can not open paste from file %s" % path)
return Paste(uuid=uuid, expiration=expiration, content=content)
@ -230,10 +230,13 @@ class Paste(object):
os.remove(self.path)
@classmethod
def iter_all(cls):
def iter_all(cls, on_error=lambda e: e):
for p in settings.PASTE_FILES_ROOT.rglob("*"):
if p.is_file() and "counter" not in str(p):
yield Paste.load_from_file(p)
try:
yield Paste.load_from_file(p)
except (TypeError, ValueError) as e:
on_error(e)
@property
def has_expired(self):

View File

@ -45,6 +45,8 @@ const app = new Vue({
clipboard: !!(isSecureContext && navigator.clipboard && navigator.clipboard.writeText),
URLSearchParams: !!window.URLSearchParams,
localStorage: (function () {
var val = !!(localStorage);
document.querySelector('html').classList.add((val ? '' : 'no-') + 'local-storage');
@ -68,13 +70,21 @@ const app = new Vue({
},
methods: {
// handleDownload: function () {
// this.$refs.downloadLink.dispatchEvent(new Event("click"));
// },
toggleReaderMode: function () {
debugger;
if (!this.readerMode) {
this.messages = [];
if (this.support.URLSearchParams) {
var searchParams = new URLSearchParams(window.location.search)
searchParams.set('readerMode', 1);
window.location.search = searchParams.toString();
}
} else {
if (this.support.URLSearchParams) {
var searchParams = new URLSearchParams(window.location.search);
searchParams.delete('readerMode');
window.location.search = searchParams.toString();
}
}
this.readerMode = !this.readerMode;
@ -391,6 +401,7 @@ window.zerobin = {
doneCallback(content);
}
} catch (err) {
debugger;
errorCallback(err);
}
@ -738,6 +749,8 @@ if (content && key) {
/* When done */
function (content) {
let readerMode = false;
if (content.indexOf('data:image') == 0) {
// Display Image
@ -773,6 +786,10 @@ if (content && key) {
url: "data:text/html;charset=UTF-8," + content
}
if (app.support.URLSearchParams) {
readerMode = (new URLSearchParams(window.location.search)).get('readerMode');
}
}
bar.set('Code coloration...', '95%');
@ -781,7 +798,7 @@ if (content && key) {
/** Syntaxic coloration */
if (zerobin.isCode(content) > 100) {
if (zerobin.isCode(content) > 100 && !readerMode) {
document.getElementById('paste-content').classList.add('linenums');
prettyPrint();
} else {
@ -805,6 +822,9 @@ if (content && key) {
form.forEach((node) => node.disabled = false);
content = '';
if (readerMode) {
app.toggleReaderMode()
}
}, 100);