2 Commits

Author SHA1 Message Date
Gregor Lohaus
9a46cd0814 remove conditional from filecleanup service for native iamge compatibility 2026-02-25 17:28:11 +01:00
Gregor Lohaus
3a2ff0fc5b Merge branch 'htmx-usage' 2026-02-25 16:44:22 +01:00
7 changed files with 41 additions and 40 deletions

View File

@@ -1,5 +1,6 @@
package com.gregor_lohaus.gtransfer; package com.gregor_lohaus.gtransfer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.context.annotation.ImportRuntimeHints;
@@ -9,11 +10,17 @@ import com.gregor_lohaus.gtransfer.config.ConfigRuntimeHints;
import com.gregor_lohaus.gtransfer.model.ModelRuntimeHints; import com.gregor_lohaus.gtransfer.model.ModelRuntimeHints;
import com.gregor_lohaus.gtransfer.native_image.HibernateRuntimeHints; import com.gregor_lohaus.gtransfer.native_image.HibernateRuntimeHints;
import com.gregor_lohaus.gtransfer.native_image.WebRuntimeHints; import com.gregor_lohaus.gtransfer.native_image.WebRuntimeHints;
import com.gregor_lohaus.gtransfer.services.filecleanup.FileCleanupService;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication @SpringBootApplication
@RestController @RestController
@EnableScheduling
@ImportRuntimeHints({ConfigRuntimeHints.class, HibernateRuntimeHints.class, ModelRuntimeHints.class, WebRuntimeHints.class}) @ImportRuntimeHints({ConfigRuntimeHints.class, HibernateRuntimeHints.class, ModelRuntimeHints.class, WebRuntimeHints.class})
public class GtransferApplication { public class GtransferApplication {
@Autowired
private FileCleanupService cleanupService;
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(GtransferApplication.class, args); SpringApplication.run(GtransferApplication.class, args);
} }

View File

@@ -48,7 +48,6 @@ public class DefaultConfig {
uc.maxDownloadLimit = 100; uc.maxDownloadLimit = 100;
uc.maxExpiryDays = 30; uc.maxExpiryDays = 30;
uc.cleanupEnabled = true; uc.cleanupEnabled = true;
uc.cleanupIntervalMs = 3600000L;
c.uploadConfig = uc; c.uploadConfig = uc;
config = c; config = c;

View File

@@ -11,6 +11,4 @@ public class UploadConfig implements TomlSerializable {
public Integer maxExpiryDays; public Integer maxExpiryDays;
@Property(name = "cleanupEnabled") @Property(name = "cleanupEnabled")
public Boolean cleanupEnabled; public Boolean cleanupEnabled;
@Property(name = "cleanupIntervalMs")
public Long cleanupIntervalMs;
} }

View File

@@ -1,28 +0,0 @@
package com.gregor_lohaus.gtransfer.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gregor_lohaus.gtransfer.services.filewriter.AbstractStorageService;
@RestController
public class Env {
@Autowired
private ConfigurableEnvironment env;
@Autowired
private AbstractStorageService storageService;
@GetMapping("/env")
public String env() {
StringBuilder b = new StringBuilder();
MutablePropertySources sources = this.env.getPropertySources();
sources.forEach((var m) -> {
b.append(m.toString());
b.append("\n");
});
b.append(storageService.getClass().toString());
return b.toString();
}
}

View File

@@ -1,4 +1,4 @@
package com.gregor_lohaus.gtransfer.services; package com.gregor_lohaus.gtransfer.services.filecleanup;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@@ -15,10 +15,11 @@ import com.gregor_lohaus.gtransfer.model.File;
import com.gregor_lohaus.gtransfer.model.FileRepository; import com.gregor_lohaus.gtransfer.model.FileRepository;
import com.gregor_lohaus.gtransfer.services.filewriter.AbstractStorageService; import com.gregor_lohaus.gtransfer.services.filewriter.AbstractStorageService;
@Component
@ConditionalOnProperty(name = "gtransfer-config.upload.cleanupEnabled", havingValue = "true", matchIfMissing = true)
public class FileCleanupService { public class FileCleanupService {
private Boolean enabled;
public FileCleanupService(Boolean enabled) {
this.enabled = enabled;
}
private static final Logger log = LoggerFactory.getLogger(FileCleanupService.class); private static final Logger log = LoggerFactory.getLogger(FileCleanupService.class);
@Autowired @Autowired
@@ -27,17 +28,24 @@ public class FileCleanupService {
@Autowired @Autowired
private AbstractStorageService storageService; private AbstractStorageService storageService;
@Scheduled(fixedDelayString = "${gtransfer-config.upload.cleanupIntervalMs:3600000}") @Scheduled(fixedDelay = 30000)
@Transactional @Transactional
public void cleanupExpiredFiles() { public void cleanupExpiredFiles() {
log.info("Cleaneup started");
if (!enabled) {
log.info("Cleaneup skipped");
return;
}
List<File> expired = fileRepository.findExpired(LocalDateTime.now()); List<File> expired = fileRepository.findExpired(LocalDateTime.now());
if (expired.isEmpty()) return; if (expired.isEmpty()) {
log.info("Nothing to clean up");
return;
};
for (File file : expired) { for (File file : expired) {
storageService.delete(file.getId()); storageService.delete(file.getId());
fileRepository.delete(file); fileRepository.delete(file);
} }
log.info("Cleaned up {} expired file(s)", expired.size()); log.info("Cleaned up {} expired file(s)", expired.size());
} }
} }

View File

@@ -0,0 +1,19 @@
package com.gregor_lohaus.gtransfer.services.filecleanup;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.gregor_lohaus.gtransfer.config.types.StorageServiceType;
@Configuration
public class FileCleanupServiceConfiguration {
@Bean
public FileCleanupService fileCleanupService(
@Value("${gtransfer-config.upload.cleanupEnabled}")
Boolean enabled
) {
return new FileCleanupService(enabled);
}
}

View File

@@ -5,12 +5,10 @@ import java.nio.file.Path;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.gregor_lohaus.gtransfer.config.types.StorageServiceType; import com.gregor_lohaus.gtransfer.config.types.StorageServiceType;
@Configuration @Configuration
@EnableScheduling
public class StorageServiceConfiguration { public class StorageServiceConfiguration {
//TODO S3 implementation //TODO S3 implementation