From f9ad37b0c9e8638036b515d19a4b6bca67b178c7 Mon Sep 17 00:00:00 2001
From: mrilyew <99399973+mrilyew@users.noreply.github.com>
Date: Sun, 12 Jan 2025 15:46:26 +0300
Subject: [PATCH] add fast uploader
---
Web/Models/Entities/Document.php | 2 +-
Web/static/js/al_docs.js | 31 +++++++++++++++++++------------
2 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/Web/Models/Entities/Document.php b/Web/Models/Entities/Document.php
index 030ffe76..b5f15cb6 100644
--- a/Web/Models/Entities/Document.php
+++ b/Web/Models/Entities/Document.php
@@ -97,7 +97,7 @@ class Document extends Media
throw new ISE("File uploaded is corrupted");
$original_name = $file["name"];
- $file_format = explode(".", $original_name)[1];
+ $file_format = end(explode(".", $original_name));
$file_size = $file["size"];
$type = Document::detectTypeByFormat($file_format);
diff --git a/Web/static/js/al_docs.js b/Web/static/js/al_docs.js
index 2c3539ca..cb638568 100644
--- a/Web/static/js/al_docs.js
+++ b/Web/static/js/al_docs.js
@@ -1,4 +1,4 @@
-function showDocumentUploadDialog(target = null, append_to_url = null)
+function showDocumentUploadDialog(target = null, append_to_url = null, after_upload = null)
{
let file = null
const cmsg = new CMessageBox({
@@ -13,7 +13,7 @@ function showDocumentUploadDialog(target = null, append_to_url = null)
-
+
`,
buttons: [tr('close')],
@@ -25,7 +25,7 @@ function showDocumentUploadDialog(target = null, append_to_url = null)
cmsg.getNode().find('#upload_btn').on('change', (e) => {
file = e.target.files[0]
const name = file.name
- const format = name.split(".")[1]
+ const format = name.split(".")[name.split(".").length - 1]
if(window.openvk.docs_allowed.indexOf(format) == -1) {
makeError(tr("error_file_invalid_format"))
return
@@ -81,7 +81,12 @@ function showDocumentUploadDialog(target = null, append_to_url = null)
const json = await fetcher.json()
if(json.success) {
- window.router.route(location.href)
+ if(target != "search") {
+ window.router.route(location.href)
+ } else {
+ if(after_upload)
+ after_upload()
+ }
} else {
fastError(escapeHtml(json.flash.message))
}
@@ -317,13 +322,10 @@ async function __docAttachment(form, ctx = "wall", source = "user", source_arg =
${tr("select_doc")}
- ${source != "user" ?
- `
-
- ${tr("go_to_my_documents")}
-
- `
- : ""}
+
+ ${source != "user" ? `${tr("go_to_my_documents")}`: ""}
+ ${tr("upload_button")}
+
@@ -495,11 +497,16 @@ async function __docAttachment(form, ctx = "wall", source = "user", source_arg =
msg.close()
await __docAttachment(form, "wall")
})
+ msg.getNode().on("click", "#_doc_picker_upload", async (e) => {
+ showDocumentUploadDialog("search", source_arg >= 0 ? NaN : Math.abs(source_arg), () => {
+ docs_reciever.clean()
+ docs_reciever.page(1)
+ })
+ })
msg.getNode().on("change", ".attachment_search input", async (e) => {
await docs_reciever.search(ovk_proc_strtr(e.target.value, 100))
})
-
await docs_reciever.page(docs_reciever.stat.page + 1)
}
u(document).on('click', '#__documentAttachment', async (e) => {