fix low register format chekc

This commit is contained in:
mrilyew 2025-01-16 21:32:56 +03:00
parent 43548f531b
commit a5aa09d554
2 changed files with 5 additions and 5 deletions

View file

@ -104,7 +104,7 @@ class Document extends Media
if(!$file_format) if(!$file_format)
throw new \TypeError("No file format"); throw new \TypeError("No file format");
if(!in_array($file_format, OPENVK_ROOT_CONF["openvk"]["preferences"]["docs"]["allowedFormats"])) if(!in_array(mb_strtolower($file_format), OPENVK_ROOT_CONF["openvk"]["preferences"]["docs"]["allowedFormats"]))
throw new \TypeError("Forbidden file format"); throw new \TypeError("Forbidden file format");
if($file_size < 1 || $file_size > (OPENVK_ROOT_CONF["openvk"]["preferences"]["docs"]["maxSize"] * 1024 * 1024)) if($file_size < 1 || $file_size > (OPENVK_ROOT_CONF["openvk"]["preferences"]["docs"]["maxSize"] * 1024 * 1024))
@ -112,8 +112,8 @@ class Document extends Media
$hash = hash_file("whirlpool", $file["tmp_name"]); $hash = hash_file("whirlpool", $file["tmp_name"]);
$this->stateChanges("original_name", ovk_proc_strtr($original_name, 255)); $this->stateChanges("original_name", ovk_proc_strtr($original_name, 255));
$this->tmp_format = $file_format; $this->tmp_format = mb_strtolower($file_format);
$this->stateChanges("format", $file_format); $this->stateChanges("format", mb_strtolower($file_format));
$this->stateChanges("filesize", $file_size); $this->stateChanges("filesize", $file_size);
$this->stateChanges("hash", $hash); $this->stateChanges("hash", $hash);
$this->stateChanges("access_key", bin2hex(random_bytes(9))); $this->stateChanges("access_key", bin2hex(random_bytes(9)));
@ -386,7 +386,7 @@ class Document extends Media
static function detectTypeByFormat(string $format) static function detectTypeByFormat(string $format)
{ {
switch($format) { switch(mb_strtolower($format)) {
case "txt": case "docx": case "doc": case "odt": case "pptx": case "ppt": case "xlsx": case "xls": case "md": case "txt": case "docx": case "doc": case "odt": case "pptx": case "ppt": case "xlsx": case "xls": case "md":
return 1; return 1;
case "zip": case "rar": case "7z": case "zip": case "rar": case "7z":

View file

@ -27,7 +27,7 @@ function showDocumentUploadDialog(target = null, append_to_url = null, after_upl
file = e.target.files[0] file = e.target.files[0]
const name = file.name const name = file.name
const format = name.split(".")[name.split(".").length - 1] const format = name.split(".")[name.split(".").length - 1]
if(window.openvk.docs_allowed.indexOf(format) == -1) { if(window.openvk.docs_allowed.indexOf(format.toLowerCase()) == -1) {
makeError(tr("error_file_invalid_format")) makeError(tr("error_file_invalid_format"))
return return
} }