Image uploads now get a generated thumbnail version
This commit is contained in:
parent
bd09ba1fe0
commit
87303d1ad7
6
pom.xml
6
pom.xml
@ -101,6 +101,12 @@
|
|||||||
<artifactId>bootstrap-icons</artifactId>
|
<artifactId>bootstrap-icons</artifactId>
|
||||||
<version>1.4.1</version>
|
<version>1.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.coobird</groupId>
|
||||||
|
<artifactId>thumbnailator</artifactId>
|
||||||
|
<version>0.4.14</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -136,7 +136,7 @@ class UploadController
|
|||||||
if (!imageConfigurationProperties.types.contains(extension)) return "upload" // TODO: Show error on page, unrecognised file type
|
if (!imageConfigurationProperties.types.contains(extension)) return "upload" // TODO: Show error on page, unrecognised file type
|
||||||
val user = memberRepository.findByName(userDetails.username)!!
|
val user = memberRepository.findByName(userDetails.username)!!
|
||||||
val hash: String = generateFileHash(file)
|
val hash: String = generateFileHash(file)
|
||||||
val tagData = tags.split(" ").map { tagRepository.findByTagIs(it) ?: tagRepository.save(Tag(it)) }.toMutableSet()
|
val tagData = tags.split(" ").map { tagRepository.findByTagIs(it) ?: tagRepository.save(Tag(tag = it)) }.toMutableSet()
|
||||||
storage.addImageFile(hash, extension, file.bytes)
|
storage.addImageFile(hash, extension, file.bytes)
|
||||||
imageRepository.save(Image("$hash.$extension", user, tagData))
|
imageRepository.save(Image("$hash.$extension", user, tagData))
|
||||||
return "upload" // TODO: Show success on page
|
return "upload" // TODO: Show success on page
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package uk.co.neviyn.booru
|
package uk.co.neviyn.booru
|
||||||
|
|
||||||
|
import net.coobird.thumbnailator.Thumbnails
|
||||||
|
import net.coobird.thumbnailator.name.Rename
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -22,6 +24,7 @@ class FileSystemStorageService
|
|||||||
override fun addImageFile(name: String, extension: String, data: ByteArray) {
|
override fun addImageFile(name: String, extension: String, data: ByteArray) {
|
||||||
val outputFile = File(imageConfigurationProperties.directory, "$name.$extension")
|
val outputFile = File(imageConfigurationProperties.directory, "$name.$extension")
|
||||||
outputFile.writeBytes(data)
|
outputFile.writeBytes(data)
|
||||||
|
Thumbnails.of(outputFile).size(200, 200).toFiles(Rename.PREFIX_DOT_THUMBNAIL)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -25,7 +25,7 @@
|
|||||||
<div class="row" th:if="${imagePage != null}">
|
<div class="row" th:if="${imagePage != null}">
|
||||||
<div class="col-2" th:each="image : ${imagePage.content}">
|
<div class="col-2" th:each="image : ${imagePage.content}">
|
||||||
<!--/*@thymesVar id="image" type="uk.co.neviyn.booru.Image"*/-->
|
<!--/*@thymesVar id="image" type="uk.co.neviyn.booru.Image"*/-->
|
||||||
<img alt="" class="img-thumbnail" th:src="'/i/' + ${image.filename}"/>
|
<img alt="" class="img-thumbnail" th:src="'/i/thumbnail.' + ${image.filename}"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row" th:if="${imagePage == null}">
|
<div class="row" th:if="${imagePage == null}">
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<form th:action="${#mvc.url('UC#uploadFile').build()}" class="mb-3 col-6 text-center" enctype="multipart/form-data" method="POST">
|
<form action="/upload" class="mb-3 col-6 text-center" enctype="multipart/form-data" method="POST">
|
||||||
<input th:name="${_csrf.parameterName}" type="hidden" th:value="${_csrf.token}"/>
|
<input th:name="${_csrf.parameterName}" type="hidden" th:value="${_csrf.token}"/>
|
||||||
<label class="form-label" for="formFile">Image file</label>
|
<label class="form-label" for="formFile">Image file</label>
|
||||||
<input class="form-control" id="formFile" name="file" type="file" th:accept="${@imageConfigurationProperties.typeListForFormFilter()}">
|
<input class="form-control" id="formFile" name="file" type="file" th:accept="${@imageConfigurationProperties.typeListForFormFilter()}">
|
||||||
|
Loading…
Reference in New Issue
Block a user