made the pages prettier and responsive for mobile users.

This commit is contained in:
Rostislav Raykov
2024-10-17 19:46:36 +03:00
parent 6fe0cb030d
commit 62dcfe4965
7 changed files with 337 additions and 130 deletions

View File

@@ -50,7 +50,7 @@ public class FileService {
String uuid = UUID.randomUUID().toString();
Path path = Path.of(fileSavePath, uuid);
if (fileUploadRequest.password == null) {
if (fileUploadRequest.password == null || fileUploadRequest.password.isEmpty()) {
if (!saveUnencryptedFile(file, path)) {
return null;
}
@@ -67,7 +67,7 @@ public class FileService {
fileEntity.size = file.getSize();
fileEntity.keepIndefinitely = fileUploadRequest.keepIndefinitely;
if (fileUploadRequest.password != null) {
if (fileUploadRequest.password != null && !fileUploadRequest.password.isEmpty()) {
fileEntity.passwordHash = passwordEncoder.encode(fileUploadRequest.password);
}

View File

@@ -0,0 +1,10 @@
function copyToClipboard() {
const copyText = document.getElementById("downloadLink");
const copyButton = document.querySelector(".copyButton");
navigator.clipboard.writeText(copyText.value).then(function () {
copyButton.innerText = "Copied!";
copyButton.classList.add("btn-success");
}).catch(function (err) {
console.error("Could not copy text: ", err);
});
}

View File

@@ -3,12 +3,30 @@
<head>
<meta charset="UTF-8">
<title>Enter Password</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<!-- Viewport Meta Tag -->
<meta content="width=device-width, initial-scale=1" name="viewport">
<!-- Bootstrap CSS -->
<link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
rel="stylesheet"
>
</head>
<body class="container mt-5">
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4">
<a class="navbar-brand" href="/">QuickDrop</a>
<div class="collapse navbar-collapse">
<button
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation"
class="navbar-toggler"
data-target="#navbarNav"
data-toggle="collapse"
type="button"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/file/list">View Files</a>
@@ -20,16 +38,29 @@
</div>
</nav>
<h1 class="text-center mb-4">Enter Password</h1>
<form class="card p-4" id="passwordForm" method="post" th:action="@{/file/password}">
<input th:name="${_csrf.parameterName}" th:value="${_csrf.token}" type="hidden"/>
<input name="uuid" th:value="${uuid}" type="hidden"/>
<div class="form-group">
<label for="password">Password:</label>
<input class="form-control" id="password" name="password" type="password"/>
<!-- Main Content -->
<div class="container mt-5">
<h1 class="text-center mb-4">Enter Password</h1>
<div class="row justify-content-center">
<div class="col-12 col-md-6 col-lg-4">
<!-- Form -->
<form class="card p-4" id="passwordForm" method="post" th:action="@{/file/password}">
<input th:name="${_csrf.parameterName}" th:value="${_csrf.token}" type="hidden"/>
<input name="uuid" th:value="${uuid}" type="hidden"/>
<div class="form-group">
<label for="password">Password:</label>
<input
class="form-control"
id="password"
name="password"
required
type="password"
/>
</div>
<button class="btn btn-primary btn-block" type="submit">Submit</button>
</form>
</div>
</div>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
</div>
</body>
</html>
</html>

View File

@@ -3,54 +3,121 @@
<head>
<meta charset="UTF-8">
<title>File View</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<!-- Viewport Meta Tag -->
<meta content="width=device-width, initial-scale=1" name="viewport">
<!-- Bootstrap 5 CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
rel="stylesheet"
>
</head>
<body class="container mt-5">
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4">
<a class="navbar-brand" href="/">QuickDrop</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/file/list">View Files</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/file/upload">Upload File</a>
</li>
</ul>
<div class="container">
<a class="navbar-brand" href="/">QuickDrop</a>
<button
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation"
class="navbar-toggler"
data-bs-target="#navbarNav"
data-bs-toggle="collapse"
type="button"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="/file/list">View Files</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/file/upload">Upload File</a>
</li>
</ul>
</div>
</div>
</nav>
<h1 class="text-center mb-4">File View</h1>
<div class="card p-4">
<h3>File Name</h3>
<p th:text="${file.name}"></p>
<!-- Main Content -->
<div class="container mt-5">
<h1 class="text-center mb-4">File View</h1>
<div class="row justify-content-center">
<div class="col-12 col-md-8 col-lg-6">
<!-- Card -->
<div class="card">
<div class="card-body">
<!-- File Name -->
<h5 class="card-title text-center" th:text="${file.name}">File Name</h5>
<h3>File description</h3>
<p th:text="${file.description}"></p>
<!-- File Description if there is a description -->
<div th:if="${!#strings.isEmpty(file.description)}">
<p class="card-text text-center mb-3" th:text="${file.description}"></p>
</div>
<h3>Uploaded/Renewed At</h3>
<p th:text="${file.uploadDate}"></p>
<p>Files are kept only for 30 days after this date.</p>
<!-- Uploaded/Renewed At -->
<div class="d-flex justify-content-between align-items-center border-top pt-3">
<h5 class="card-title mb-0">Uploaded/Renewed At:</h5>
<p class="card-text mb-0" th:text="${file.uploadDate}"></p>
</div>
<small class="text-muted">Files are kept only for 30 days after this date.</small>
<h3>Keep Indefinitely</h3>
<p th:text="${file.keepIndefinitely} ? 'Yes' : 'No'"></p>
<!-- Keep Indefinitely -->
<div class="d-flex justify-content-between align-items-center pt-3">
<h5 class="card-title">Keep Indefinitely:</h5>
<p class="card-text" th:text="${file.keepIndefinitely} ? 'Yes' : 'No'"></p>
</div>
<h3>File Size</h3>
<p th:text="${fileSize}"></p>
<!-- File Size -->
<div class="d-flex justify-content-between align-items-center">
<h5 class="card-title">File Size:</h5>
<p class="card-text" th:text="${fileSize}"></p>
</div>
<h3>Renew file lifetime</h3>
<form method="post" th:action="@{/file/extend/{id}(id=${file.id})}">
<input th:name="${_csrf.parameterName}" th:value="${_csrf.token}" type="hidden"/>
<button class="btn btn-primary" type="submit">Extend</button>
</form>
<!-- Link -->
<h5 class="card-title border-top pt-3">Link</h5>
<div class="input-group mb-3">
<input
class="form-control"
id="downloadLink"
readonly
th:value="${downloadLink}"
type="text"
/>
<button
class="btn btn-outline-secondary copyButton"
onclick="copyToClipboard()"
type="button"
>
Copy Link
</button>
</div>
<h3>Link</h3>
<a th:href="@{${downloadLink}}"><p th:text="${downloadLink}"></p></a>
<h3>Download</h3>
<p>
<a class="btn btn-success" th:href="@{/file/download/{id}(id=${file.id})}">Download</a>
</p>
<!-- Buttons Row -->
<div class="d-flex justify-content-between mt-3 border-top pt-3">
<form method="post" th:action="@{/file/extend/{id}(id=${file.id})}">
<input
th:name="${_csrf.parameterName}"
th:value="${_csrf.token}"
type="hidden"
/>
<button class="btn btn-primary" type="submit">Renew File Lifetime</button>
</form>
<a
class="btn btn-success"
th:href="@{/file/download/{id}(id=${file.id})}"
>
Download
</a>
</div>
</div>
</div>
<!-- End of Card -->
</div>
</div>
</div>
<script src="/js/fileView.js"></script>
</body>
</html>

View File

@@ -2,48 +2,69 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>All files</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<title>All Files</title>
<!-- Viewport Meta Tag -->
<meta content="width=device-width, initial-scale=1" name="viewport">
<!-- Bootstrap 5 CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
rel="stylesheet"
>
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4">
<a class="navbar-brand" href="/">QuickDrop</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/file/list">View Files</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/file/upload">Upload File</a>
</li>
</ul>
<div class="container">
<a class="navbar-brand" href="/">QuickDrop</a>
<button
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation"
class="navbar-toggler"
data-bs-target="#navbarNav"
data-bs-toggle="collapse"
type="button"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="/file/list">View Files</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/file/upload">Upload File</a>
</li>
</ul>
</div>
</div>
</nav>
<body class="container mt-5">
<h1 class="text-center mb-4">All Files</h1>
<table class="table table-bordered table-striped">
<thead class="thead-dark">
<tr>
<th>File Name</th>
<th>Description</th>
<th>Uploaded At</th>
<th>Keep Indefinitely</th>
<th>Password Protected</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<tr th:each="file : ${files}">
<td th:text="${file.name}"></td>
<td th:text="${file.description}"></td>
<td th:text="${file.uploadDate}"></td>
<td th:text="${file.keepIndefinitely} ? 'Yes' : 'No'"></td>
<td th:text="${file.passwordHash != null} ? 'Yes' : 'No'"></td>
<td>
<a class="btn btn-primary" th:href="@{/file/{UUID}(UUID=${file.uuid})}">Go to file page</a>
</td>
</tr>
</tbody>
</table>
<!-- Main Content -->
<div class="container mt-5">
<h1 class="text-center mb-4">All Files</h1>
<!-- Cards Row -->
<div class="row">
<!-- Card Column -->
<div class="col-12 col-sm-6 col-md-4 col-lg-3 mb-4" th:each="file : ${files}">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title" th:text="${file.name}">File Name</h5>
<p class="card-text" th:if="${!#strings.isEmpty(file.description)}"
th:text="${file.description}"></p>
<p class="card-text border-top pt-3"
th:text="'Keep Indefinitely: ' + (${file.keepIndefinitely} ? 'Yes' : 'No')">Keep Indefinitely</p>
<p class="card-text"
th:text="'Password Protected: ' + (${file.passwordHash != null} ? 'Yes' : 'No')">Password
Protected</p>
<p class="card-text border-top pt-3" th:text="${file.uploadDate}"></p>
</div>
<div class="card-footer">
<a class="btn btn-primary w-100" th:href="@{/file/{UUID}(UUID=${file.uuid})}">Go to File Page</a>
</div>
</div>
</div> <!-- End of Card Column -->
</div> <!-- End of Cards Row -->
</div>
</body>
</html>

View File

@@ -3,21 +3,37 @@
<head>
<meta charset="UTF-8">
<title>Password Required</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<!-- Viewport Meta Tag -->
<meta content="width=device-width, initial-scale=1" name="viewport">
<!-- Bootstrap CSS -->
<link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
rel="stylesheet"
>
</head>
<body>
<div class="container mt-5">
<h2>Please enter the password to continue</h2>
<form action="/password/login" method="POST">
<input th:name="${_csrf.parameterName}" th:value="${_csrf.token}" type="hidden"/>
<div class="form-group">
<label for="password">Password:</label>
<input class="form-control" id="password" name="password" required type="password">
<div class="container">
<div class="row justify-content-center mt-5">
<div class="col-12 col-md-6 col-lg-4">
<h2 class="text-center mb-4">Please Enter the Password to Continue</h2>
<form action="/password/login" method="POST">
<input th:name="${_csrf.parameterName}" th:value="${_csrf.token}" type="hidden"/>
<div class="form-group">
<label for="password">Password:</label>
<input
class="form-control"
id="password"
name="password"
required
type="password"
>
</div>
<button class="btn btn-primary btn-block" type="submit">Submit</button>
</form>
<div th:if="${error}">
<p class="text-danger mt-3" th:text="${error}"></p>
</div>
</div>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
<div th:if="${error}">
<p class="text-danger" th:text="${error}"></p>
</div>
</div>
</body>

View File

@@ -3,12 +3,30 @@
<head>
<meta charset="UTF-8">
<title>Upload File</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<!-- Viewport Meta Tag -->
<meta content="width=device-width, initial-scale=1" name="viewport">
<!-- Bootstrap CSS -->
<link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
rel="stylesheet"
>
</head>
<body class="container mt-5">
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4">
<a class="navbar-brand" href="/">QuickDrop</a>
<div class="collapse navbar-collapse">
<button
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation"
class="navbar-toggler"
data-target="#navbarNav"
data-toggle="collapse"
type="button"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/file/list">View Files</a>
@@ -20,32 +38,76 @@
</div>
</nav>
<h1 class="text-center mb-4">Upload a File</h1>
<p class="text-center mb-2">Max file size 1GB</p>
<p class="text-center mb-4">Files are deleted after 30 days if the option for indefinite upload is not selected</p>
<form class="card p-4" enctype="multipart/form-data" id="uploadForm" method="post" th:action="@{/file/upload}">
<input th:name="${_csrf.parameterName}" th:value="${_csrf.token}" type="hidden"/>
<div class="form-group">
<label for="file">Select a file:</label>
<input class="form-control" id="file" name="file" required type="file"/>
<!-- Main Content -->
<div class="container">
<h1 class="text-center mb-4">Upload a File</h1>
<p class="text-center mb-2">Max file size 1GB</p>
<p class="text-center mb-4">
Files are deleted after 30 days if the option for indefinite upload is not selected
</p>
<div class="row justify-content-center">
<div class="col-12 col-md-8 col-lg-6">
<!-- Form -->
<form
class="card p-4"
enctype="multipart/form-data"
id="uploadForm"
method="post"
th:action="@{/file/upload}"
>
<input th:name="${_csrf.parameterName}" th:value="${_csrf.token}" type="hidden"/>
<div class="form-group">
<label for="file">Select a file:</label>
<input
class="form-control"
id="file"
name="file"
required
type="file"
/>
</div>
<div class="form-group">
<label for="description">Description:</label>
<input
class="form-control"
id="description"
name="description"
type="text"
/>
</div>
<div class="form-group form-check">
<input
class="form-check-input"
id="keepIndefinitely"
name="keepIndefinitely"
type="checkbox"
/>
<label class="form-check-label" for="keepIndefinitely">
Keep indefinitely
</label>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input
class="form-control"
id="password"
name="password"
type="password"
/>
</div>
<button class="btn btn-primary btn-block" type="submit">Upload</button>
</form>
</div>
</div>
<div class="form-group">
<label for="description">Description:</label>
<input class="form-control" id="description" name="description" type="text"/>
<!-- Upload Indicator -->
<div
class="mt-3 text-info text-center"
id="uploadIndicator"
style="display: none;"
>
Upload started...
</div>
<div class="form-group form-check">
<input class="form-check-input" id="keepIndefinitely" name="keepIndefinitely" type="checkbox"/>
<label class="form-check-label" for="keepIndefinitely">Keep indefinitely</label>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input class="form-control" id="password" name="password" type="password"/>
</div>
<button class="btn btn-primary" type="submit">Upload</button>
</form>
<div class="mt-3 text-info" id="uploadIndicator" style="display: none;">Upload started...</div>
</div>
<script src="/js/upload.js"></script>
</body>
</html>