mobi ios workaround, improve style up recieve page

This commit is contained in:
daniel-j
2023-12-06 15:00:41 +01:00
parent 78e5d79ca8
commit 77173960ca
4 changed files with 98 additions and 27 deletions

View File

@@ -4,7 +4,7 @@
<title>Send to Kobo/Kindle</title> <title>Send to Kobo/Kindle</title>
<meta charset="utf-8"/> <meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" type="text/css" href="/style.css"/> <link rel="stylesheet" type="text/css" href="/style.css?l"/>
</head> </head>
<body> <body>
@@ -12,25 +12,40 @@
<h1 class="center">Send to Kobo/Kindle</h1> <h1 class="center">Send to Kobo/Kindle</h1>
<div class="center"> <div class="center">
<div style="font-size: 1.4em;">Unique key:</div> <div style="font-size: 1.3em;">Unique key:</div>
<div id="key"></div> <div id="key">
<br/> <span id="keyoutput"></span>
<button id="keygen">Generate new key</button> <button id="keygen" title="Generate new key">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path d="M19.146 4.854l-1.489 1.489A8 8 0 1 0 12 20a8.094 8.094 0 0 0 7.371-4.886 1 1 0 1 0-1.842-.779A6.071 6.071 0 0 1 12 18a6 6 0 1 1 4.243-10.243l-1.39 1.39a.5.5 0 0 0 .354.854H19.5A.5.5 0 0 0 20 9.5V5.207a.5.5 0 0 0-.854-.353z"/>
</svg>
</button>
</div> </div>
<br/> <br/>
</div>
<div class="center" id="downloads">
<div style="font-size: 1.3em;"><em>Downloads</em></div>
<br/>
<div><a id="downloadlink"></a></div>
<br/>
</div>
<hr/> <hr/>
<br/> <br/>
<div class="center" id="downloads"> <div class="center">
<a id="downloadlink"></a> Visit this on other devices to send ebooks to this ereader:<br/><a id="siteurl">https://send.djazz.se</a><br/>
<br/>
Created by djazz. Source code on <a href="https://github.com/daniel-j/send2ereader" target="_blank">Github</a><br/>
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var keyOutput = document.getElementById('key') var keyOutput = document.getElementById('keyoutput')
var keyGenBtn = document.getElementById('keygen') var keyGenBtn = document.getElementById('keygen')
var downloads = document.getElementById('downloads') var downloads = document.getElementById('downloads')
var downloadlink = document.getElementById('downloadlink') var downloadlink = document.getElementById('downloadlink')
var siteurl = document.getElementById('siteurl')
var key = null var key = null
var pollTimer = null var pollTimer = null
@@ -97,6 +112,10 @@ window.onload = function () {
generateKey() generateKey()
} }
siteurl.textContent = window.location.origin
siteurl.href = siteurl.textContent
siteurl.target = '_self'
</script> </script>
</body> </body>
</html> </html>

View File

