return same map id if it already has been uploaded

This commit is contained in:
Lee 2023-04-15 18:36:17 +01:00
parent 02d093e773
commit 5d35694d93
2 changed files with 28 additions and 13 deletions

@ -19,6 +19,18 @@
<meta name="twitter:description" content="Simple website to host WIP BeatSaber maps" /> <meta name="twitter:description" content="Simple website to host WIP BeatSaber maps" />
<meta property="theme-color" content="#4d3a9c" /> <meta property="theme-color" content="#4d3a9c" />
<script>
function copy() {
navigator.clipboard.writeText("!wip <?php echo $_GET["map"]; ?>");
Swal.fire({
icon: "success",
title: "Copied to clipboard",
showConfirmButton: false,
timer: 1000
});
}
</script>
</head> </head>
<body> <body>
@ -58,19 +70,6 @@
?> ?>
</div> </div>
</div> </div>
<script>
function copy() {
navigator.clipboard.writeText("!wip <?php echo $_GET["map"]; ?>");
Swal.fire({
position: "top-end",
icon: "success",
title: "Copied to clipboard",
showConfirmButton: false,
timer: 1000
});
}
</script>
</body> </body>
</html> </html>

@ -35,6 +35,22 @@ if (!isZipFile($map["name"])) {
die(); die();
} }
$fileHash = hash_file("sha256", $file); // the hash of the file
$exists = false;
foreach (scandir($target_dir) as $file) { // scan the maps directory for a file with the same hash
if (hash_file("sha256", $target_dir . $file) == $fileHash) {
$mapId = pathinfo($file, PATHINFO_FILENAME);
$exists = true;
break;
}
}
if ($exists) { // if the file already exists, redirect to the existing file
header("Location: /?map=https://wip.fascinated.cc/maps/" . $mapId . ".zip");
die();
}
$target_file = $target_dir . $mapId . ".zip"; $target_file = $target_dir . $mapId . ".zip";
if (!move_uploaded_file($file, $target_file)) { if (!move_uploaded_file($file, $target_file)) {
echo "There was an error uploading the file"; echo "There was an error uploading the file";