diff options
| -rw-r--r-- | php/includes/settings.inc.php | 2 | ||||
| -rw-r--r-- | php/upload.php | 36 | ||||
| -rw-r--r-- | static/js/app.js | 29 |
3 files changed, 37 insertions, 30 deletions
diff --git a/php/includes/settings.inc.php b/php/includes/settings.inc.php index 4468669..c984c69 100644 --- a/php/includes/settings.inc.php +++ b/php/includes/settings.inc.php @@ -82,7 +82,7 @@ define('POMF_FILES_LENGTH', 6); define('POMF_URL', 'https://i.pantsu.cat/'); /** - * URI for filename generation + * URI for filename generation * * @param string characters to be used in generateName() */ diff --git a/php/upload.php b/php/upload.php index ec7968e..f14a4d3 100644 --- a/php/upload.php +++ b/php/upload.php @@ -39,14 +39,16 @@ function generateName($file) do { // Iterate until we reach the maximum number of retries if ($tries-- === 0) { - throw new Exception('Gave up trying to find an unused name', - 500); // HTTP status code "500 Internal Server Error" + throw new Exception( + 'Gave up trying to find an unused name', + 500 + ); // HTTP status code "500 Internal Server Error" } - $chars = ID_CHARSET; + $chars = ID_CHARSET; $name = ''; for ($i = 0; $i < $length; ++$i) { - $name .= $chars[mt_rand(0, strlen($chars))]; + $name .= $chars[mt_rand(0, strlen($chars))]; } // Add the extension to the file name @@ -103,7 +105,7 @@ function uploadFile($file) $q = $db->prepare('SELECT filename, COUNT(*) AS count FROM files WHERE hash = (:hash) '. 'AND size = (:size)'); $q->bindValue(':hash', $file->getSha1(), PDO::PARAM_STR); - $q->bindValue(':size', $file->size, PDO::PARAM_INT); + $q->bindValue(':size', $file->size, PDO::PARAM_INT); $q->execute(); $result = $q->fetch(); if ($result['count'] > 0) { @@ -123,14 +125,18 @@ function uploadFile($file) // Attempt to move it to the static directory if (!move_uploaded_file($file->tempfile, $uploadFile)) { - throw new Exception('Failed to move file to destination', - 500); // HTTP status code "500 Internal Server Error" + throw new Exception( + 'Failed to move file to destination', + 500 + ); // HTTP status code "500 Internal Server Error" } // Need to change permissions for the new file to make it world readable if (!chmod($uploadFile, 0644)) { - throw new Exception('Failed to change file permissions', - 500); // HTTP status code "500 Internal Server Error" + throw new Exception( + 'Failed to change file permissions', + 500 + ); // HTTP status code "500 Internal Server Error" } // Add it to the database @@ -150,13 +156,13 @@ function uploadFile($file) } // Common parameters binding - $q->bindValue(':hash', $file->getSha1(), PDO::PARAM_STR); + $q->bindValue(':hash', $file->getSha1(), PDO::PARAM_STR); $q->bindValue(':orig', strip_tags($file->name), PDO::PARAM_STR); - $q->bindValue(':name', $newname, PDO::PARAM_STR); - $q->bindValue(':size', $file->size, PDO::PARAM_INT); - $q->bindValue(':date', date('Y-m-d'), PDO::PARAM_STR); - $q->bindValue(':exp', null, PDO::PARAM_STR); - $q->bindValue(':del', sha1($file->tempfile), PDO::PARAM_STR); + $q->bindValue(':name', $newname, PDO::PARAM_STR); + $q->bindValue(':size', $file->size, PDO::PARAM_INT); + $q->bindValue(':date', date('Y-m-d'), PDO::PARAM_STR); + $q->bindValue(':exp', null, PDO::PARAM_STR); + $q->bindValue(':del', sha1($file->tempfile), PDO::PARAM_STR); $q->execute(); return array( diff --git a/static/js/app.js b/static/js/app.js index 1b65fc0..e9e755a 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -20,7 +20,7 @@ * SOFTWARE. */ -document.addEventListener('DOMContentLoaded', function() { +document.addEventListener('DOMContentLoaded', function () { function addRow(file) { var row = document.createElement('li'); @@ -35,8 +35,8 @@ document.addEventListener('DOMContentLoaded', function() { var progressBar = document.createElement('progress'); progressBar.className = 'file-progress'; - progressBar.setAttribute("max", "100"); - progressBar.setAttribute("value", "0"); + progressBar.setAttribute('max', '100'); + progressBar.setAttribute('value', '0'); row.appendChild(name); row.appendChild(progressBar); @@ -53,7 +53,7 @@ document.addEventListener('DOMContentLoaded', function() { if (evt.lengthComputable) { var progressPercent = Math.floor((evt.loaded / evt.total) * 100); - bar.setAttribute("value", progressPercent); + bar.setAttribute('value', progressPercent); percentIndicator.textContent = progressPercent + '%'; } } @@ -64,8 +64,8 @@ document.addEventListener('DOMContentLoaded', function() { var row = xhr.row; var percentIndicator = xhr.percent; - percentIndicator.style.visibility = "hidden"; - bar.style.visibility = "hidden"; + percentIndicator.style.visibility = 'hidden'; + bar.style.visibility = 'hidden'; row.removeChild(bar); row.removeChild(percentIndicator); var respStatus = xhr.status; @@ -78,7 +78,7 @@ document.addEventListener('DOMContentLoaded', function() { if (respStatus === 200) { var response = JSON.parse(xhr.responseText); if (response.success) { - link.textContent = response.files[0].url.replace(/.*?:\/\//g, ""); + link.textContent = response.files[0].url.replace(/.*?:\/\//g, ''); link.href = response.files[0].url; url.appendChild(link); } else { @@ -99,11 +99,11 @@ document.addEventListener('DOMContentLoaded', function() { var xhr = new XMLHttpRequest(); xhr.open('POST', '/upload.php'); - xhr["row"] = row; - xhr["bar"] = bar; - xhr["percent"] = percentIndicator; - xhr.upload["bar"] = bar; - xhr.upload["percent"] = percentIndicator; + xhr['row'] = row; + xhr['bar'] = bar; + xhr['percent'] = percentIndicator; + xhr.upload['bar'] = bar; + xhr.upload['percent'] = percentIndicator; xhr.addEventListener('load', handleUploadComplete, false); xhr.upload.onprogress = handleUploadProgress; @@ -121,8 +121,9 @@ document.addEventListener('DOMContentLoaded', function() { function handleDrag(state, element, evt) { stopDefaultEvent(evt); if (state.dragCount == 1) { - element.textContent = "Drop it here~"; + element.textContent = 'Drop it here~'; } + state.dragCount += 1; } @@ -130,7 +131,7 @@ document.addEventListener('DOMContentLoaded', function() { stopDefaultEvent(evt); state.dragCount -= 1; if (state.dragCount == 0) { - element.textContent = "Select or drop file(s)"; + element.textContent = 'Select or drop file(s)'; } } |
