Initial
This commit is contained in:
60
files/pom.xml
Normal file
60
files/pom.xml
Normal file
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>de.77zzcx7.nbs-cloud</groupId>
|
||||
<artifactId>nbs-cloud-aggregator</artifactId>
|
||||
<version>1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>de.77zzcx7.nbs-cloud</groupId>
|
||||
<artifactId>files</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.flywaydb</groupId>-->
|
||||
<!-- <artifactId>flyway-core</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.thymeleaf.extras</groupId>-->
|
||||
<!-- <artifactId>thymeleaf-extras-springsecurity5</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-test</artifactId>-->
|
||||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.security</groupId>-->
|
||||
<!-- <artifactId>spring-security-test</artifactId>-->
|
||||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
68
files/src/main/java/de/nbscloud/files/FileSystemService.java
Normal file
68
files/src/main/java/de/nbscloud/files/FileSystemService.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package de.nbscloud.files;
|
||||
|
||||
import de.nbscloud.files.config.FilesConfig;
|
||||
import de.nbscloud.files.exception.FileSystemServiceException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class FileSystemService {
|
||||
|
||||
public record ContentContainer(boolean directory, String name, long size) {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private FilesConfig filesConfig;
|
||||
|
||||
@Autowired
|
||||
private LocationTracker locationTracker;
|
||||
|
||||
public Path createDirectory(String name) {
|
||||
try {
|
||||
return Files.createDirectory(this.locationTracker.getCurrentLocation().resolve(name));
|
||||
} catch (IOException e) {
|
||||
throw new FileSystemServiceException("Could not create directory", e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean delete(String name) {
|
||||
try {
|
||||
return Files.deleteIfExists(this.locationTracker.getCurrentLocation().resolve(name));
|
||||
} catch (IOException e) {
|
||||
throw new FileSystemServiceException("Could not delete file", e);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO soft vs hard delete - first move into /trash then delete from there
|
||||
public Path move(Path originalPath, Path newPath) {
|
||||
try {
|
||||
return Files.move(originalPath, newPath);
|
||||
} catch (IOException e) {
|
||||
throw new FileSystemServiceException("Could not move file", e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ContentContainer> list() {
|
||||
try {
|
||||
return Files.list(this.locationTracker.getCurrentLocation())
|
||||
.map(path -> {
|
||||
try {
|
||||
return new ContentContainer(Files.isDirectory(path),
|
||||
path.getFileName().toString(),
|
||||
Files.size(path));
|
||||
} catch (IOException e) {
|
||||
throw new FileSystemServiceException("Could not list files", e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
} catch (IOException e) {
|
||||
throw new FileSystemServiceException("Could not list files", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
54
files/src/main/java/de/nbscloud/files/LocationTracker.java
Normal file
54
files/src/main/java/de/nbscloud/files/LocationTracker.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package de.nbscloud.files;
|
||||
|
||||
import de.nbscloud.files.config.FilesConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Component
|
||||
public class LocationTracker {
|
||||
@Autowired
|
||||
private FilesConfig filesConfig;
|
||||
|
||||
private Path baseDirPath;
|
||||
private Path currentLocation;
|
||||
|
||||
public void init() {
|
||||
this.baseDirPath = Paths.get(this.filesConfig.getBaseDir());
|
||||
this.currentLocation = baseDirPath.resolve("");
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
init();
|
||||
}
|
||||
|
||||
public Path getCurrentLocation() {
|
||||
return this.currentLocation;
|
||||
}
|
||||
|
||||
public void setCurrentLocation(String navigateTo) {
|
||||
validate(navigateTo);
|
||||
|
||||
this.currentLocation = this.currentLocation.resolve(navigateTo);
|
||||
}
|
||||
|
||||
private void validate(String navigateTo) {
|
||||
if(navigateTo == null) {
|
||||
throw new IllegalStateException("Null");
|
||||
}
|
||||
|
||||
if(navigateTo.contains("..")) {
|
||||
throw new IllegalStateException("Relative path");
|
||||
}
|
||||
|
||||
if (Paths.get(navigateTo).isAbsolute()) {
|
||||
throw new IllegalStateException("Absolute path: " + navigateTo);
|
||||
}
|
||||
|
||||
if(!this.currentLocation.resolve(navigateTo).startsWith(this.baseDirPath)) {
|
||||
throw new IllegalStateException("Illegal path: " + navigateTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.nbscloud.files.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "nbs-cloud.files")
|
||||
public class FilesConfig {
|
||||
private String baseDir;
|
||||
|
||||
public String getBaseDir() {
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
public void setBaseDir(String baseDir) {
|
||||
this.baseDir = baseDir;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.nbscloud.files.exception;
|
||||
|
||||
public class FileSystemServiceException extends RuntimeException {
|
||||
public FileSystemServiceException(String message, Exception cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
14
files/src/main/resources/config/application.properties
Normal file
14
files/src/main/resources/config/application.properties
Normal file
@@ -0,0 +1,14 @@
|
||||
### This is the main configuration file of the application.
|
||||
### Filtering of the @...@ values happens via the maven-resource-plugin. The execution of the plugin is configured in
|
||||
### the Spring Boot parent POM.// The same property exists on the server, look there for documentation
|
||||
spring.profiles.active=@activeProfiles@
|
||||
|
||||
info.app.name=NoBullShit Cloud - Files app
|
||||
info.app.description=A simple web file admin app
|
||||
info.build.group=@project.groupId@
|
||||
info.build.artifact=@project.artifactId@
|
||||
info.build.version=@project.version@
|
||||
|
||||
nbs-cloud.files.baseDir=/home/marius
|
||||
|
||||
spring.flyway.enabled=false
|
||||
14
files/target/classes/config/application.properties
Normal file
14
files/target/classes/config/application.properties
Normal file
@@ -0,0 +1,14 @@
|
||||
### This is the main configuration file of the application.
|
||||
### Filtering of the @...@ values happens via the maven-resource-plugin. The execution of the plugin is configured in
|
||||
### the Spring Boot parent POM.// The same property exists on the server, look there for documentation
|
||||
spring.profiles.active=[]
|
||||
|
||||
info.app.name=NoBullShit Cloud - Files app
|
||||
info.app.description=A simple web file admin app
|
||||
info.build.group=de.77zzcx7.nbs-cloud
|
||||
info.build.artifact=files
|
||||
info.build.version=1-SNAPSHOT
|
||||
|
||||
nbs-cloud.files.baseDir=/home/marius
|
||||
|
||||
spring.flyway.enabled=false
|
||||
Binary file not shown.
BIN
files/target/classes/de/nbscloud/files/FileSystemService.class
Normal file
BIN
files/target/classes/de/nbscloud/files/FileSystemService.class
Normal file
Binary file not shown.
BIN
files/target/classes/de/nbscloud/files/LocationTracker.class
Normal file
BIN
files/target/classes/de/nbscloud/files/LocationTracker.class
Normal file
Binary file not shown.
BIN
files/target/classes/de/nbscloud/files/config/FilesConfig.class
Normal file
BIN
files/target/classes/de/nbscloud/files/config/FilesConfig.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
files/target/files-1-SNAPSHOT.jar
Normal file
BIN
files/target/files-1-SNAPSHOT.jar
Normal file
Binary file not shown.
3
files/target/maven-archiver/pom.properties
Normal file
3
files/target/maven-archiver/pom.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
artifactId=files
|
||||
groupId=de.77zzcx7.nbs-cloud
|
||||
version=1-SNAPSHOT
|
||||
@@ -0,0 +1,5 @@
|
||||
de/nbscloud/files/FileSystemService.class
|
||||
de/nbscloud/files/LocationTracker.class
|
||||
de/nbscloud/files/config/FilesConfig.class
|
||||
de/nbscloud/files/exception/FileSystemServiceException.class
|
||||
de/nbscloud/files/FileSystemService$ContentContainer.class
|
||||
@@ -0,0 +1,4 @@
|
||||
/home/marius/dev/nbs-cloud/files/src/main/java/de/nbscloud/files/LocationTracker.java
|
||||
/home/marius/dev/nbs-cloud/files/src/main/java/de/nbscloud/files/exception/FileSystemServiceException.java
|
||||
/home/marius/dev/nbs-cloud/files/src/main/java/de/nbscloud/files/FileSystemService.java
|
||||
/home/marius/dev/nbs-cloud/files/src/main/java/de/nbscloud/files/config/FilesConfig.java
|
||||
Reference in New Issue
Block a user