@@ -1,25 +0,0 @@
|
|||||||
package ru.soune.nocopy.configuration.file;
|
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ConfigurationProperties(prefix = "file.storage")
|
|
||||||
@Data
|
|
||||||
public class FileStorageConfig {
|
|
||||||
private String basePath;
|
|
||||||
private long maxFileSize;
|
|
||||||
private int chunkSize;
|
|
||||||
private int authTokenLifeHours;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() throws IOException {
|
|
||||||
Files.createDirectories(Paths.get(basePath));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
package ru.soune.nocopy.service.file;
|
package ru.soune.nocopy.service.file;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.UrlResource;
|
import org.springframework.core.io.UrlResource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.soune.nocopy.configuration.file.FileStorageConfig;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -16,11 +15,14 @@ import java.nio.file.Paths;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class FileStorageService {
|
public class FileStorageService {
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
private FileStorageConfig storageConfig;
|
// private FileStorageConfig storageConfig;
|
||||||
|
|
||||||
|
@Value("${file.storage.base-path}")
|
||||||
|
private String basePath;
|
||||||
|
|
||||||
public Resource loadFileAsResource(String filePath) throws IOException {
|
public Resource loadFileAsResource(String filePath) throws IOException {
|
||||||
Path path = Paths.get(storageConfig.getBasePath()).resolve(filePath).normalize();
|
Path path = Paths.get(basePath).resolve(filePath).normalize();
|
||||||
Resource resource = new UrlResource(path.toUri());
|
Resource resource = new UrlResource(path.toUri());
|
||||||
|
|
||||||
if (!resource.exists()) {
|
if (!resource.exists()) {
|
||||||
|
|||||||
@@ -57,9 +57,6 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
@Value("${file.storage.max-retry-attempts:3}")
|
@Value("${file.storage.max-retry-attempts:3}")
|
||||||
private int maxRetryAttempts;
|
private int maxRetryAttempts;
|
||||||
|
|
||||||
@Value("${file.storage.chunk-timeout-ms:300000}") // 5 минут
|
|
||||||
private long chunkTimeoutMs;
|
|
||||||
|
|
||||||
@Value("${file.storage.session-expiry-hours:24}")
|
@Value("${file.storage.session-expiry-hours:24}")
|
||||||
private int sessionExpiryHours;
|
private int sessionExpiryHours;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user