FileAPI + Frontend
This commit is contained in:
@@ -100,7 +100,7 @@ namespace Api\File {
|
||||
$res = $sql->select("UserFile.uid", "valid_until", "token_type", "maxFiles", "maxSize", "extensions", "name", "path", "directory")
|
||||
->from("UserFileToken")
|
||||
->leftJoin("UserFileTokenFile", "UserFileToken.uid", "token_id")
|
||||
->innerJoin("UserFile", "UserFile.uid", "file_id")
|
||||
->leftJoin("UserFile", "UserFile.uid", "file_id")
|
||||
->where(new Compare("token", $token))
|
||||
->where(new Compare("valid_until", $sql->now(), ">"))
|
||||
->execute();
|
||||
@@ -120,20 +120,22 @@ namespace Api\File {
|
||||
|
||||
$this->result["files"] = array();
|
||||
foreach ($res as $row) {
|
||||
$file = array(
|
||||
"isDirectory" => $row["directory"],
|
||||
"name" => $row["name"],
|
||||
"uid" => $row["uid"]
|
||||
);
|
||||
if ($row["uid"]) {
|
||||
$file = array(
|
||||
"isDirectory" => $row["directory"],
|
||||
"name" => $row["name"],
|
||||
"uid" => $row["uid"]
|
||||
);
|
||||
|
||||
if ($file["isDirectory"]) {
|
||||
$file["items"] = array();
|
||||
} else {
|
||||
$file["size"] = @filesize($row["path"]);
|
||||
$file["mimeType"] = @mime_content_type($row["path"]);
|
||||
if ($file["isDirectory"]) {
|
||||
$file["items"] = array();
|
||||
} else {
|
||||
$file["size"] = @filesize($row["path"]);
|
||||
$file["mimeType"] = @mime_content_type($row["path"]);
|
||||
}
|
||||
|
||||
$this->result["files"][] = $file;
|
||||
}
|
||||
|
||||
$this->result["files"][] = $file;
|
||||
}
|
||||
|
||||
if ($row["token_type"] === "upload") {
|
||||
@@ -314,6 +316,8 @@ namespace Api\File {
|
||||
unset($row["maxSize"]);
|
||||
unset($row["extensions"]);
|
||||
}
|
||||
unset($row["token_type"]);
|
||||
$row["type"] = $tokenType;
|
||||
$this->result["tokens"][] = $row;
|
||||
}
|
||||
}
|
||||
@@ -464,8 +468,12 @@ namespace Api\File {
|
||||
foreach ($_FILES as $key => $file) {
|
||||
$fileName = $file["name"];
|
||||
$tmpPath = $file["tmp_name"];
|
||||
$md5Hash = hash_file('md5', $tmpPath);
|
||||
$sha1Hash = hash_file('sha1', $tmpPath);
|
||||
if (!$tmpPath) {
|
||||
return $this->createError("Error uploading file: $fileName");
|
||||
}
|
||||
|
||||
$md5Hash = @hash_file('md5', $tmpPath);
|
||||
$sha1Hash = @hash_file('sha1', $tmpPath);
|
||||
$filePath = $uploadDir . "/" . $md5Hash . $sha1Hash;
|
||||
if (move_uploaded_file($tmpPath, $filePath)) {
|
||||
$res = $sql->insert("UserFile", array("name", "directory", "path", "user_id", "parent_id"))
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Documents {
|
||||
namespace Documents\Files {
|
||||
|
||||
use Elements\Head;
|
||||
use Elements\Script;
|
||||
use Elements\SimpleBody;
|
||||
|
||||
class FilesHead extends Head {
|
||||
@@ -54,6 +55,7 @@ namespace Documents\Files {
|
||||
protected function getContent() {
|
||||
$html = "<noscript>" . $this->createErrorText("Javascript is required for this site to render.") . "</noscript>";
|
||||
$html .= "<div id=\"root\"></div>";
|
||||
$html .= new Script(Script::MIME_TEXT_JAVASCRIPT, Script::FILES);
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class Script extends StaticView {
|
||||
const INSTALL = "/js/install.js";
|
||||
const BOOTSTRAP = "/js/bootstrap.bundle.min.js";
|
||||
const ACCOUNT = "/js/account.js";
|
||||
const FILES = "/js/files.min.js";
|
||||
|
||||
private string $type;
|
||||
private string $content;
|
||||
|
||||
Reference in New Issue
Block a user