@@ -97,7 +97,7 @@ const upload = multer({
cb(null, false) cb(null, false)
return return
} }
if (!allowedTypes.includes(file.mimetype) || !allowedExtensions.includes(extname(file.originalname.toLowerCase()).substr(1))) { if (!allowedTypes.includes(file.mimetype) || !allowedExtensions.includes(extname(file.originalname.toLowerCase()).substring(1))) {
console.error('FileFilter: File is of an invalid type ', file) console.error('FileFilter: File is of an invalid type ', file)
cb(null, false) cb(null, false)
return return
@@ -198,7 +198,7 @@ router.post('/upload', upload.single('file'), async ctx => {
const type = await FileType.fromFile(ctx.request.file.path) const type = await FileType.fromFile(ctx.request.file.path)
if (!type || !allowedTypes.includes(type.mime)) { if ((!type || !allowedTypes.includes(type.mime)) && !allowedTypes.includes(mimetype)) {
flash(ctx, { flash(ctx, {
message: 'Uploaded file is of an invalid type: ' + ctx.request.file.originalname + ' (' + (type? type.mime : 'unknown mimetype') + ')', message: 'Uploaded file is of an invalid type: ' + ctx.request.file.originalname + ' (' + (type? type.mime : 'unknown mimetype') + ')',
success: false, success: false,

View File

@@ -14,14 +14,15 @@ h1 {
font-weight: normal; font-weight: normal;
font-style: italic; font-style: italic;
} }
#key { #keyoutput {
font-size: 5em; font-size: 5em;
display: block; display: inline-block;
letter-spacing: 0.2em; letter-spacing: 0.2em;
margin: 10px 0; margin: 10px 0;
font-family: sans-serif; font-family: monospace, sans-serif;
white-space: nowrap; white-space: nowrap;
text-transform: uppercase; text-transform: uppercase;
vertical-align: middle;
} }
.center { .center {
text-align: center; text-align: center;
@@ -39,11 +40,23 @@ h1 {
display: inline-block; display: inline-block;
font-family: inherit; font-family: inherit;
font-size: 1.2em; font-size: 1.2em;
margin: 0 0.5em;
vertical-align: middle;
}
#keygen {
margin-left: 1em;
margin-right: -4.7em;
padding: 1em;
} }
#keygen:focus { #keygen:focus {
background: black; background: black;
color: white; color: white;
} }
#keygen svg {
display: block;
width: 1.5em;
height: 1.5em;
}
#downloads { #downloads {
display: none; display: none;
} }

View File

@@ -14,7 +14,7 @@
<form action="/upload" method="post" enctype="multipart/form-data"> <form action="/upload" method="post" enctype="multipart/form-data">
<table style="margin: 0 auto;" cellpadding=0 cellspacing=0> <table style="margin: 0 auto;" cellpadding=0 cellspacing=0>
<tr><td class="right"><label for="keyinput">Unique key</label></td><td><input type="text" name="key" id="keyinput" autocomplete="off" pattern="...." placeholder="" required style="text-transform: uppercase;" maxlength=4/></td></tr> <tr><td class="right"><label for="keyinput">Unique key</label></td><td><input type="text" name="key" id="keyinput" autocomplete="off" pattern="...." placeholder="" required style="text-transform: uppercase;" maxlength=4/></td></tr>
<tr><td class="right"><label for="fileinput">EPUB/MOBI file</label></td><td><input type="file" name="file" id="fileinput" accept=".epub,.mobi,.pdf,.cbz,.cbr,application/epub+zip,application/x-mobipocket-ebook,application/pdf,application/vnd.comicbook+zip,application/vnd.comicbook-rar" required /></td></tr> <tr><td class="right"><label for="fileinput">EPUB/MOBI file</label></td><td><input type="file" name="file" id="fileinput" accept=".txt,.epub,.mobi,.pdf,.cbz,.cbr,application/epub+zip,application/x-mobipocket-ebook,application/pdf,application/vnd.comicbook+zip,application/vnd.comicbook-rar" required /></td></tr>
<tr><td></td><td id="fileinfo"></td></tr> <tr><td></td><td id="fileinfo"></td></tr>
<tr><td class="right"><label for="kepubify">Kepubify</label></td><td><input type="checkbox" name="kepubify" id="kepubify" checked /></td></tr> <tr><td class="right"><label for="kepubify">Kepubify</label></td><td><input type="checkbox" name="kepubify" id="kepubify" checked /></td></tr>
<tr><td></td><td><input type="submit" value="Upload and send" /></td></tr> <tr><td></td><td><input type="submit" value="Upload and send" /></td></tr>
@@ -33,6 +33,7 @@
Source code on <a href="https://github.com/daniel-j/send2ereader" target="_blank">Github</a> - <a id="siteurl">https://send.djazz.se</span> Source code on <a href="https://github.com/daniel-j/send2ereader" target="_blank">Github</a> - <a id="siteurl">https://send.djazz.se</span>
</div> </div>
</div> </div>
<script> <script>
function getCookies() { function getCookies() {
var cookieRegex = /([\w\.]+)\s*=\s*(?:"((?:\\"|[^"])*)"|(.*?))\s*(?:[;,]|$)/g var cookieRegex = /([\w\.]+)\s*=\s*(?:"((?:\\"|[^"])*)"|(.*?))\s*(?:[;,]|$)/g
@@ -51,12 +52,17 @@ function deleteCookie(name) {
document.cookie = name + "= ; expires = Thu, 01 Jan 1970 00:00:00 GMT" document.cookie = name + "= ; expires = Thu, 01 Jan 1970 00:00:00 GMT"
} }
var uploadstatus = document.getElementById('uploadstatus') var uploadstatus = document.getElementById('uploadstatus')
var keyinput = document.getElementById('keyinput') var keyinput = document.getElementById('keyinput')
var fileinput = document.getElementById('fileinput') var fileinput = document.getElementById('fileinput')
var fileinputAccept = fileinput.accept.split(',') // cache it
var fileinfo = document.getElementById('fileinfo') var fileinfo = document.getElementById('fileinfo')
var siteurl = document.getElementById('siteurl') var siteurl = document.getElementById('siteurl')
var isIOS = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
var flash = getCookies().flash var flash = getCookies().flash
deleteCookie('flash') deleteCookie('flash')
@@ -80,20 +86,53 @@ uploadstatus.addEventListener('click', function () {
uploadstatus.className = '' uploadstatus.className = ''
}, 500) }, 500)
}, false) }, false)
function fileinputChange () { function fileinputChange () {
if (!fileinput.files[0]) { if (!fileinput.files[0] || fileinput.files.length === 0) {
fileinfo.textContent = '' fileinfo.textContent = ''
fileinput.value = ''
return return
} }
if (fileinput.accept == '') {
var filename = fileinput.files[0].name
var type = fileinput.files[0].type
var found = false
for (var i = 0; i < fileinputAccept.length; i++) {
var item = fileinputAccept[i]
if (item.length > 1 && item[0] == '.') {
if (filename.toLowerCase().endsWith(item.toLowerCase())) {
found = true
break
}
} else if (type == item) {
found = true
break
}
}
if (!found) {
fileinfo.textContent = ''
fileinput.value = ''
alert("Invalid file: " + filename)
return
}
}
fileinfo.textContent = Math.ceil(fileinput.files[0].size / 1024) + ' kB' fileinfo.textContent = Math.ceil(fileinput.files[0].size / 1024) + ' kB'
} }
fileinput.addEventListener('change', fileinputChange, false) fileinput.addEventListener('change', fileinputChange, false)
fileinputChange() fileinputChange()
siteurl.textContent = window.location.href if (isIOS) {
// Can't accept .mobi files otherwise (iOS thinks it's an unknown type)
fileinput.accept = ''
}
siteurl.textContent = window.location.origin
siteurl.href = siteurl.textContent siteurl.href = siteurl.textContent
siteurl.target = '_self' siteurl.target = '_self'
</script> </script>
</body> </body>
</html> </html>