Compare commits

..

No commits in common. "main" and "v1.2.0" have entirely different histories.
main ... v1.2.0

4 changed files with 34 additions and 36 deletions

View File

@ -66,18 +66,16 @@ jobs:
- name: Initialize Docker runtime - name: Initialize Docker runtime
if: env.SKIP_SUBSEQUENT_STEPS != 'true' if: env.SKIP_SUBSEQUENT_STEPS != 'true'
run: | run: |
sudo apt-get update apt-get update
sudo apt-get install ca-certificates curl apt-get install ca-certificates curl gnupg lsb-release -y
sudo install -m 0755 -d /etc/apt/keyrings install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.asc chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \ $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin -y apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin -y
- name: Download Artifact - name: Download Artifact

View File

@ -5,7 +5,7 @@ plugins {
} }
group = 'de.w665' group = 'de.w665'
version = '1.2.1' version = '1.2.0'
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.6' implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.12.5'
// 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.6' runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.12.5'
// 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.6' runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-orgjson', version: '0.12.5'
} }

View File

@ -12,8 +12,6 @@ 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
@ -54,12 +52,7 @@ 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) {
@ -86,24 +79,32 @@ public class FileUploadRepository {
.run(connection); .run(connection);
} }
public List<FileUpload> getAllExpiredFileUploads() { // This query filters all file uploads that are older than 24 hours from the file_uplaods table (not the expired_file_uploads table)
long timestamp = getTimestamp24HoursAgo(); public List<FileUpload> findAllExpiredActiveFileUploads() {
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();
} }
private long getTimestamp24HoursAgo() { public List<FileUpload> findAll() {
Instant now = Instant.now(); return r.db("sharepulse").table("file_uploads")
Instant oneMinuteAgo = now.minus(24, ChronoUnit.HOURS); .run(connection, FileUpload.class)
return oneMinuteAgo.toEpochMilli(); .toList();
} }
// For testing only private long get24HoursAgoTimestamp() {
private long getTimestampOneMinuteAgo() { Calendar calendar = Calendar.getInstance();
Instant now = Instant.now(); calendar.add(Calendar.HOUR, -24);
Instant oneMinuteAgo = now.minus(1, ChronoUnit.MINUTES); return calendar.getTimeInMillis() / 1000;
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)
}
}

View File

@ -23,11 +23,10 @@ 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.getAllExpiredFileUploads(); List<FileUpload> expFileUploads = fileUploadRepository.findAllExpiredActiveFileUploads();
for (FileUpload fileUpload : expFileUploads) { for (FileUpload fileUpload : expFileUploads) {
fileService.deleteFile(fileUpload); fileService.deleteFile(fileUpload);
expiredFileUploadRepository.insertExpiredFileUpload(fileUpload); expiredFileUploadRepository.insertExpiredFileUpload(fileUpload);