forked from MarseyWorld/MarseyWorld
save images only + improvements
parent
4fbab6a6be
commit
74f55162e5
|
@ -518,9 +518,11 @@ function handle_files(input, newfiles) {
|
||||||
if (location.pathname.endsWith('/submit')) {
|
if (location.pathname.endsWith('/submit')) {
|
||||||
files_b64 = JSON.parse(localStorage.getItem("files_b64")) || [];
|
files_b64 = JSON.parse(localStorage.getItem("files_b64")) || [];
|
||||||
for (const file of newfiles) {
|
for (const file of newfiles) {
|
||||||
|
if (!file.type.startsWith('image/'))
|
||||||
|
continue
|
||||||
fileReader = new FileReader();
|
fileReader = new FileReader();
|
||||||
fileReader.onload = function () {
|
fileReader.onload = function () {
|
||||||
files_b64.push([this.filename, this.result]);
|
files_b64.push([file.name, file.type, this.result]);
|
||||||
localStorage.setItem("files_b64", JSON.stringify(files_b64));
|
localStorage.setItem("files_b64", JSON.stringify(files_b64));
|
||||||
savetext()
|
savetext()
|
||||||
};
|
};
|
||||||
|
@ -537,23 +539,24 @@ if (file_upload) {
|
||||||
function process_url_image() {
|
function process_url_image() {
|
||||||
if (file_upload.files)
|
if (file_upload.files)
|
||||||
{
|
{
|
||||||
const filename = file_upload.files[0].name
|
const file = file_upload.files[0]
|
||||||
file_upload.previousElementSibling.textContent = filename.substr(0, 50);
|
file_upload.previousElementSibling.textContent = file.name.substr(0, 50);
|
||||||
for (const s of document.getElementById('IMAGE_FORMATS').value.split(','))
|
if (file.type.startsWith('image/')) {
|
||||||
{
|
const fileReader = new FileReader();
|
||||||
if (filename.toLowerCase().endsWith(s)) {
|
fileReader.readAsDataURL(file_upload.files[0]);
|
||||||
const fileReader = new FileReader();
|
fileReader.onload = function () {
|
||||||
fileReader.readAsDataURL(file_upload.files[0]);
|
document.getElementById('image-preview').setAttribute('src', this.result);
|
||||||
fileReader.onload = function () {
|
const str = JSON.stringify([file.name, file.type, this.result])
|
||||||
document.getElementById('image-preview').setAttribute('src', this.result);
|
localStorage.setItem("attachment_b64", str);
|
||||||
const str = JSON.stringify([filename, this.result])
|
document.getElementById('image-preview').classList.remove('d-none');
|
||||||
localStorage.setItem("attachment_b64", str);
|
document.getElementById('image-preview').classList.add('mr-2');
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
document.getElementById('image-preview').nextElementSibling.classList.add('mt-3');
|
||||||
document.getElementById('image-preview').classList.add('mr-2');
|
};
|
||||||
document.getElementById('image-preview').nextElementSibling.classList.add('mt-3');
|
}
|
||||||
};
|
else {
|
||||||
break;
|
document.getElementById('image-preview').classList.add('d-none');
|
||||||
}
|
document.getElementById('image-preview').classList.remove('mr-2');
|
||||||
|
document.getElementById('image-preview').nextElementSibling.classList.remove('mt-3');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof checkForRequired === "function") {
|
if (typeof checkForRequired === "function") {
|
||||||
|
|
|
@ -221,9 +221,9 @@ function submit(form) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function array_to_file(array) {
|
async function array_to_file(array) {
|
||||||
const res = await fetch(array[1]);
|
const res = await fetch(array[2]);
|
||||||
const blob = await res.blob();
|
const blob = await res.blob();
|
||||||
return new File([blob], array[0], { type: 'image/png' });
|
return new File([blob], array[0], {type: array[1]});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function restore_attachment() {
|
async function restore_attachment() {
|
||||||
|
|
Loading…
Reference in New Issue