@@ -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;
|
||||
|
||||
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.UrlResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.soune.nocopy.configuration.file.FileStorageConfig;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -16,11 +15,14 @@ import java.nio.file.Paths;
|
||||
@Slf4j
|
||||
public class FileStorageService {
|
||||
|
||||
@Autowired
|
||||
private FileStorageConfig storageConfig;
|
||||
// @Autowired
|
||||
// private FileStorageConfig storageConfig;
|
||||
|
||||
@Value("${file.storage.base-path}")
|
||||
private String basePath;
|
||||
|
||||
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());
|
||||
|
||||
if (!resource.exists()) {
|
||||
|
||||
@@ -57,9 +57,6 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
@Value("${file.storage.max-retry-attempts:3}")
|
||||
private int maxRetryAttempts;
|
||||
|
||||
@Value("${file.storage.chunk-timeout-ms:300000}") // 5 минут
|
||||
private long chunkTimeoutMs;
|
||||
|
||||
@Value("${file.storage.session-expiry-hours:24}")
|
||||
private int sessionExpiryHours;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user