1
0
This commit is contained in:
2022-04-20 21:47:36 +02:00
commit 8abb6d0372
31 changed files with 395 additions and 0 deletions

60
files/pom.xml Normal file
View 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>

View 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);
}
}
}

View 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);
}
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,7 @@
package de.nbscloud.files.exception;
public class FileSystemServiceException extends RuntimeException {
public FileSystemServiceException(String message, Exception cause) {
super(message, cause);
}
}

View 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

View 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.

View File

@@ -0,0 +1,3 @@
artifactId=files
groupId=de.77zzcx7.nbs-cloud
version=1-SNAPSHOT

View File

@@ -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

View File

@@ -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

70
pom.xml Normal file
View File

@@ -0,0 +1,70 @@
<?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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</build>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/>
</parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<artifactId>nbs-cloud-aggregator</artifactId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>
<description>The umbrella for all No BullShit cloud projects</description>
<name>nbs-cloud-aggregator</name>
<modules>
<module>files</module>
<module>web-container</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
</properties>
<distributionManagement>
<snapshotRepository>
<id>77zzcx7-snapshots</id>
<url>http://192.168.10.4:8100/snapshots/</url>
</snapshotRepository>
<repository>
<id>77zzcx7-releases</id>
<url>http://192.168.10.4:8100/releases/</url>
</repository>
</distributionManagement>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.77zzc7.nbs-cloud</groupId>
<artifactId>web-container</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>de.77zzc7.nbs-cloud</groupId>
<artifactId>files</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

49
web-container/pom.xml Normal file
View File

@@ -0,0 +1,49 @@
<?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>web-container</artifactId>
<packaging>jar</packaging>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- nbs-cloud modules -->
<dependency>
<groupId>de.77zzc7.nbs-cloud</groupId>
<artifactId>files</artifactId>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,11 @@
package de.nbscloud.webcontainer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@@ -0,0 +1,11 @@
package de.nbscloud.webcontainer.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConfigurationProperties(prefix = "nbs-cloud.web-container")
@ComponentScan("de.nbscloud.files")
public class WebContainerConfig {
}

View File

@@ -0,0 +1,3 @@
artifactId=web-container
groupId=de.77zzcx7.nbs-cloud
version=1-SNAPSHOT

View File

@@ -0,0 +1,2 @@
de/nbscloud/webcontainer/config/WebContainerConfig.class
de/nbscloud/webcontainer/Application.class

View File

@@ -0,0 +1,2 @@
/home/marius/dev/nbs-cloud/web-container/src/main/java/de/nbscloud/webcontainer/Application.java
/home/marius/dev/nbs-cloud/web-container/src/main/java/de/nbscloud/webcontainer/config/WebContainerConfig.java

Binary file not shown.

Binary file not shown.