Compare commits

..

3 commits

Author SHA1 Message Date
Dmitry Isaenko
1791fd909d Add Download ability 2024-01-10 21:59:11 +03:00
Dmitry Isaenko
ae367797bb Mock book page 2024-01-10 20:08:05 +03:00
Dmitry Isaenko
a1105f2830 update footer 2024-01-10 20:07:06 +03:00
11 changed files with 248 additions and 17 deletions

View file

@ -0,0 +1,31 @@
package ru.redrise.marinesco;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import ru.redrise.marinesco.data.InpEntryRepository;
import ru.redrise.marinesco.library.InpEntry;
@Controller
@RequestMapping("/book")
public class BookController {
InpEntryRepository inpEntryRepository;
public BookController(InpEntryRepository inpEntryRepository){
this.inpEntryRepository = inpEntryRepository;
}
@GetMapping("/{bookId}")
public String getPage(@PathVariable("bookId") Long bookId, Model model) {
InpEntry book = inpEntryRepository.findById(bookId).orElse(null);
if (book == null){
model.addAttribute("Error", "Not found");
return "book";
}
model.addAttribute("book", book);
return "book";
}
}

View file

@ -0,0 +1,89 @@
package ru.redrise.marinesco;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import ru.redrise.marinesco.settings.ApplicationSettings;
@Slf4j
@Controller
@RequestMapping("/download")
public class DownloadController {
private String filesLocation;
public DownloadController(ApplicationSettings applicationSettings) {
this.filesLocation = applicationSettings.getFilesLocation();
}
@GetMapping(value = "/")
public void getMethodName(@RequestParam String container,
@RequestParam String file,
HttpServletResponse response) throws Exception {
final FileSystemResource libraryLocation = new FileSystemResource(filesLocation + File.separator + container);
try (ZipInputStream zipInputStream = new ZipInputStream(libraryLocation.getInputStream())) {
ZipEntry zipEntry = zipInputStream.getNextEntry();
while (zipEntry != null) {
if (zipEntry.getName().contains(file)) {
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.attachment()
.filename(file+".fb2", StandardCharsets.UTF_8) //TODO: fix
.build()
.toString());
ServletOutputStream outStream = response.getOutputStream();
sendFile(zipEntry.getSize(), zipInputStream, outStream);
outStream.flush();
outStream.close();
return;
}
zipEntry = zipInputStream.getNextEntry();
}
}
throw new Exception("file not found " +
filesLocation + File.separator + container + "" + file);
}
private void sendFile(long fileSize,
ZipInputStream zipInputStream,
ServletOutputStream outStream) throws Exception {
int blockSize = 0x200;
if (fileSize < 0x200)
blockSize = (int) fileSize;
byte[] block = new byte[blockSize];
long i = 0;
while (true) {
int actuallyRead = zipInputStream.read(block);
outStream.write(block, 0, actuallyRead);
i += actuallyRead;
if ((i + blockSize) > fileSize) {
blockSize = (int) (fileSize - i);
if (blockSize == 0)
break;
block = new byte[blockSize];
}
}
}
}

View file

