Stuff
This commit is contained in:
parent
1f1e4997fa
commit
f1165f2c51
@ -107,7 +107,7 @@ async function displayList(data, elementId, deleteFunction) {
|
|||||||
if ("function" === typeof deleteFunction) {
|
if ("function" === typeof deleteFunction) {
|
||||||
const th = document.createElement("th");
|
const th = document.createElement("th");
|
||||||
let deleteBtn = document.createElement('i');
|
let deleteBtn = document.createElement('i');
|
||||||
deleteBtn.classList = "ri-delete-bin-line";
|
deleteBtn.classList[0] = "ri-delete-bin-line";
|
||||||
th.appendChild(deleteBtn);
|
th.appendChild(deleteBtn);
|
||||||
headerRow.appendChild(th);
|
headerRow.appendChild(th);
|
||||||
}
|
}
|
||||||
@ -559,8 +559,9 @@ function uploadFile() {
|
|||||||
|
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
const respData = JSON.parse(xhr.responseText);
|
const respData = JSON.parse(xhr.responseText);
|
||||||
handleResponse(resp, "Súbor bol úspešne nahraný", "Nastala chyba pri nahrávaní súboru");
|
handleResponse(respData, "Súbor bol úspešne nahraný", "Nastala chyba pri nahrávaní súboru").then(() => {
|
||||||
fileInput.reset();
|
fileInput.reset();
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
@ -574,6 +575,7 @@ function deleteFile(fileID) {
|
|||||||
let xhr = new XMLHttpRequest();
|
let xhr = new XMLHttpRequest();
|
||||||
xhr.open('POST', '/upload', true);
|
xhr.open('POST', '/upload', true);
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
|
// noinspection JSIgnoredPromiseFromCall
|
||||||
listFiles();
|
listFiles();
|
||||||
};
|
};
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
@ -583,14 +585,13 @@ async function getFileList() {
|
|||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append('action', 'getAllFiles');
|
formData.append('action', 'getAllFiles');
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch('/upload', {
|
const response = await fetch('/upload', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Network response was not ok');
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const resp = await response.json();
|
const resp = await response.json();
|
||||||
@ -600,15 +601,12 @@ async function getFileList() {
|
|||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listFiles() {
|
async function listFiles() {
|
||||||
const fileList = await getFileList();
|
const fileList = await getFileList();
|
||||||
if (fileList) {
|
if (fileList) {
|
||||||
displayList(fileList, "filelist", deleteFile);
|
await displayList(fileList, "filelist", deleteFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,10 +624,11 @@ function addMeme() {
|
|||||||
xhr.open('POST', '/meme', true);
|
xhr.open('POST', '/meme', true);
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
const resp = JSON.parse(xhr.responseText);
|
const resp = JSON.parse(xhr.responseText);
|
||||||
handleResponse(resp, "Meme bol pridaný", "Nastala chyba pri pridávaní meme-u");
|
handleResponse(resp, "Meme bol pridaný", "Nastala chyba pri pridávaní meme-u").then(() => {
|
||||||
memeTitleElement.reset();
|
memeTitleElement.reset();
|
||||||
memeTextElement.reset();
|
memeTextElement.reset();
|
||||||
memeImageElement.reset();
|
memeImageElement.reset();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
}
|
}
|
||||||
|
@ -344,7 +344,7 @@ div#articleslist>article{
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-containe {
|
.form-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ function endpoint($endpoint_data): array
|
|||||||
"uploadFiles" => parseIncomingFiles(),
|
"uploadFiles" => parseIncomingFiles(),
|
||||||
"deleteFile" => deleteFile($endpoint_data['file_id']),
|
"deleteFile" => deleteFile($endpoint_data['file_id']),
|
||||||
"addToGroup" => addToGroup($endpoint_data['group_id'], $endpoint_data['file_id']),
|
"addToGroup" => addToGroup($endpoint_data['group_id'], $endpoint_data['file_id']),
|
||||||
"myFileExists" => fileExists($endpoint_data['file_id'], ),
|
"myFileExists" => fileExists($endpoint_data['file_id']),
|
||||||
"FileExists" => fileExists($endpoint_data['file_id'], false),
|
"FileExists" => fileExists($endpoint_data['file_id'], false),
|
||||||
default => ["Status" => "Fail", "message" => "Invalid action"],
|
default => ["Status" => "Fail", "message" => "Invalid action"],
|
||||||
};
|
};
|
||||||
|
@ -28,15 +28,12 @@ function getEndpoint($endpoint_name): string
|
|||||||
$output["Endpoint"] = $endpoint_name;
|
$output["Endpoint"] = $endpoint_name;
|
||||||
$type = gettype($output_tmp);
|
$type = gettype($output_tmp);
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case 'array':
|
||||||
case 'string':
|
case 'string':
|
||||||
$output = $output_tmp;
|
$output = $output_tmp;
|
||||||
$output['Status'] = 'Success';
|
$output['Status'] = 'Success';
|
||||||
break;
|
break;
|
||||||
case 'array':
|
case 'boolean':
|
||||||
$output = $output_tmp;
|
|
||||||
$output['Status'] = 'Success';
|
|
||||||
break;
|
|
||||||
case 'bool':
|
|
||||||
$output['Status'] = $output_tmp ? 'Success' : 'Fail';
|
$output['Status'] = $output_tmp ? 'Success' : 'Fail';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -18,6 +18,31 @@ function makePathSafe($userInput): string
|
|||||||
return substr($safeString, 0, 255);
|
return substr($safeString, 0, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function autoRotateImage(Imagick $imagick): void {
|
||||||
|
// Get the current orientation of the image
|
||||||
|
try {
|
||||||
|
$orientation = $imagick->getImageOrientation();
|
||||||
|
switch ($orientation) {
|
||||||
|
case Imagick::ORIENTATION_BOTTOMRIGHT: // upside down
|
||||||
|
$imagick->rotateimage("#000", 180); // rotate 180 degrees
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Imagick::ORIENTATION_RIGHTTOP: // 90 degrees CW
|
||||||
|
$imagick->rotateimage("#000", 90); // rotate 90 degrees CW
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Imagick::ORIENTATION_LEFTBOTTOM: // 90 degrees CCW
|
||||||
|
$imagick->rotateimage("#000", -90); // rotate 90 degrees CCW
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset orientation to normal after the correction
|
||||||
|
$imagick->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
|
||||||
|
} catch (ImagickException) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function getIncomingFiles(): array
|
function getIncomingFiles(): array
|
||||||
{
|
{
|
||||||
$files = $_FILES;
|
$files = $_FILES;
|
||||||
@ -60,10 +85,11 @@ function doImageUpload($inFile, $outFile): bool
|
|||||||
try {
|
try {
|
||||||
$imagick = new Imagick($inFile);
|
$imagick = new Imagick($inFile);
|
||||||
$imagick->setImageFormat('webp');
|
$imagick->setImageFormat('webp');
|
||||||
|
autoRotateImage($imagick);
|
||||||
$imagick->stripImage();
|
$imagick->stripImage();
|
||||||
$imagick->writeImage($outFile);
|
$imagick->writeImage($outFile);
|
||||||
$imagick->destroy();
|
$imagick->destroy();
|
||||||
} catch (ImagickException $e) {
|
} catch (ImagickException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the reencoding was successful
|
// Check if the reencoding was successful
|
||||||
@ -225,20 +251,7 @@ function addToGroup(int $groupId, int $fileId): array
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getImageURL(int $imageFileID): string
|
function deleteFile(int $fileID): array
|
||||||
{
|
|
||||||
global $mysqli;
|
|
||||||
$path = "";
|
|
||||||
$stmtget = $mysqli->prepare('SELECT Path FROM Files WHERE ID = ?');
|
|
||||||
$stmtget->bind_param('i', $imageFileID);
|
|
||||||
$stmtget->execute();
|
|
||||||
$stmtget->bind_result($path);
|
|
||||||
$stmtget->fetch();
|
|
||||||
return $path;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteFile(int $fileID): string
|
|
||||||
{
|
{
|
||||||
global $mysqli;
|
global $mysqli;
|
||||||
$out = ["Status" => "Fail"];
|
$out = ["Status" => "Fail"];
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<p class='meme_author'><i class="ri-user-line"></i>__TEMPLATE_MEME_AUTHOR__</p>
|
<p class='meme_author'><i class="ri-user-line"></i>__TEMPLATE_MEME_AUTHOR__</p>
|
||||||
__TEMPLATE_MEME_DELETE_BUTTON__
|
__TEMPLATE_MEME_DELETE_BUTTON__
|
||||||
<p class='meme_date'><i class="ri-calendar-line"></i>__TEMPLATE_MEME_DATE__</p>
|
<p class='meme_date'><i class="ri-calendar-line"></i>__TEMPLATE_MEME_DATE__</p>
|
||||||
<img src="__TEMPLATE_MEME_IMAGE__" width="500" class="meme_image">
|
<img src="__TEMPLATE_MEME_IMAGE__" width="500" alt="meme image" class="meme_image">
|
||||||
<p class="meme_text">__TEMPLATE_MEME_TEXT__</p>
|
<p class="meme_text">__TEMPLATE_MEME_TEXT__</p>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
Loading…
Reference in New Issue
Block a user