Added delete all files
This commit is contained in:
parent
dbb53ca9da
commit
7b683ce0a0
@ -52,7 +52,7 @@
|
||||
</svg>
|
||||
Change Administrator Login
|
||||
</button>
|
||||
<button class="btn btn-secondary">Delete All Uploaded Files</button>
|
||||
<button class="btn btn-secondary" (click)="confirm('Are you sure?') && deleteAllFileUploads()">Delete All Uploaded Files</button>
|
||||
<button class="btn btn-accent">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-people" viewBox="0 0 16 16">
|
||||
<path d="M15 14s1 0 1-1-1-4-5-4-5 3-5 4 1 1 1 1zm-7.978-1L7 12.996c.001-.264.167-1.03.76-1.72C8.312 10.629 9.282 10 11 10c1.717 0 2.687.63 3.24 1.276.593.69.758 1.457.76 1.72l-.008.002-.014.002zM11 7a2 2 0 1 0 0-4 2 2 0 0 0 0 4m3-2a3 3 0 1 1-6 0 3 3 0 0 1 6 0M6.936 9.28a6 6 0 0 0-1.23-.247A7 7 0 0 0 5 9c-4 0-5 3-5 4q0 1 1 1h4.216A2.24 2.24 0 0 1 5 13c0-1.01.377-2.042 1.09-2.904.243-.294.526-.569.846-.816M4.92 10A5.5 5.5 0 0 0 4 13H1c0-.26.164-1.03.76-1.724.545-.636 1.492-1.256 3.16-1.275ZM1.5 5.5a3 3 0 1 1 6 0 3 3 0 0 1-6 0m3-2a2 2 0 1 0 0 4 2 2 0 0 0 0-4"/>
|
||||
@ -131,7 +131,7 @@
|
||||
<td>{{ file.id }}</td>
|
||||
<td>{{ file.fileId }}</td>
|
||||
<td>{{ file.fileName }}</td>
|
||||
<td>{{ file.fileSize | number }}</td>
|
||||
<td>{{ file.fileSize | formatFileSizePipe }}</td>
|
||||
<td>{{ file.singleDownload ? 'true' : 'false' }}</td>
|
||||
<td>{{ file.disabled ? 'true' : 'false' }}</td>
|
||||
<td>{{ file.uploadDate | date: 'medium' }}</td>
|
||||
|
@ -111,4 +111,21 @@ export class AdminuiComponent {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
async deleteAllFileUploads() {
|
||||
try {
|
||||
const response = await axios({
|
||||
method: 'delete',
|
||||
url: this.developmentStore.getBaseUrl() + 'api/v1/secure/files',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + await firstValueFrom(this.authStore.token$)
|
||||
}
|
||||
});
|
||||
console.log(this.statistics)
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
protected readonly confirm = confirm;
|
||||
}
|
||||
|
@ -2,16 +2,20 @@ package de.w665.sharepulse.rest.mappings;
|
||||
|
||||
import de.w665.sharepulse.SharepulseApplication;
|
||||
import de.w665.sharepulse.db.repo.UserRepository;
|
||||
import de.w665.sharepulse.model.FileUpload;
|
||||
import de.w665.sharepulse.model.User;
|
||||
import de.w665.sharepulse.rest.SecureApiRestController;
|
||||
import de.w665.sharepulse.service.AuthenticationService;
|
||||
import de.w665.sharepulse.service.FileCleanupService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -21,15 +25,19 @@ public class Administration extends SecureApiRestController {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final AuthenticationService authenticationService;
|
||||
private final FileCleanupService fileCleanupService;
|
||||
|
||||
public Administration(UserRepository userRepository, AuthenticationService authenticationService) {
|
||||
public Administration(UserRepository userRepository, AuthenticationService authenticationService, FileCleanupService fileCleanupService) {
|
||||
this.userRepository = userRepository;
|
||||
this.authenticationService = authenticationService;
|
||||
this.fileCleanupService = fileCleanupService;
|
||||
}
|
||||
|
||||
@GetMapping("/statistics")
|
||||
public ResponseEntity<Object> getStatistics(HttpServletRequest request) {
|
||||
|
||||
// TODO: FIX LAST LOGIN
|
||||
|
||||
String token = request.getHeader("Authorization");
|
||||
token = token.substring(7);
|
||||
String username = authenticationService.getClaimValue(token, "username", String.class);
|
||||
@ -47,4 +55,10 @@ public class Administration extends SecureApiRestController {
|
||||
log.debug("Received statistics request");
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@DeleteMapping("/files")
|
||||
public ResponseEntity<Object> deleteFiles(HttpServletRequest request) {
|
||||
List<FileUpload> files = fileCleanupService.deleteFiles();
|
||||
return ResponseEntity.ok(files);
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,15 @@ public class FileCleanupService {
|
||||
log.debug("Moved file " + fileUpload.getFileId() + " to old_file_uploads table.");
|
||||
}
|
||||
}
|
||||
|
||||
public List<FileUpload> deleteFiles() {
|
||||
log.debug("Running cleanup. Clearing all files...");
|
||||
List<FileUpload> fileUploads = fileUploadRepository.findAll();
|
||||
for (FileUpload fileUpload : fileUploads) {
|
||||
fileService.deleteFile(fileUpload);
|
||||
expiredFileUploadRepository.insertExpiredFileUpload(fileUpload);
|
||||
log.debug("Moved file " + fileUpload.getFileId() + " to old_file_uploads table.");
|
||||
}
|
||||
return fileUploads;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user