@ -2,12 +2,20 @@ package ru.redrise.marinesco;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Controller
@RequestMapping("/")
public class RootController {
@GetMapping("/")
public String home(){
@GetMapping
public String getPage(@ModelAttribute("search") String text) {
// TODO: SEARCH PAGE + CONTROLLER
log.info(text);
return "root";
}
}

View file

@ -0,0 +1,21 @@
package ru.redrise.marinesco.library;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import ru.redrise.marinesco.data.AuthorRepository;
@Component
public class AthorByIdConverter implements Converter<Long, Author>{
private AuthorRepository authorRepository;
public AthorByIdConverter(AuthorRepository authorRepository){
this.authorRepository = authorRepository;
}
@Override
public Author convert(Long id) {
return authorRepository.findById(id).orElse(null);
}
}

View file

@ -0,0 +1,21 @@
package ru.redrise.marinesco.library;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import ru.redrise.marinesco.data.GenreRepository;
@Component
public class GenreByIdConverter implements Converter<String, Genre>{
private GenreRepository genreRepository;
public GenreByIdConverter(GenreRepository genreRepository){
this.genreRepository = genreRepository;
}
@Override
public Genre convert(String id) {
return genreRepository.findById(id).orElse(null);
}
}

View file

@ -17,27 +17,29 @@ import ru.redrise.marinesco.data.AuthorRepository;
import ru.redrise.marinesco.data.GenreRepository;
import ru.redrise.marinesco.data.InpEntryRepository;
import ru.redrise.marinesco.data.LibraryMetadataRepository;
import ru.redrise.marinesco.settings.ApplicationSettings;
@Slf4j
@Component
@ConfigurationProperties(prefix = "marinesco.library")
public class InpxScanner implements Runnable {
private static volatile Thread parser;
private static volatile String lastRunErrors;
private String filesLocation = "";
private LibraryMetadata libraryMetadata;
private LibraryMetadataRepository libraryMetadataRepository;
private AuthorRepository authorRepository;
private GenreRepository genreRepository;
private InpEntryRepository inpEntryRepository;
public InpxScanner(AuthorRepository authorRepository,
private String filesLocation;
public InpxScanner(ApplicationSettings applicationSettings,
AuthorRepository authorRepository,
GenreRepository genreRepository,
InpEntryRepository inpEntryRepository,
LibraryMetadataRepository libraryMetadataRepository) {
this.filesLocation = applicationSettings.getFilesLocation();
this.authorRepository = authorRepository;
this.genreRepository = genreRepository;
this.inpEntryRepository = inpEntryRepository;
@ -47,7 +49,7 @@ public class InpxScanner implements Runnable {
/*
* @return true if executed, false if already running
*/
public boolean reScan(){
public boolean reScan() {
if (parser == null || !parser.isAlive()) {
parser = new Thread(this);
parser.start();
@ -133,6 +135,9 @@ public class InpxScanner implements Runnable {
}
private void parseInp(File inpxFile) throws Exception {
log.warn("REMOVE TEMPORARY SOLUTION - BREAKER");
log.warn("REMOVE TEMPORARY SOLUTION - BREAKER");
log.warn("REMOVE TEMPORARY SOLUTION - BREAKER");
boolean breaker = false;
try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(inpxFile))) {
@ -187,14 +192,6 @@ public class InpxScanner implements Runnable {
return i + 1 < content.length && (content[i + 1] == '\r');
}
public String getFilesLocation() {
return filesLocation;
}
public void setFilesLocation(String location) {
filesLocation = location;
}
public static String getLastRunErrors() {
return lastRunErrors;
}

View file

@ -1,11 +1,15 @@
package ru.redrise.marinesco.settings;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "marinesco.library")
public class ApplicationSettings {
private static final String ALLOW_REGISTRATION = "allow_registration";
private String filesLocation = "";
private KeyValueRepository keyValueRepository;
private boolean registrationAllowed;
@ -34,4 +38,13 @@ public class ApplicationSettings {
public synchronized boolean isRegistrationAllowed() {
return registrationAllowed;
}
public String getFilesLocation() {
return filesLocation;
}
public void setFilesLocation(String location) {
filesLocation = location;
}
}

View file

@ -8,6 +8,10 @@
src: url('/styles/Arimo-VariableFont_wght.ttf');
}
html{
line-height: 1.5;
}
body {
font-family: Arimo;
background-color: #212121;

View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Marinesco</title>
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="alternate icon" href="/favicon.png" type="image/png">
<link rel="stylesheet" th:href="@{/styles/styles.css}" />
</head>
<body>
<div class="page">
<div th:replace="~{fragments/header :: 'header'}"></div>
<div class="container base">
<span class="validationError" th:if="${Error} != null" th:text="${Error}"></span>
<div th:if="${book} != null">
<br /><span th:text="${'Title: ' + book.title}"></span>
<br /><span>Authors: </span>
<div th:each="author : ${book.authors}">
<span th:text="${' * ' + author.authorName}"></span>
</div>
<br /><span>Genres: </span>
<div th:each="genre : ${book.genres}">
<span th:text="${' * ' + genre.genreId + ' — ' + genre.humanReadableDescription}"></span>
</div>
<br /><span th:if="${book.series} != null" th:text="${'Series: ' + book.series}"></span>
<br /><span th:if="${book.serNo} != null" th:text="${'Series # : ' + book.serNo}"></span>
<br /><span th:text="${'Format: ' + book.fileExtension}"></span>
<br /><span th:if="${book.addedDate} != null" th:text="${'Added : ' + book.addedDate}"></span>
<br /><span th:text="${'Size: ' + book.fileSize + ' bytes'}"></span>
<p>
<a th:href="${'/download/?container=' + book.container + '&file=' + book.fsFileName}" th:text="Download"></a>
</p>
</div>
</div>
</div>
<div th:replace="~{fragments/footer :: 'footer'}"></div>
</body>
</html>

View file

@ -9,7 +9,7 @@
<div class="container">
<footer class="inner_footer">
<a class="entry" href="https://redrise.ru">
<div class="copy_link">&copy; 2023 Dmitry Isaenko</div>
<div class="copy_link">&copy; 2023-2024 Dmitry Isaenko</div>
</a>
</footer>
</div>

View file

@ -4,7 +4,7 @@
<head>
<title>Marinesco</title>
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="alternate icon" href="/favicon.png" type="image/png">
<link rel="alternate icon" href="/favicon.png" type="image/png">
<link rel="stylesheet" th:href="@{/styles/styles.css}" />
</head>
@ -16,7 +16,14 @@
<br /><a href="/profile">/profile</a>
<br /><a href="/manage_users">/manage_users</a>
<br /><a href="/settings">/settings</a>
<br /><a href="/book/59992766">/book/59992766</a>
<br /><a href="/h2">H2</a>
<br />
<br />
<form action='' method='get'>
<input type='text' name='search'>
<button class="sign" type='submit'>Search</button>
</form>
</div>
</div>
<div th:replace="~{fragments/footer :: 'footer'}"></div>