commit 8abb6d03726713b8f5a88c24a4df138103e5a168 Author: MK13 Date: Wed Apr 20 21:47:36 2022 +0200 Initial diff --git a/files/pom.xml b/files/pom.xml new file mode 100644 index 0000000..7be073b --- /dev/null +++ b/files/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + + de.77zzcx7.nbs-cloud + nbs-cloud-aggregator + 1-SNAPSHOT + + + de.77zzcx7.nbs-cloud + files + jar + + + + + + + + + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + + + + + + + + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + + + + + + + + + + + + \ No newline at end of file diff --git a/files/src/main/java/de/nbscloud/files/FileSystemService.java b/files/src/main/java/de/nbscloud/files/FileSystemService.java new file mode 100644 index 0000000..912f7eb --- /dev/null +++ b/files/src/main/java/de/nbscloud/files/FileSystemService.java @@ -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 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); + } + } +} diff --git a/files/src/main/java/de/nbscloud/files/LocationTracker.java b/files/src/main/java/de/nbscloud/files/LocationTracker.java new file mode 100644 index 0000000..d527cfe --- /dev/null +++ b/files/src/main/java/de/nbscloud/files/LocationTracker.java @@ -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); + } + } +} diff --git a/files/src/main/java/de/nbscloud/files/config/FilesConfig.java b/files/src/main/java/de/nbscloud/files/config/FilesConfig.java new file mode 100644 index 0000000..698d33d --- /dev/null +++ b/files/src/main/java/de/nbscloud/files/config/FilesConfig.java @@ -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; + } +} diff --git a/files/src/main/java/de/nbscloud/files/exception/FileSystemServiceException.java b/files/src/main/java/de/nbscloud/files/exception/FileSystemServiceException.java new file mode 100644 index 0000000..dc1f63e --- /dev/null +++ b/files/src/main/java/de/nbscloud/files/exception/FileSystemServiceException.java @@ -0,0 +1,7 @@ +package de.nbscloud.files.exception; + +public class FileSystemServiceException extends RuntimeException { + public FileSystemServiceException(String message, Exception cause) { + super(message, cause); + } +} diff --git a/files/src/main/resources/config/application.properties b/files/src/main/resources/config/application.properties new file mode 100644 index 0000000..9c3732e --- /dev/null +++ b/files/src/main/resources/config/application.properties @@ -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 \ No newline at end of file diff --git a/files/target/classes/config/application.properties b/files/target/classes/config/application.properties new file mode 100644 index 0000000..4c3045b --- /dev/null +++ b/files/target/classes/config/application.properties @@ -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 \ No newline at end of file diff --git a/files/target/classes/de/nbscloud/files/FileSystemService$ContentContainer.class b/files/target/classes/de/nbscloud/files/FileSystemService$ContentContainer.class new file mode 100644 index 0000000..69c9cca Binary files /dev/null and b/files/target/classes/de/nbscloud/files/FileSystemService$ContentContainer.class differ diff --git a/files/target/classes/de/nbscloud/files/FileSystemService.class b/files/target/classes/de/nbscloud/files/FileSystemService.class new file mode 100644 index 0000000..200fa08 Binary files /dev/null and b/files/target/classes/de/nbscloud/files/FileSystemService.class differ diff --git a/files/target/classes/de/nbscloud/files/LocationTracker.class b/files/target/classes/de/nbscloud/files/LocationTracker.class new file mode 100644 index 0000000..9b442a4 Binary files /dev/null and b/files/target/classes/de/nbscloud/files/LocationTracker.class differ diff --git a/files/target/classes/de/nbscloud/files/config/FilesConfig.class b/files/target/classes/de/nbscloud/files/config/FilesConfig.class new file mode 100644 index 0000000..c6b4765 Binary files /dev/null and b/files/target/classes/de/nbscloud/files/config/FilesConfig.class differ diff --git a/files/target/classes/de/nbscloud/files/exception/FileSystemServiceException.class b/files/target/classes/de/nbscloud/files/exception/FileSystemServiceException.class new file mode 100644 index 0000000..12f4e12 Binary files /dev/null and b/files/target/classes/de/nbscloud/files/exception/FileSystemServiceException.class differ diff --git a/files/target/files-1-SNAPSHOT.jar b/files/target/files-1-SNAPSHOT.jar new file mode 100644 index 0000000..e2692f4 Binary files /dev/null and b/files/target/files-1-SNAPSHOT.jar differ diff --git a/files/target/maven-archiver/pom.properties b/files/target/maven-archiver/pom.properties new file mode 100644 index 0000000..9115e2a --- /dev/null +++ b/files/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=files +groupId=de.77zzcx7.nbs-cloud +version=1-SNAPSHOT diff --git a/files/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/files/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..da66856 --- /dev/null +++ b/files/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -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 diff --git a/files/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/files/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..330b402 --- /dev/null +++ b/files/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -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 diff --git a/files/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/files/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/files/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/files/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..91821d6 --- /dev/null +++ b/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 16 + 16 + + + + + + org.springframework.boot + spring-boot-starter-parent + 2.6.6 + + + + de.77zzcx7.nbs-cloud + nbs-cloud-aggregator + 1-SNAPSHOT + pom + The umbrella for all No BullShit cloud projects + nbs-cloud-aggregator + + + files + web-container + + + + 17 + 17 + UTF-8 + 17 + + + + + 77zzcx7-snapshots + http://192.168.10.4:8100/snapshots/ + + + 77zzcx7-releases + http://192.168.10.4:8100/releases/ + + + + + + + de.77zzc7.nbs-cloud + web-container + ${project.version} + + + de.77zzc7.nbs-cloud + files + ${project.version} + + + + + \ No newline at end of file diff --git a/web-container/pom.xml b/web-container/pom.xml new file mode 100644 index 0000000..37c09ae --- /dev/null +++ b/web-container/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + + de.77zzcx7.nbs-cloud + nbs-cloud-aggregator + 1-SNAPSHOT + + + de.77zzcx7.nbs-cloud + web-container + jar + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + + + + + + de.77zzc7.nbs-cloud + files + + + + + org.springframework.boot + spring-boot-starter-web + + + + \ No newline at end of file diff --git a/web-container/src/main/java/de/nbscloud/webcontainer/Application.java b/web-container/src/main/java/de/nbscloud/webcontainer/Application.java new file mode 100644 index 0000000..60e6964 --- /dev/null +++ b/web-container/src/main/java/de/nbscloud/webcontainer/Application.java @@ -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); + } +} diff --git a/web-container/src/main/java/de/nbscloud/webcontainer/config/WebContainerConfig.java b/web-container/src/main/java/de/nbscloud/webcontainer/config/WebContainerConfig.java new file mode 100644 index 0000000..18f5299 --- /dev/null +++ b/web-container/src/main/java/de/nbscloud/webcontainer/config/WebContainerConfig.java @@ -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 { +} diff --git a/web-container/target/classes/de/nbscloud/webcontainer/Application.class b/web-container/target/classes/de/nbscloud/webcontainer/Application.class new file mode 100644 index 0000000..fec9034 Binary files /dev/null and b/web-container/target/classes/de/nbscloud/webcontainer/Application.class differ diff --git a/web-container/target/classes/de/nbscloud/webcontainer/config/WebContainerConfig.class b/web-container/target/classes/de/nbscloud/webcontainer/config/WebContainerConfig.class new file mode 100644 index 0000000..dee2477 Binary files /dev/null and b/web-container/target/classes/de/nbscloud/webcontainer/config/WebContainerConfig.class differ diff --git a/web-container/target/maven-archiver/pom.properties b/web-container/target/maven-archiver/pom.properties new file mode 100644 index 0000000..fe6c2e1 --- /dev/null +++ b/web-container/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=web-container +groupId=de.77zzcx7.nbs-cloud +version=1-SNAPSHOT diff --git a/web-container/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/web-container/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..c859765 --- /dev/null +++ b/web-container/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +de/nbscloud/webcontainer/config/WebContainerConfig.class +de/nbscloud/webcontainer/Application.class diff --git a/web-container/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/web-container/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..5dc1b34 --- /dev/null +++ b/web-container/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -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 diff --git a/web-container/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/web-container/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/web-container/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/web-container/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/web-container/target/web-container.jar b/web-container/target/web-container.jar new file mode 100644 index 0000000..36fad6a Binary files /dev/null and b/web-container/target/web-container.jar differ diff --git a/web-container/target/web-container.jar.original b/web-container/target/web-container.jar.original new file mode 100644 index 0000000..3430c91 Binary files /dev/null and b/web-container/target/web-container.jar.original differ