Skip to content

Commit

Permalink
UwU
Browse files Browse the repository at this point in the history
  • Loading branch information
judemont committed Sep 26, 2024
1 parent f310eeb commit fc38296
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
13 changes: 13 additions & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>randomedia ADMIN</title>
</head>
<body>
<div id='content'></div>
<script src="../scripts/admin.js"></script>
<script src="scripts/moderation.js"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions api/recive_all.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$mediaDir = __DIR__ . '/../medias/';
$files = array_diff(scandir($mediaDir), ['.', '..']);

echo json_encode(['success' => true, 'files' => array_values($files)]);
?>
32 changes: 32 additions & 0 deletions scripts/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

document.addEventListener('DOMContentLoaded', () => {
const basePath = ".."
const apiPath = `${basePath}/api/recive_all.php`;
const mediaPath = `${basePath}/medias/`;

function fetchMedias() {
fetch(apiPath)
.then(response => response.json())
.then(data => {
let result = "";
if (data.success) {
console.log(data.files)
for (let i = 0; i < data.files.length; i++) {
const mediaUrl = mediaPath + data.files[i];
result += `
${data.files[i].endsWith('.mp4') ?
`<video width='100' height='100' controls><source src="${mediaUrl}" type="video/mp4">Your browser does not support the video tag.</video>` :
`<img width='100' height='100' src="${mediaUrl}" alt="Random Media">`}
<button onclick="removeMedia('medias/${data.files[i]}')">Remove</button>
`;
}
console.log(result)
document.getElementById("content").innerHTML = result

}
})
.catch(error => console.error('Stupid error :', error));
}

fetchMedias();
});
5 changes: 2 additions & 3 deletions scripts/moderation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function removeMedia() {
const mediaPath = localStorage.getItem("mediaPath");
function removeMedia(mediaPath) {
const adminPassword = prompt("Enter the admin password to remove this media:");
fetch("api/remove.php", {
fetch("../api/remove.php", {
method: 'POST',
body: objectToFormData({ mediaPath: mediaPath, adminPassword: adminPassword }),
}).catch(error => console.error('Error :', error));
Expand Down
1 change: 0 additions & 1 deletion scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ document.addEventListener('DOMContentLoaded', () => {
.then(response => response.json())
.then(data => {
if (data.success) {
localStorage.setItem("mediaPath", "medias/"+data.file);
const mediaUrl = mediaPath + data.file;
mediaDisplay.innerHTML = `
${data.file.endsWith('.mp4') ?
Expand Down

0 comments on commit fc38296

Please sign in to comment.