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

Add batch paste methods and fix dl link glitch

This commit is contained in:
ksamuel 2020-08-14 10:07:36 +02:00
parent e37ed06a47
commit 9b2f9911f2
3 changed files with 25 additions and 11 deletions

View File

@ -228,3 +228,16 @@ class Paste(object):
Delete the paste file.
"""
os.remove(self.path)
@classmethod
def iter_all(cls):
for p in settings.PASTE_FILES_ROOT.rglob("*"):
if p.is_file() and "counter" not in str(p):
yield Paste.load_from_file(p)
@property
def has_expired(self):
try:
return self.expiration < datetime.now()
except TypeError:
return False

View File

@ -23,7 +23,6 @@ const app = new Vue({
el: '#app',
data: {
previousPastes: [],
downloadLink: {},
displayBottomToolBar: false,
openPreviousPastesMenu: false,
readerMode: false,
@ -32,7 +31,8 @@ const app = new Vue({
ownerKey: '',
id: '',
type: '',
content: ''
content: '',
downloadLink: {},
},
newPaste: {
expiration: '1_day',
@ -68,6 +68,10 @@ const app = new Vue({
},
methods: {
// handleDownload: function () {
// this.$refs.downloadLink.dispatchEvent(new Event("click"));
// },
toggleReaderMode: function () {
if (!this.readerMode) {
this.messages = [];
@ -753,7 +757,7 @@ if (content && key) {
let extension = /data:image\/([^;]+);base64/.exec(content)[1];
app.downloadLink = {
app.currentPaste.downloadLink = {
name: '0bin_' + document.location.pathname.split('/').pop() + '.' + extension,
url: content
}
@ -764,7 +768,7 @@ if (content && key) {
document.querySelector('#paste-content').innerText = content;
app.currentPaste.content = content
app.downloadLink = {
app.currentPaste.downloadLink = {
name: '0bin_' + document.location.pathname.split('/').pop() + ".txt",
url: "data:text/html;charset=UTF-8," + content
}

View File

@ -33,10 +33,8 @@
<div>
<span class="paste-option btn-group">
<button class="btn btn-clone btn-secondary" @click.prevent="handleClone()">Clone</button>
<button class="btn btn-secondary download-link" v-if="downloadLink.url">
<a :href="downloadLink.url" :download="downloadLink.name">Download</a>
</button>
<a class="btn btn-secondary download-link" :href="currentPaste.downloadLink.url"
:download="currentPaste.downloadLink.name">Download</a>
<button class="btn btn-secondary">New Paste</button>
</span>
</div>
@ -72,9 +70,8 @@
<span class="paste-option btn-group">
<button class="btn btn-clone btn-secondary" @click.prevent="handleClone()">Clone</button>
<button class="btn btn-secondary download-link" v-if="downloadLink.url">
<a :href="downloadLink.url" :download="downloadLink.name"> Download</a>
</button>
<a class="btn btn-secondary download-link" :href="currentPaste.downloadLink.url"
:download="currentPaste.downloadLink.name"> Download</a>
<button class="btn btn-secondary">New Paste</button>
</span>