From 638d6f987908f44766e1aa2f7fc4c566e0f63c04 Mon Sep 17 00:00:00 2001
From: lalka2016 <99399973+lalka2016@users.noreply.github.com>
Date: Wed, 20 Sep 2023 19:34:22 +0300
Subject: [PATCH] Fix graffiti and copypaste
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Какого-то хуя копипаста у постов срабатывает два раза.
---
Web/static/js/al_wall.js | 102 ++++++++++++++++++++++++---------------
locales/en.strings | 1 +
locales/ru.strings | 1 +
3 files changed, 66 insertions(+), 38 deletions(-)
diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js
index d3a18471..096a5e79 100644
--- a/Web/static/js/al_wall.js
+++ b/Web/static/js/al_wall.js
@@ -22,7 +22,7 @@ function trim(string) {
return newStr;
}
-function handleVideoTAreaUpdate(event, id) {
+/*function handleVideoTAreaUpdate(event, id) {
console.log(event, id);
let indicator = u("#post-buttons" + id + " .post-upload");
let file = event.target.files[0];
@@ -34,7 +34,7 @@ function handleVideoTAreaUpdate(event, id) {
}
document.querySelector("#post-buttons" + id + " #wallAttachmentMenu").classList.add("hidden");
-}
+}*/
function initGraffiti(id) {
let canvas = null;
@@ -43,16 +43,7 @@ function initGraffiti(id) {
let fName = "Graffiti-" + Math.ceil(performance.now()).toString() + ".jpeg";
let image = new File([blob], fName, {type: "image/jpeg", lastModified: new Date().getTime()});
- let formdata = new FormData()
- formdata.append("hash", u("meta[name=csrf]").attr("value"))
- formdata.append("count", 1)
-
- //ky.post("/photos/upload", {body:})
- let fileSelect = document.querySelector("#post-buttons" + id + " input[name='_pic_attachment']");
- fileSelect.files = trans.files;
-
- u(fileSelect).trigger("change");
- u("#post-buttons" + id + " #write textarea").trigger("focusin");
+ fastUploadImage(id, image)
}, "image/jpeg", 0.92);
canvas.teardown();
@@ -75,6 +66,61 @@ function initGraffiti(id) {
});
}
+function fastUploadImage(textareaId, file) {
+ // uploading images
+
+ let xhr = new XMLHttpRequest
+ let data = new FormData
+
+ data.append("photo_0", file)
+ data.append("count", 1)
+ data.append("hash", u("meta[name=csrf]").attr("value"))
+
+ xhr.open("POST", "/photos/upload")
+
+ xhr.onloadstart = () => {
+ document.querySelector("#post-buttons"+textareaId+" .upload").insertAdjacentHTML("beforeend", ``)
+ }
+
+ xhr.onload = () => {
+ let response = JSON.parse(xhr.responseText)
+
+ appendImage(response, textareaId)
+ }
+
+ xhr.send(data)
+}
+
+// append image after uploading via /photos/upload
+function appendImage(response, textareaId) {
+ if(!response.success) {
+ MessageBox(tr("error"), (tr("error_uploading_photo") + response.flash.message), [tr("ok")], [() => {Function.noop}])
+ } else {
+ let form = document.querySelector("#post-buttons"+textareaId)
+ let photosInput = form.querySelector("input[name='photos']")
+ let photosIndicator = form.querySelector(".upload")
+
+ for(const phot of response.photos) {
+ let id = phot.owner + "_" + phot.vid
+
+ photosInput.value += (id + ",")
+
+ u(photosIndicator).append(u(`
+