Stuff
This commit is contained in:
parent
1f1e4997fa
commit
f1165f2c51
@ -107,7 +107,7 @@ async function displayList(data, elementId, deleteFunction) {
|
||||
if ("function" === typeof deleteFunction) {
|
||||
const th = document.createElement("th");
|
||||
let deleteBtn = document.createElement('i');
|
||||
deleteBtn.classList = "ri-delete-bin-line";
|
||||
deleteBtn.classList[0] = "ri-delete-bin-line";
|
||||
th.appendChild(deleteBtn);
|
||||
headerRow.appendChild(th);
|
||||
}
|
||||
@ -559,8 +559,9 @@ function uploadFile() {
|
||||
|
||||
xhr.onload = function () {
|
||||
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();
|
||||
})
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
@ -574,6 +575,7 @@ function deleteFile(fileID) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/upload', true);
|
||||
xhr.onload = function () {
|
||||
// noinspection JSIgnoredPromiseFromCall
|
||||
listFiles();
|
||||
};
|
||||
xhr.send(formData);
|
||||
@ -583,14 +585,13 @@ async function getFileList() {
|
||||
let formData = new FormData();
|
||||
formData.append('action', 'getAllFiles');
|
||||
|
||||
try {
|
||||
const response = await fetch('/upload', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
return false;
|
||||
}
|
||||
|
||||
const resp = await response.json();
|
||||
@ -600,15 +601,12 @@ async function getFileList() {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function listFiles() {
|
||||
const fileList = await getFileList();
|
||||
if(fileList){
|
||||
displayList(fileList, "filelist", deleteFile);
|
||||
if (fileList) {
|
||||
await displayList(fileList, "filelist", deleteFile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -626,10 +624,11 @@ function addMeme() {
|
||||
xhr.open('POST', '/meme', true);
|
||||
xhr.onload = function () {
|
||||
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();
|
||||
memeTextElement.reset();
|
||||
memeImageElement.reset();
|
||||
});
|
||||
};
|
||||
xhr.send(formData);
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ div#articleslist>article{
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.form-containe {
|
||||
.form-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ function endpoint($endpoint_data): array
|
||||
"uploadFiles" => parseIncomingFiles(),
|
||||
"deleteFile" => deleteFile($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),
|
||||
default => ["Status" => "Fail", "message" => "Invalid action"],
|
||||
};
|
||||
|
@ -28,15 +28,12 @@ function getEndpoint($endpoint_name): string
|
||||
$output["Endpoint"] = $endpoint_name;
|
||||
$type = gettype($output_tmp);
|
||||
switch ($type) {
|
||||
case 'array':
|
||||
case 'string':
|
||||
$output = $output_tmp;
|
||||
$output['Status'] = 'Success';
|
||||
break;
|
||||
case 'array':
|
||||
$output = $output_tmp;
|
||||
$output['Status'] = 'Success';
|
||||
break;
|
||||
case 'bool':
|
||||
case 'boolean':
|
||||
$output['Status'] = $output_tmp ? 'Success' : 'Fail';
|
||||
break;
|
||||
default:
|
||||
|
@ -18,6 +18,31 @@ function makePathSafe($userInput): string
|
||||
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
|
||||
{
|
||||
$files = $_FILES;
|
||||
@ -60,10 +85,11 @@ function doImageUpload($inFile, $outFile): bool
|
||||
try {
|
||||
$imagick = new Imagick($inFile);
|
||||
$imagick->setImageFormat('webp');
|
||||
autoRotateImage($imagick);
|
||||
$imagick->stripImage();
|
||||
$imagick->writeImage($outFile);
|
||||
$imagick->destroy();
|
||||
} catch (ImagickException $e) {
|
||||
} catch (ImagickException) {
|
||||
}
|
||||
|
||||
// Check if the reencoding was successful
|
||||
@ -225,20 +251,7 @@ function addToGroup(int $groupId, int $fileId): array
|
||||
return $output;
|
||||
}
|
||||
|
||||
function getImageURL(int $imageFileID): string
|
||||
{
|
||||
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
|
||||
function deleteFile(int $fileID): array
|
||||
{
|
||||
global $mysqli;
|
||||
$out = ["Status" => "Fail"];
|
||||
|
@ -4,7 +4,7 @@
|
||||
<p class='meme_author'><i class="ri-user-line"></i>__TEMPLATE_MEME_AUTHOR__</p>
|
||||
__TEMPLATE_MEME_DELETE_BUTTON__
|
||||
<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>
|
||||
</div>
|
||||
</article>
|
Loading…
Reference in New Issue
Block a user