Compare commits
5 Commits
v1.2.0
...
0f64322af3
Author | SHA1 | Date | |
---|---|---|---|
0f64322af3 | |||
e5ce27adfd | |||
4134367350 | |||
f65a0d0e22 | |||
e73a2e6e8d |
@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'de.w665'
|
group = 'de.w665'
|
||||||
version = '1.2.0'
|
version = '1.2.1'
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = '21'
|
sourceCompatibility = '21'
|
||||||
@ -39,11 +39,11 @@ dependencies {
|
|||||||
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security
|
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security
|
||||||
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '3.2.4'
|
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '3.2.4'
|
||||||
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api
|
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api
|
||||||
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.12.5'
|
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.12.6'
|
||||||
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-impl
|
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-impl
|
||||||
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.12.5'
|
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.12.6'
|
||||||
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-orgjson
|
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-orgjson
|
||||||
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-orgjson', version: '0.12.5'
|
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-orgjson', version: '0.12.6'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@ -52,7 +54,12 @@ public class FileUploadRepository {
|
|||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FileUpload> findAll() {
|
||||||
|
return r.db("sharepulse").table("file_uploads")
|
||||||
|
.run(connection, FileUpload.class)
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFileUpload(FileUpload updatedFileUpload) {
|
public void updateFileUpload(FileUpload updatedFileUpload) {
|
||||||
@ -79,32 +86,24 @@ public class FileUploadRepository {
|
|||||||
.run(connection);
|
.run(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This query filters all file uploads that are older than 24 hours from the file_uplaods table (not the expired_file_uploads table)
|
public List<FileUpload> getAllExpiredFileUploads() {
|
||||||
public List<FileUpload> findAllExpiredActiveFileUploads() {
|
long timestamp = getTimestamp24HoursAgo();
|
||||||
|
|
||||||
long timestamp = getOneMinuteAgoTimestamp();
|
|
||||||
|
|
||||||
return r.db("sharepulse").table("file_uploads")
|
return r.db("sharepulse").table("file_uploads")
|
||||||
.filter(row -> row.g("uploadDate").lt(timestamp))
|
.filter(row -> row.g("uploadDate").lt(timestamp))
|
||||||
.run(connection, FileUpload.class)
|
.run(connection, FileUpload.class)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FileUpload> findAll() {
|
private long getTimestamp24HoursAgo() {
|
||||||
return r.db("sharepulse").table("file_uploads")
|
Instant now = Instant.now();
|
||||||
.run(connection, FileUpload.class)
|
Instant oneMinuteAgo = now.minus(24, ChronoUnit.HOURS);
|
||||||
.toList();
|
return oneMinuteAgo.toEpochMilli();
|
||||||
}
|
}
|
||||||
|
|
||||||
private long get24HoursAgoTimestamp() {
|
// For testing only
|
||||||
Calendar calendar = Calendar.getInstance();
|
private long getTimestampOneMinuteAgo() {
|
||||||
calendar.add(Calendar.HOUR, -24);
|
Instant now = Instant.now();
|
||||||
return calendar.getTimeInMillis() / 1000;
|
Instant oneMinuteAgo = now.minus(1, ChronoUnit.MINUTES);
|
||||||
}
|
return oneMinuteAgo.toEpochMilli();
|
||||||
|
|
||||||
private long getOneMinuteAgoTimestamp() {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.add(Calendar.MINUTE, -1); // Subtract 1 minute
|
|
||||||
return calendar.getTimeInMillis() / 1000; // Convert milliseconds to seconds (Unix timestamp)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,10 +23,11 @@ public class FileCleanupService {
|
|||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@Scheduled(cron = "*/10 * * * * *") // every 10 seconds
|
||||||
@Scheduled(cron = "0 0 * * * *")
|
@Scheduled(cron = "0 0 * * * *")
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
log.debug("Running cleanup...");
|
log.debug("Running cleanup...");
|
||||||
List<FileUpload> expFileUploads = fileUploadRepository.findAllExpiredActiveFileUploads();
|
List<FileUpload> expFileUploads = fileUploadRepository.getAllExpiredFileUploads();
|
||||||
for (FileUpload fileUpload : expFileUploads) {
|
for (FileUpload fileUpload : expFileUploads) {
|
||||||
fileService.deleteFile(fileUpload);
|
fileService.deleteFile(fileUpload);
|
||||||
expiredFileUploadRepository.insertExpiredFileUpload(fileUpload);
|
expiredFileUploadRepository.insertExpiredFileUpload(fileUpload);
|
||||||
|
Reference in New Issue
Block a user