diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..30da14f --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +export DIRENV_WARN_TIMEOUT=20s + +eval "$(devenv direnvrc)" + +use devenv diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a5bd6a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Devenv +.devenv* +devenv.local.nix + +# direnv +.direnv + +# pre-commit +.pre-commit-config.yaml +.gradle diff --git a/Backend/.gitattributes b/Backend/.gitattributes new file mode 100644 index 0000000..8af972c --- /dev/null +++ b/Backend/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/Backend/.gitignore b/Backend/.gitignore new file mode 100644 index 0000000..9c4c5ed --- /dev/null +++ b/Backend/.gitignore @@ -0,0 +1,40 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ +build +buildcompleted.at +bin diff --git a/Backend/.ignore b/Backend/.ignore new file mode 100644 index 0000000..e5d8d13 --- /dev/null +++ b/Backend/.ignore @@ -0,0 +1,4 @@ +.claude +.gradle +bin +build diff --git a/Backend/build.gradle b/Backend/build.gradle new file mode 100644 index 0000000..79b7dad --- /dev/null +++ b/Backend/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '4.0.2' + id 'org.graalvm.buildtools.native' version '0.11.1' + id 'io.spring.dependency-management' version '1.1.7' +} + +group = 'com.gregor-lohaus' +version = '0.0.1-SNAPSHOT' +description = 'FOSS alternative to WeTransfer' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(25) + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.webjars:webjars-locator-lite' + implementation 'org.webjars.npm:htmx.org:2.0.4' + implementation 'org.webjars.npm:bootstrap:5.3.3' + runtimeOnly 'org.postgresql:postgresql' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'io.github.wasabithumb:jtoml:1.4.2' + implementation 'io.github.wasabithumb:jtoml-serializer-reflect:1.4.2' +} + +tasks.named('test') { + useJUnitPlatform() +} + +tasks.build { + dependsOn('processAot') + dependsOn('nativeCompile') +} diff --git a/Backend/gradle/wrapper/gradle-wrapper.jar b/Backend/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..61285a6 Binary files /dev/null and b/Backend/gradle/wrapper/gradle-wrapper.jar differ diff --git a/Backend/gradle/wrapper/gradle-wrapper.properties b/Backend/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..19a6bde --- /dev/null +++ b/Backend/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/Backend/gradlew b/Backend/gradlew new file mode 100755 index 0000000..adff685 --- /dev/null +++ b/Backend/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/Backend/gradlew.bat b/Backend/gradlew.bat new file mode 100644 index 0000000..c4bdd3a --- /dev/null +++ b/Backend/gradlew.bat @@ -0,0 +1,93 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/Backend/settings.gradle b/Backend/settings.gradle new file mode 100644 index 0000000..19624be --- /dev/null +++ b/Backend/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'gtransfer' diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/GtransferApplication.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/GtransferApplication.java new file mode 100644 index 0000000..c158483 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/GtransferApplication.java @@ -0,0 +1,21 @@ +package com.gregor_lohaus.gtransfer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportRuntimeHints; +import org.springframework.web.bind.annotation.RestController; + +import com.gregor_lohaus.gtransfer.config.ConfigRuntimeHints; +import com.gregor_lohaus.gtransfer.model.ModelRuntimeHints; +import com.gregor_lohaus.gtransfer.native_image.HibernateRuntimeHints; +import com.gregor_lohaus.gtransfer.native_image.WebRuntimeHints; + +@SpringBootApplication +@RestController +@ImportRuntimeHints({ConfigRuntimeHints.class, HibernateRuntimeHints.class, ModelRuntimeHints.class, WebRuntimeHints.class}) +public class GtransferApplication { + public static void main(String[] args) { + SpringApplication.run(GtransferApplication.class, args); + } + +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ConfigEnvironmentPostProcessor.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ConfigEnvironmentPostProcessor.java new file mode 100644 index 0000000..937fa42 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ConfigEnvironmentPostProcessor.java @@ -0,0 +1,55 @@ +package com.gregor_lohaus.gtransfer.config; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import com.gregor_lohaus.gtransfer.config.types.Config; + +import org.springframework.boot.EnvironmentPostProcessor; +// import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.boot.SpringApplication; +import org.springframework.core.env.ConfigurableEnvironment; + +import io.github.wasabithumb.jtoml.JToml; +import io.github.wasabithumb.jtoml.value.table.TomlTable; + +public class ConfigEnvironmentPostProcessor implements EnvironmentPostProcessor { + private static final Path CONFIG_FILE_PATH; + static { + Path sysPath = Paths.get("etc","gtransfer","config.toml"); + Path userPath = Paths.get(System.getProperty("user.home"),".config","gtransfer","config.toml"); + if (Files.isReadable(sysPath) && !Files.isReadable(userPath)) { + CONFIG_FILE_PATH = sysPath; + } else { + CONFIG_FILE_PATH = userPath; + } + } + + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + JToml toml = JToml.jToml(); + TomlTable table; + if (Files.isReadable(CONFIG_FILE_PATH)) { + table = toml.read(CONFIG_FILE_PATH); + } else { + try { + Files.createDirectories(CONFIG_FILE_PATH.getParent()); + Files.createFile(CONFIG_FILE_PATH); + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + Config defaultConfig = DefaultConfig.config; + table = ConfigSerializer.toToml(defaultConfig); + toml.write(CONFIG_FILE_PATH, table); + } + ; + Config config = new Config(); + config = ConfigSerializer.fromToml(table); + ReflectionPropertySource source = new ReflectionPropertySource("gtransfer-config", config); + environment.getPropertySources() + .addLast(source); + } + +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ConfigRuntimeHints.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ConfigRuntimeHints.java new file mode 100644 index 0000000..e1acb05 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ConfigRuntimeHints.java @@ -0,0 +1,57 @@ +package com.gregor_lohaus.gtransfer.config; + +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import com.gregor_lohaus.gtransfer.config.types.*; + +import io.github.wasabithumb.jtoml.serial.reflect.adapter.TypeAdapter; + +public class ConfigRuntimeHints implements RuntimeHintsRegistrar { + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + hints.reflection().registerType(Config.class, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, + MemberCategory.ACCESS_DECLARED_FIELDS, + MemberCategory.ACCESS_PUBLIC_FIELDS); + hints.reflection().registerType(StorageService.class, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, + MemberCategory.ACCESS_DECLARED_FIELDS, + MemberCategory.ACCESS_PUBLIC_FIELDS); + hints.reflection().registerType(StorageServiceType.class, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, + MemberCategory.ACCESS_DECLARED_FIELDS, + MemberCategory.ACCESS_PUBLIC_FIELDS); + hints.reflection().registerType(SpringConfig.class, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, + MemberCategory.ACCESS_DECLARED_FIELDS, + MemberCategory.ACCESS_PUBLIC_FIELDS); + hints.reflection().registerType(JpaConfig.class, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, + MemberCategory.ACCESS_DECLARED_FIELDS, + MemberCategory.ACCESS_PUBLIC_FIELDS); + hints.reflection().registerType(DataSourceConfig.class, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, + MemberCategory.ACCESS_DECLARED_FIELDS, + MemberCategory.ACCESS_PUBLIC_FIELDS); + hints.reflection().registerType(ServletConfig.class, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, + MemberCategory.ACCESS_DECLARED_FIELDS, + MemberCategory.ACCESS_PUBLIC_FIELDS); + hints.reflection().registerType(MultipartConfig.class, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, + MemberCategory.ACCESS_DECLARED_FIELDS, + MemberCategory.ACCESS_PUBLIC_FIELDS); + hints.reflection().registerType(TypeAdapter.class, + MemberCategory.ACCESS_DECLARED_FIELDS, + MemberCategory.ACCESS_PUBLIC_FIELDS); + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ConfigSerializer.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ConfigSerializer.java new file mode 100644 index 0000000..c831a1a --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ConfigSerializer.java @@ -0,0 +1,33 @@ +package com.gregor_lohaus.gtransfer.config; + +import io.github.wasabithumb.jtoml.serial.reflect.ReflectTomlSerializer; +import io.github.wasabithumb.jtoml.serial.reflect.adapter.TypeAdapter; +import io.github.wasabithumb.jtoml.serial.reflect.adapter.TypeAdapters; +import io.github.wasabithumb.jtoml.value.TomlValue; +import io.github.wasabithumb.jtoml.value.table.TomlTable; +import com.gregor_lohaus.gtransfer.config.types.Config; +import com.gregor_lohaus.gtransfer.config.types.StorageServiceType; + +public class ConfigSerializer { + static final private ReflectTomlSerializer s; + static { + TypeAdapter fileWritTypeAdapter = TypeAdapter.of( + StorageServiceType.class, + (TomlValue v) -> StorageServiceType.fromToml(v), + (StorageServiceType f) -> StorageServiceType.toToml(f) + ); + TypeAdapters typeAdapters = TypeAdapters.builder() + .add(TypeAdapters.standard()) + .add(fileWritTypeAdapter) + .build(); + s = new ReflectTomlSerializer(Config.class,typeAdapters); + } + + public static Config fromToml(TomlTable t) { + return s.fromToml(t); + } + + public static TomlTable toToml(Config c) { + return s.toToml(c); + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/DefaultConfig.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/DefaultConfig.java new file mode 100644 index 0000000..c47322e --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/DefaultConfig.java @@ -0,0 +1,47 @@ +package com.gregor_lohaus.gtransfer.config; + +import java.nio.file.Path; + +import com.gregor_lohaus.gtransfer.config.types.Config; +import com.gregor_lohaus.gtransfer.config.types.DataSourceConfig; +import com.gregor_lohaus.gtransfer.config.types.JpaConfig; +import com.gregor_lohaus.gtransfer.config.types.MultipartConfig; +import com.gregor_lohaus.gtransfer.config.types.ServletConfig; +import com.gregor_lohaus.gtransfer.config.types.SpringConfig; +import com.gregor_lohaus.gtransfer.config.types.StorageService; +import com.gregor_lohaus.gtransfer.config.types.StorageServiceType; + +public class DefaultConfig { + public static final Config config; + static { + Config c = new Config(); + + StorageService ss = new StorageService(); + ss.type = StorageServiceType.LOCAL; + ss.path = Path.of(System.getProperty("user.home"),".local","share","gtransfer").toString(); + c.storageService= ss; + + SpringConfig sc = new SpringConfig(); + DataSourceConfig dsc = new DataSourceConfig(); + dsc.password = "gtransfer"; + dsc.url = "jdbc:postgresql://localhost:5432/gtransfer"; + dsc.username = "gtransfer"; + sc.dataSourceConfig = dsc; + + JpaConfig jc = new JpaConfig(); + jc.ddlAuto = "update"; + jc.dialect = "org.hibernate.dialect.PostgreSQLDialect"; + jc.showSql = true; + sc.jpaConfig = jc; + + MultipartConfig mc = new MultipartConfig(); + mc.maxFileSize = "10GB"; + mc.maxRequestSize = "10GB"; + ServletConfig svc = new ServletConfig(); + svc.multipartConfig = mc; + sc.servletConfig = svc; + + c.springConfig = sc; + config = c; + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ReflectionPropertySource.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ReflectionPropertySource.java new file mode 100644 index 0000000..a1a7755 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/ReflectionPropertySource.java @@ -0,0 +1,98 @@ +package com.gregor_lohaus.gtransfer.config; + +import java.lang.annotation.Annotation; +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Optional; + +import org.jspecify.annotations.Nullable; +import org.springframework.core.env.PropertySource; + +import com.gregor_lohaus.gtransfer.config.annotations.Named; +import com.gregor_lohaus.gtransfer.config.annotations.Nested; +import com.gregor_lohaus.gtransfer.config.annotations.NoPrefix; +import com.gregor_lohaus.gtransfer.config.annotations.Property; + +public class ReflectionPropertySource extends PropertySource { + private HashMap fields; + private ArrayList propNameBuffer; + + public ReflectionPropertySource(String name, T source) { + super(name); + this.fields = new HashMap(); + this.propNameBuffer = new ArrayList(); + this.propNameBuffer.add(this.getName()); + this.getFields(source, 0); + } + + private boolean hasPrefix() { + if (propNameBuffer.size() > 0 && propNameBuffer.getFirst() == this.getName()) { + return true; + } + return false; + } + + private void handleNoPrefix(Field field) { + NoPrefix np = field.getAnnotation(NoPrefix.class); + if (np != null && this.hasPrefix()) { + this.propNameBuffer.remove(0); + } + } + + public void handleAnnotated(Field field, Object object, int depth) throws IllegalAccessException { + Annotation annotation; + annotation = field.getAnnotation(Property.class); + if (annotation == null) { + annotation = field.getAnnotation(Nested.class); + } + Optional name = Named.nameOf(annotation); + if (name.isEmpty()) { + return; + } + field.setAccessible(true); + Object fieldValue = field.get(object); + if (fieldValue == null) { + return; + } + handleNoPrefix(field); + propNameBuffer.add(name.get()); + switch (annotation) { + case Nested _ -> getFields(fieldValue, depth + 1); + case Property _ -> fields.put(String.join(".", propNameBuffer), fieldValue); + case null -> {} + default -> {} + } + propNameBuffer.removeLast(); + } + + private void getFields(Object object, int depth) { + Class c = object.getClass(); + Field[] fields = c.getDeclaredFields(); + for (Field field : fields) { + try { + handleAnnotated(field, object, depth); + } catch (IllegalAccessException e) { + e.printStackTrace(); + System.exit(1); + } + if (depth == 0 && !hasPrefix()) { + propNameBuffer.addFirst(this.getName()); + } + } + }; + + @Override + public @Nullable Object getProperty(String name) { + return this.fields.get(name); + } + + public String toString() { + StringBuilder out = new StringBuilder(); + this.fields.forEach((String f, Object o) -> { + out.append(f + ":" + o.toString() + "\n"); + }); + return out.toString(); + } + +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/Named.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/Named.java new file mode 100644 index 0000000..54fa44f --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/Named.java @@ -0,0 +1,15 @@ +package com.gregor_lohaus.gtransfer.config.annotations; + +import java.lang.annotation.Annotation; +import java.util.Optional; + +public interface Named { + static Optional nameOf(Annotation annotation) { + return switch (annotation) { + case Property p -> Optional.of(p.name()); + case Nested n -> Optional.of(n.name()); + case null -> Optional.empty(); + default -> Optional.empty(); + }; + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/Nested.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/Nested.java new file mode 100644 index 0000000..691da21 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/Nested.java @@ -0,0 +1,12 @@ +package com.gregor_lohaus.gtransfer.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Nested { + String name() default ""; +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/NoPrefix.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/NoPrefix.java new file mode 100644 index 0000000..0706cf6 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/NoPrefix.java @@ -0,0 +1,10 @@ +package com.gregor_lohaus.gtransfer.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface NoPrefix {} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/Property.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/Property.java new file mode 100644 index 0000000..2bef9c0 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/annotations/Property.java @@ -0,0 +1,12 @@ +package com.gregor_lohaus.gtransfer.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Property { + String name() default ""; +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/Config.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/Config.java new file mode 100644 index 0000000..f7b7b32 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/Config.java @@ -0,0 +1,14 @@ +package com.gregor_lohaus.gtransfer.config.types; + +import com.gregor_lohaus.gtransfer.config.annotations.Nested; +import com.gregor_lohaus.gtransfer.config.annotations.NoPrefix; + +import io.github.wasabithumb.jtoml.serial.TomlSerializable; + +public class Config implements TomlSerializable { + @Nested(name = "spring") + @NoPrefix + public SpringConfig springConfig; + @Nested(name = "storageService") + public StorageService storageService; +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/DataSourceConfig.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/DataSourceConfig.java new file mode 100644 index 0000000..b0f7dfc --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/DataSourceConfig.java @@ -0,0 +1,14 @@ +package com.gregor_lohaus.gtransfer.config.types; + +import com.gregor_lohaus.gtransfer.config.annotations.Property; + +import io.github.wasabithumb.jtoml.serial.TomlSerializable; + +public class DataSourceConfig implements TomlSerializable { + @Property(name = "url") + public String url; + @Property(name = "username") + public String username; + @Property(name = "password") + public String password; +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/JpaConfig.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/JpaConfig.java new file mode 100644 index 0000000..643b784 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/JpaConfig.java @@ -0,0 +1,14 @@ +package com.gregor_lohaus.gtransfer.config.types; + +import com.gregor_lohaus.gtransfer.config.annotations.Property; + +import io.github.wasabithumb.jtoml.serial.TomlSerializable; + +public class JpaConfig implements TomlSerializable { + @Property(name = "hibernate.ddl-auto") + public String ddlAuto; + @Property(name = "show-sql") + public boolean showSql; + @Property(name = "properties.hibernate.dialect") + public String dialect; +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/MultipartConfig.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/MultipartConfig.java new file mode 100644 index 0000000..2d3ee9f --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/MultipartConfig.java @@ -0,0 +1,12 @@ +package com.gregor_lohaus.gtransfer.config.types; + +import com.gregor_lohaus.gtransfer.config.annotations.Property; + +import io.github.wasabithumb.jtoml.serial.TomlSerializable; + +public class MultipartConfig implements TomlSerializable { + @Property(name = "max-file-size") + public String maxFileSize; + @Property(name = "max-request-size") + public String maxRequestSize; +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/ServletConfig.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/ServletConfig.java new file mode 100644 index 0000000..777a8e7 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/ServletConfig.java @@ -0,0 +1,10 @@ +package com.gregor_lohaus.gtransfer.config.types; + +import com.gregor_lohaus.gtransfer.config.annotations.Nested; + +import io.github.wasabithumb.jtoml.serial.TomlSerializable; + +public class ServletConfig implements TomlSerializable { + @Nested(name = "multipart") + public MultipartConfig multipartConfig; +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/SpringConfig.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/SpringConfig.java new file mode 100644 index 0000000..e4c7c30 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/SpringConfig.java @@ -0,0 +1,14 @@ +package com.gregor_lohaus.gtransfer.config.types; + +import com.gregor_lohaus.gtransfer.config.annotations.Nested; + +import io.github.wasabithumb.jtoml.serial.TomlSerializable; + +public class SpringConfig implements TomlSerializable { + @Nested(name = "datasource") + public DataSourceConfig dataSourceConfig; + @Nested(name = "jpa") + public JpaConfig jpaConfig; + @Nested(name = "servlet") + public ServletConfig servletConfig; +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/StorageService.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/StorageService.java new file mode 100644 index 0000000..a9f4cd9 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/StorageService.java @@ -0,0 +1,12 @@ +package com.gregor_lohaus.gtransfer.config.types; + +import com.gregor_lohaus.gtransfer.config.annotations.Property; + +import io.github.wasabithumb.jtoml.serial.TomlSerializable; + +public class StorageService implements TomlSerializable { + @Property(name = "type") + public StorageServiceType type; + @Property(name = "root") + public String path; +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/StorageServiceType.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/StorageServiceType.java new file mode 100644 index 0000000..7a2d552 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/config/types/StorageServiceType.java @@ -0,0 +1,26 @@ +package com.gregor_lohaus.gtransfer.config.types; + +import io.github.wasabithumb.jtoml.serial.TomlSerializable; +import io.github.wasabithumb.jtoml.value.TomlValue; +import io.github.wasabithumb.jtoml.value.primitive.TomlPrimitive;; +public enum StorageServiceType implements TomlSerializable { + LOCAL, + S3, + DUMMY; + public static StorageServiceType fromToml(TomlValue value) { + return switch (value.asPrimitive().asString().toLowerCase()) { + case "dummy" -> DUMMY; + case "local" -> LOCAL; + case "s3" -> S3; + default -> throw new IllegalArgumentException("couldnt parse filewriter type"); + }; + } + public static TomlValue toToml(StorageServiceType t) { + return switch (t) { + case LOCAL -> TomlPrimitive.of("local"); + case S3 -> TomlPrimitive.of("s3"); + case DUMMY -> TomlPrimitive.of("dummy"); + default -> throw new IllegalArgumentException(); + }; + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/controller/Env.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/controller/Env.java new file mode 100644 index 0000000..e4dd935 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/controller/Env.java @@ -0,0 +1,28 @@ +package com.gregor_lohaus.gtransfer.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.gregor_lohaus.gtransfer.services.filewriter.AbstractStorageService; + +@RestController +public class Env { + @Autowired + private ConfigurableEnvironment env; + @Autowired + private AbstractStorageService storageService; + @GetMapping("/env") + public String env() { + StringBuilder b = new StringBuilder(); + MutablePropertySources sources = this.env.getPropertySources(); + sources.forEach((var m) -> { + b.append(m.toString()); + b.append("\n"); + }); + b.append(storageService.getClass().toString()); + return b.toString(); + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/controller/IndexController.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/controller/IndexController.java new file mode 100644 index 0000000..b4b7950 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/controller/IndexController.java @@ -0,0 +1,19 @@ +package com.gregor_lohaus.gtransfer.controller; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class IndexController { + + @Value("${spring.servlet.multipart.max-file-size:10GB}") + private String maxFileSize; + + @GetMapping("/") + public String index(Model model) { + model.addAttribute("maxFileSize", maxFileSize); + return "index"; + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/controller/UploadController.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/controller/UploadController.java new file mode 100644 index 0000000..cf228cf --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/controller/UploadController.java @@ -0,0 +1,37 @@ +package com.gregor_lohaus.gtransfer.controller; + +import java.io.IOException; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import com.gregor_lohaus.gtransfer.model.File; +import com.gregor_lohaus.gtransfer.model.FileRepository; +import com.gregor_lohaus.gtransfer.services.filewriter.AbstractStorageService; + +@RestController +public class UploadController { + + @Autowired + private AbstractStorageService storageService; + + @Autowired + private FileRepository fileRepository; + + @PostMapping("/upload") + public ResponseEntity> upload( + @RequestParam("file") MultipartFile file, + @RequestParam("hash") String hash, + @RequestParam("name") String name) throws IOException { + + storageService.put(hash, file.getBytes()); + fileRepository.save(new File(hash, hash, name, null)); + + return ResponseEntity.ok(Map.of("id", hash)); + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/model/File.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/model/File.java new file mode 100644 index 0000000..69496e2 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/model/File.java @@ -0,0 +1,54 @@ +package com.gregor_lohaus.gtransfer.model; + +import java.time.LocalDateTime; + +import jakarta.persistence.*; + +@Entity +@Table(name = "files") +public class File { + protected File() {} + + @Id + private String id; + private String path; + private String name; + private LocalDateTime expireyDateTime; + private Integer downloadLimit; + public LocalDateTime getExpireyDateTime() { + return expireyDateTime; +} + public void setExpireyDateTime(LocalDateTime expireyDateTime) { + this.expireyDateTime = expireyDateTime; + } + public String getId() { + return id; +} + public void setId(String id) { + this.id = id; + } + public String getPath() { + return path; + } + public void setPath(String path) { + this.path = path; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public Integer getDownloadLimit() { + return downloadLimit; + } + public void setDownloadLimit(Integer downloadLimit) { + this.downloadLimit = downloadLimit; + } + public File(String id, String path, String name, LocalDateTime expDateTime) { + this.path = path; + this.name = name; + this.id = id; + this.expireyDateTime = expDateTime; + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/model/FileRepository.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/model/FileRepository.java new file mode 100644 index 0000000..dbcac13 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/model/FileRepository.java @@ -0,0 +1,8 @@ +package com.gregor_lohaus.gtransfer.model; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface FileRepository extends JpaRepository { +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/model/ModelRuntimeHints.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/model/ModelRuntimeHints.java new file mode 100644 index 0000000..1df4a08 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/model/ModelRuntimeHints.java @@ -0,0 +1,17 @@ +package com.gregor_lohaus.gtransfer.model; + +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; + +public class ModelRuntimeHints implements RuntimeHintsRegistrar { + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + hints.reflection().registerType(File.class, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, + MemberCategory.ACCESS_DECLARED_FIELDS, + MemberCategory.INVOKE_DECLARED_METHODS, + MemberCategory.INVOKE_PUBLIC_METHODS); + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/native_image/HibernateRuntimeHints.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/native_image/HibernateRuntimeHints.java new file mode 100644 index 0000000..f44980f --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/native_image/HibernateRuntimeHints.java @@ -0,0 +1,121 @@ +package com.gregor_lohaus.gtransfer.native_image; + +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; + +public class HibernateRuntimeHints implements RuntimeHintsRegistrar { + private static final String[] LOGGER_IMPLEMENTATIONS = { + "org.hibernate.jpa.internal.JpaLogger_$logger", + "org.hibernate.internal.CoreMessageLogger_$logger", + "org.hibernate.internal.log.DeprecationLogger_$logger", + "org.hibernate.internal.log.IncubationLogger_$logger", + "org.hibernate.internal.log.ConnectionAccessLogger_$logger", + "org.hibernate.internal.log.ConnectionInfoLogger_$logger", + "org.hibernate.internal.log.StatisticsLogger_$logger", + "org.hibernate.internal.log.UrlMessageBundle_$logger", + "org.hibernate.internal.SessionFactoryLogging_$logger", + "org.hibernate.internal.SessionFactoryRegistryMessageLogger_$logger", + "org.hibernate.internal.SessionLogging_$logger", + "org.hibernate.boot.BootLogging_$logger", + "org.hibernate.boot.archive.scan.internal.ScannerLogger_$logger", + "org.hibernate.boot.beanvalidation.BeanValidationLogger_$logger", + "org.hibernate.boot.jaxb.JaxbLogger_$logger", + "org.hibernate.dialect.DialectLogging_$logger", + "org.hibernate.engine.jdbc.JdbcLogging_$logger", + "org.hibernate.engine.jdbc.batch.JdbcBatchLogging_$logger", + "org.hibernate.engine.jdbc.connections.internal.ConnectionProviderLogging_$logger", + "org.hibernate.engine.jdbc.env.internal.LobCreationLogging_$logger", + "org.hibernate.engine.jdbc.spi.SQLExceptionLogging_$logger", + "org.hibernate.engine.internal.NaturalIdLogging_$logger", + "org.hibernate.engine.internal.PersistenceContextLogging_$logger", + "org.hibernate.engine.internal.SessionMetricsLogger_$logger", + "org.hibernate.engine.internal.VersionLogger_$logger", + "org.hibernate.resource.jdbc.internal.LogicalConnectionLogging_$logger", + "org.hibernate.resource.jdbc.internal.ResourceRegistryLogger_$logger", + "org.hibernate.resource.transaction.internal.SynchronizationLogging_$logger", + "org.hibernate.resource.transaction.backend.jta.internal.JtaLogging_$logger", + "org.hibernate.resource.beans.internal.BeansMessageLogger_$logger", + "org.hibernate.service.internal.ServiceLogger_$logger", + "org.hibernate.sql.ast.tree.SqlAstTreeLogger_$logger", + "org.hibernate.sql.exec.SqlExecLogger_$logger", + "org.hibernate.sql.model.ModelMutationLogging_$logger", + "org.hibernate.sql.results.LoadingLogger_$logger", + "org.hibernate.sql.results.ResultsLogger_$logger", + "org.hibernate.sql.results.graph.embeddable.EmbeddableLoadingLogger_$logger", + "org.hibernate.query.QueryLogging_$logger", + "org.hibernate.query.hql.HqlLogging_$logger", + "org.hibernate.id.UUIDLogger_$logger", + "org.hibernate.id.enhanced.OptimizerLogger_$logger", + "org.hibernate.id.enhanced.SequenceGeneratorLogger_$logger", + "org.hibernate.id.enhanced.TableGeneratorLogger_$logger", + "org.hibernate.action.internal.ActionLogging_$logger", + "org.hibernate.cache.spi.SecondLevelCacheLogger_$logger", + "org.hibernate.collection.internal.CollectionLogger_$logger", + "org.hibernate.context.internal.CurrentSessionLogging_$logger", + "org.hibernate.event.internal.EntityCopyLogging_$logger", + "org.hibernate.event.internal.EventListenerLogging_$logger", + "org.hibernate.loader.ast.internal.MultiKeyLoadLogging_$logger", + "org.hibernate.metamodel.mapping.MappingModelCreationLogging_$logger", + "org.hibernate.bytecode.enhance.internal.BytecodeEnhancementLogging_$logger", + "org.hibernate.bytecode.enhance.spi.interceptor.BytecodeInterceptorLogging_$logger", + }; + + private static final Class[] EVENT_LISTENER_TYPES = { + org.hibernate.event.spi.AutoFlushEventListener.class, + org.hibernate.event.spi.ClearEventListener.class, + org.hibernate.event.spi.DeleteEventListener.class, + org.hibernate.event.spi.DirtyCheckEventListener.class, + org.hibernate.event.spi.EvictEventListener.class, + org.hibernate.event.spi.FlushEntityEventListener.class, + org.hibernate.event.spi.FlushEventListener.class, + org.hibernate.event.spi.InitializeCollectionEventListener.class, + org.hibernate.event.spi.LoadEventListener.class, + org.hibernate.event.spi.LockEventListener.class, + org.hibernate.event.spi.MergeEventListener.class, + org.hibernate.event.spi.PersistEventListener.class, + org.hibernate.event.spi.PostCollectionRecreateEventListener.class, + org.hibernate.event.spi.PostCollectionRemoveEventListener.class, + org.hibernate.event.spi.PostCollectionUpdateEventListener.class, + org.hibernate.event.spi.PostCommitDeleteEventListener.class, + org.hibernate.event.spi.PostCommitInsertEventListener.class, + org.hibernate.event.spi.PostCommitUpdateEventListener.class, + org.hibernate.event.spi.PostDeleteEventListener.class, + org.hibernate.event.spi.PostInsertEventListener.class, + org.hibernate.event.spi.PostLoadEventListener.class, + org.hibernate.event.spi.PostUpdateEventListener.class, + org.hibernate.event.spi.PostUpsertEventListener.class, + org.hibernate.event.spi.PreCollectionRecreateEventListener.class, + org.hibernate.event.spi.PreCollectionRemoveEventListener.class, + org.hibernate.event.spi.PreCollectionUpdateEventListener.class, + org.hibernate.event.spi.PreDeleteEventListener.class, + org.hibernate.event.spi.PreFlushEventListener.class, + org.hibernate.event.spi.PreInsertEventListener.class, + org.hibernate.event.spi.PreLoadEventListener.class, + org.hibernate.event.spi.PreUpdateEventListener.class, + org.hibernate.event.spi.PreUpsertEventListener.class, + org.hibernate.event.spi.RefreshEventListener.class, + org.hibernate.event.spi.ReplicateEventListener.class, + }; + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + for (String logger : LOGGER_IMPLEMENTATIONS) { + hints.reflection().registerTypeIfPresent(classLoader, logger, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, + MemberCategory.INVOKE_DECLARED_METHODS, + MemberCategory.INVOKE_PUBLIC_METHODS); + } + + for (Class listenerType : EVENT_LISTENER_TYPES) { + hints.reflection().registerType( + listenerType.arrayType(), + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); + } + + hints.reflection().registerTypeIfPresent(classLoader, + "org.hibernate.event.spi.PostActionEventListener[]", + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/native_image/WebRuntimeHints.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/native_image/WebRuntimeHints.java new file mode 100644 index 0000000..6ab7792 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/native_image/WebRuntimeHints.java @@ -0,0 +1,12 @@ +package com.gregor_lohaus.gtransfer.native_image; + +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; + +public class WebRuntimeHints implements RuntimeHintsRegistrar { + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + hints.resources().registerPattern("templates/**"); + hints.resources().registerPattern("static/**"); + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/AbstractStorageService.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/AbstractStorageService.java new file mode 100644 index 0000000..4c79ee1 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/AbstractStorageService.java @@ -0,0 +1,16 @@ +package com.gregor_lohaus.gtransfer.services.filewriter; + +import java.nio.file.Path; +import java.util.Optional; +import java.util.OptionalLong; + +public abstract class AbstractStorageService { + protected Path root; + + public AbstractStorageService(Path root) { + this.root = root; + } + + abstract public OptionalLong put(String id, byte[] data); + abstract public Optional get(String id); +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/DummyStorageService.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/DummyStorageService.java new file mode 100644 index 0000000..a24399e --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/DummyStorageService.java @@ -0,0 +1,22 @@ +package com.gregor_lohaus.gtransfer.services.filewriter; + +import java.nio.file.Path; +import java.util.Optional; +import java.util.OptionalLong; + +public class DummyStorageService extends AbstractStorageService { + + public DummyStorageService(Path root) { + super(root); + } + + @Override + public OptionalLong put(String id, byte[] data) { + return OptionalLong.empty(); + } + + @Override + public Optional get(String id) { + return Optional.empty(); + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/LocalStorageService.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/LocalStorageService.java new file mode 100644 index 0000000..9ff1cd4 --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/LocalStorageService.java @@ -0,0 +1,36 @@ +package com.gregor_lohaus.gtransfer.services.filewriter; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Optional; +import java.util.OptionalLong; + +public class LocalStorageService extends AbstractStorageService { + + public LocalStorageService(Path root) { + super(root); + } + + @Override + public OptionalLong put(String id, byte[] data) { + try { + Files.createDirectories(root); + Files.write(root.resolve(id), data); + return OptionalLong.of(data.length); + } catch (IOException e) { + return OptionalLong.empty(); + } + } + + @Override + public Optional get(String id) { + try { + Path target = root.resolve(id); + if (!Files.exists(target)) return Optional.empty(); + return Optional.of(Files.readAllBytes(target)); + } catch (IOException e) { + return Optional.empty(); + } + } +} diff --git a/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/StorageServiceConfiguration.java b/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/StorageServiceConfiguration.java new file mode 100644 index 0000000..6268dff --- /dev/null +++ b/Backend/src/main/java/com/gregor_lohaus/gtransfer/services/filewriter/StorageServiceConfiguration.java @@ -0,0 +1,25 @@ +package com.gregor_lohaus.gtransfer.services.filewriter; + +import java.nio.file.Path; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.gregor_lohaus.gtransfer.config.types.StorageServiceType; + +@Configuration +public class StorageServiceConfiguration { + + //TODO S3 implementation + @Bean + public AbstractStorageService storageService( + @Value("${gtransfer-config.storageService.type}") StorageServiceType type, + @Value("${gtransfer-config.storageService.root}") String root) { + return switch (type) { + case LOCAL -> new LocalStorageService(Path.of(root)); + case DUMMY -> new DummyStorageService(Path.of(root)); + case S3 -> new LocalStorageService(Path.of(root)); + }; + } +} diff --git a/Backend/src/main/resources/META-INF/spring.factories b/Backend/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..9310b1a --- /dev/null +++ b/Backend/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.EnvironmentPostProcessor=com.gregor_lohaus.gtransfer.config.ConfigEnvironmentPostProcessor diff --git a/Backend/src/main/resources/application.properties b/Backend/src/main/resources/application.properties new file mode 100644 index 0000000..1ccde43 --- /dev/null +++ b/Backend/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=gtransfer diff --git a/Backend/src/main/resources/static/style.css b/Backend/src/main/resources/static/style.css new file mode 100644 index 0000000..0ffbbc0 --- /dev/null +++ b/Backend/src/main/resources/static/style.css @@ -0,0 +1,67 @@ +body { + background-color: #0d1117; + color: #e6edf3; +} + +.brand { + letter-spacing: -0.5px; + color: #e6edf3; +} +.brand span { + color: #3fb950; +} + +.hero-title { + font-size: 3rem; + font-weight: 800; + letter-spacing: -1px; + line-height: 1.1; +} +.hero-title span { + color: #3fb950; +} + +.hero-subtitle { + color: #8b949e; + max-width: 480px; +} + +.drop-zone { + border: 2px dashed #30363d; + border-radius: 16px; + background-color: #161b22; + cursor: pointer; + transition: border-color 0.2s, background-color 0.2s; + max-width: 520px; +} +.drop-zone:hover, +.drop-zone.dragover { + border-color: #3fb950; + background-color: #0d1117; +} + +.drop-zone-icon { + font-size: 2.5rem; + opacity: 0.6; +} + +.drop-zone-text { + color: #8b949e; +} +.drop-zone-text strong { + color: #3fb950; +} + +.badge-e2e { + background-color: #1a2f1e; + color: #3fb950; + border: 1px solid #2ea043; + font-size: 0.78rem; +} + +footer, footer a { + color: #484f58; +} +footer a:hover { + color: #8b949e; +} diff --git a/Backend/src/main/resources/static/upload.js b/Backend/src/main/resources/static/upload.js new file mode 100644 index 0000000..c415450 --- /dev/null +++ b/Backend/src/main/resources/static/upload.js @@ -0,0 +1,135 @@ +const dropZone = document.getElementById('drop-zone'); +const fileInput = document.getElementById('file-input'); + +const views = { + prompt: document.getElementById('view-prompt'), + selected: document.getElementById('view-selected'), + uploading: document.getElementById('view-uploading'), + result: document.getElementById('view-result'), +}; + +let selectedFile = null; + +function showView(name) { + Object.entries(views).forEach(([key, el]) => el.classList.toggle('d-none', key !== name)); +} + +// ── File selection ──────────────────────────────────────────────────────────── + +dropZone.addEventListener('click', () => { + if (views.prompt.classList.contains('d-none')) return; + fileInput.click(); +}); + +fileInput.addEventListener('change', e => { + if (e.target.files[0]) selectFile(e.target.files[0]); +}); + +dropZone.addEventListener('dragover', e => { + e.preventDefault(); + dropZone.classList.add('dragover'); +}); + +dropZone.addEventListener('dragleave', () => dropZone.classList.remove('dragover')); + +dropZone.addEventListener('drop', e => { + e.preventDefault(); + dropZone.classList.remove('dragover'); + if (e.dataTransfer.files[0]) selectFile(e.dataTransfer.files[0]); +}); + +function selectFile(file) { + selectedFile = file; + document.getElementById('selected-name').textContent = file.name; + showView('selected'); +} + +document.getElementById('reset-btn').addEventListener('click', e => { + e.stopPropagation(); + selectedFile = null; + fileInput.value = ''; + showView('prompt'); +}); + +document.getElementById('new-upload-btn').addEventListener('click', e => { + e.stopPropagation(); + selectedFile = null; + fileInput.value = ''; + showView('prompt'); +}); + +// ── Upload ──────────────────────────────────────────────────────────────────── + +document.getElementById('upload-btn').addEventListener('click', async e => { + e.stopPropagation(); + await upload(); +}); + +function setStatus(msg) { + document.getElementById('upload-status').textContent = msg; +} + +async function upload() { + const file = selectedFile; + showView('uploading'); + + try { + setStatus('Generating encryption key\u2026'); + const key = await crypto.subtle.generateKey( + { name: 'AES-GCM', length: 256 }, + true, + ['encrypt', 'decrypt'] + ); + + const iv = crypto.getRandomValues(new Uint8Array(12)); + + setStatus('Encrypting\u2026'); + const ciphertext = await crypto.subtle.encrypt( + { name: 'AES-GCM', iv }, + key, + await file.arrayBuffer() + ); + + // Payload: 12-byte IV prepended to ciphertext + const payload = new Uint8Array(12 + ciphertext.byteLength); + payload.set(iv, 0); + payload.set(new Uint8Array(ciphertext), 12); + + // SHA-256(rawKey) → file identifier sent to server (server never sees the key) + const rawKey = await crypto.subtle.exportKey('raw', key); + const hash = Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', rawKey))) + .map(b => b.toString(16).padStart(2, '0')) + .join(''); + + // Base64url-encode key for URL fragment + const base64urlKey = btoa(String.fromCharCode(...new Uint8Array(rawKey))) + .replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); + + setStatus('Uploading\u2026'); + const formData = new FormData(); + formData.append('file', new Blob([payload]), file.name); + formData.append('hash', hash); + formData.append('name', file.name); + + const response = await fetch('/upload', { method: 'POST', body: formData }); + if (!response.ok) throw new Error(`Server responded with ${response.status}`); + + const { id } = await response.json(); + document.getElementById('share-link').value = + `${window.location.origin}/download/${id}#${base64urlKey}`; + showView('result'); + + } catch (err) { + setStatus(`Error: ${err.message}`); + } +} + +// ── Copy link ───────────────────────────────────────────────────────────────── + +document.getElementById('copy-btn').addEventListener('click', async e => { + e.stopPropagation(); + await navigator.clipboard.writeText(document.getElementById('share-link').value); + const btn = document.getElementById('copy-btn'); + btn.textContent = 'Copied!'; + setTimeout(() => { btn.textContent = 'Copy'; }, 2000); +}); diff --git a/Backend/src/main/resources/templates/index.html b/Backend/src/main/resources/templates/index.html new file mode 100644 index 0000000..a3e1804 --- /dev/null +++ b/Backend/src/main/resources/templates/index.html @@ -0,0 +1,87 @@ + + + + + + GTransfer + + + + + + + + + + +
+
+
+

Send files.
Privately.

+

+ Share files of any size with end-to-end encryption. + No account needed. Files are encrypted before they leave your device. +

+
+
+
+ + +
+
📂
+
+ Choose a file + or drag and drop here +
+
Any file type · Up to 10GB
+
+ + +
+
📄
+
+
+ + +
+
+ + +
+
+
+ Loading... +
+
+
Preparing…
+
+ + +
+
+
Your file is ready to share
+
+ + +
+ +
+ + +
+
+
+
+ + + + + diff --git a/Backend/src/test/java/com/gregor_lohaus/gtransfer/GtransferApplicationTests.java b/Backend/src/test/java/com/gregor_lohaus/gtransfer/GtransferApplicationTests.java new file mode 100644 index 0000000..931b735 --- /dev/null +++ b/Backend/src/test/java/com/gregor_lohaus/gtransfer/GtransferApplicationTests.java @@ -0,0 +1,13 @@ +package com.gregor_lohaus.gtransfer; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class GtransferApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 0000000..fac2e6e --- /dev/null +++ b/devenv.lock @@ -0,0 +1,65 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1771852244, + "narHash": "sha256-4t3gQ4s7kqtDwSiE74Px6szKJtKtcoHgUiNmIm+Xl9Y=", + "owner": "cachix", + "repo": "devenv", + "rev": "c88c14a32d06173867e26b7d4f5daed38a3f6f1e", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "nixpkgs": { + "inputs": { + "nixpkgs-src": "nixpkgs-src" + }, + "locked": { + "lastModified": 1770434727, + "narHash": "sha256-YzOZRgiqIccnkkZvckQha7wvOfN2z50xEdPvfgu6sf8=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "8430f16a39c27bdeef236f1eeb56f0b51b33d348", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "nixpkgs-src": { + "flake": false, + "locked": { + "lastModified": 1769922788, + "narHash": "sha256-H3AfG4ObMDTkTJYkd8cz1/RbY9LatN5Mk4UF48VuSXc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "207d15f1a6603226e1e223dc79ac29c7846da32e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} \ No newline at end of file diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 0000000..85638a0 --- /dev/null +++ b/devenv.nix @@ -0,0 +1,57 @@ +{ pkgs, lib, config, inputs, ... }: + +{ + # https://devenv.sh/basics/ + env.GRAALVM_HOME = "${pkgs.graalvmPackages.graalvm-ce}"; + + # https://devenv.sh/packages/ + packages = [ + pkgs.graalvmPackages.graalvm-ce + pkgs.watchexec + ]; + + # https://devenv.sh/languages/ + languages.java.enable = true; + languages.java.lsp.enable = true; + languages.java.gradle.enable = true; + languages.java.jdk.package = pkgs.jdk25_headless; + # https://devenv.sh/processes/ + # processes.cargo-watch.exec = "cargo-watch"; + # process.manager.implementation = "mprocs"; + processes.watchbuild = { + exec = "watchexec -r -e java,html,css,js -w ./Backend/src -- build-backend"; + }; + processes.runbin = { + exec = "watchexec -r -w ./Backend/buildcompleted.at ./Backend/build/native/nativeCompile/gtransfer"; + }; + # https://devenv.sh/services/ + services.postgres.enable = true; + services.postgres.listen_addresses = "localhost"; + services.postgres.port = 5432; + services.postgres.initialDatabases = [ + {name="gtransfer";user="gtransfer";pass="gtransfer";} + ]; + + # https://devenv.sh/scripts/ + scripts.build-backend.exec = '' + gradle -p ./Backend build && echo $(date) > ./Backend/buildcompleted.at + ''; + + enterShell = '' + ''; + + # https://devenv.sh/tasks/ + # tasks = { + # "myproj:setup".exec = "mytool build"; + # "devenv:enterShell".after = [ "myproj:setup" ]; + # }; + + # https://devenv.sh/tests/ + enterTest = '' + ''; + + # https://devenv.sh/git-hooks/ + # git-hooks.hooks.shellcheck.enable = true; + + # See full reference at https://devenv.sh/reference/options/ +} diff --git a/devenv.yaml b/devenv.yaml new file mode 100644 index 0000000..116a2ad --- /dev/null +++ b/devenv.yaml @@ -0,0 +1,15 @@ +# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json +inputs: + nixpkgs: + url: github:cachix/devenv-nixpkgs/rolling + +# If you're using non-OSS software, you can set allowUnfree to true. +# allowUnfree: true + +# If you're willing to use a package that's vulnerable +# permittedInsecurePackages: +# - "openssl-1.1.1w" + +# If you have more than one devenv you can merge them +#imports: +# - ./backend diff --git a/layout.kdl b/layout.kdl new file mode 100644 index 0000000..b2defb3 --- /dev/null +++ b/layout.kdl @@ -0,0 +1,337 @@ +layout { + cwd "/home/anon" + tab name="Tab #1" focus=true { + pane size=1 borderless=true { + plugin location="zellij:tab-bar" + } + pane command="devenv" cwd="Dev/GTransfer" { + args "shell" + } + pane size=1 borderless=true { + plugin location="zellij:status-bar" + } + floating_panes { + pane command="devenv" cwd="Dev/GTransfer" { + height 30 + width 170 + x 85 + y 16 + args "up" + } + pane command="hx" cwd=".config/gtransfer" { + height 30 + width 170 + x 87 + y 18 + args "config.toml" + } + pane command="devenv" cwd="Dev/GTransfer" { + height 30 + width 170 + x 89 + y 20 + args "shell" + } + pane command="claude" cwd="Dev/GTransfer" { + height 30 + width 170 + x 91 + y 22 + args "." + } + pane command="yy" cwd="Dev/GTransfer" { + height 30 + width 170 + x 93 + y 24 + } + } + } + new_tab_template { + pane size=1 borderless=true { + plugin location="zellij:tab-bar" + } + pane cwd="/home/anon" + pane size=1 borderless=true { + plugin location="zellij:status-bar" + } + } + swap_tiled_layout name="vertical" { + tab max_panes=5 { + pane size=1 borderless=true { + plugin location="tab-bar" + } + pane { + pane split_direction="vertical" { + pane + pane { + children + } + } + } + pane size=1 borderless=true { + plugin location="status-bar" + } + } + tab max_panes=8 { + pane size=1 borderless=true { + plugin location="tab-bar" + } + pane { + pane split_direction="vertical" { + pane { + children + } + pane { + pane + pane + pane + pane + } + } + } + pane size=1 borderless=true { + plugin location="status-bar" + } + } + tab max_panes=12 { + pane size=1 borderless=true { + plugin location="tab-bar" + } + pane { + pane split_direction="vertical" { + pane { + children + } + pane { + pane + pane + pane + pane + } + pane { + pane + pane + pane + pane + } + } + } + pane size=1 borderless=true { + plugin location="status-bar" + } + } + } + swap_tiled_layout name="horizontal" { + tab max_panes=4 { + pane size=1 borderless=true { + plugin location="tab-bar" + } + pane { + pane + pane + } + pane size=1 borderless=true { + plugin location="status-bar" + } + } + tab max_panes=8 { + pane size=1 borderless=true { + plugin location="tab-bar" + } + pane { + pane { + pane split_direction="vertical" { + children + } + pane split_direction="vertical" { + pane + pane + pane + pane + } + } + } + pane size=1 borderless=true { + plugin location="status-bar" + } + } + tab max_panes=12 { + pane size=1 borderless=true { + plugin location="tab-bar" + } + pane { + pane { + pane split_direction="vertical" { + children + } + pane split_direction="vertical" { + pane + pane + pane + pane + } + pane split_direction="vertical" { + pane + pane + pane + pane + } + } + } + pane size=1 borderless=true { + plugin location="status-bar" + } + } + } + swap_tiled_layout name="stacked" { + tab min_panes=5 { + pane size=1 borderless=true { + plugin location="tab-bar" + } + pane { + pane split_direction="vertical" { + pane + pane stacked=true { + children + } + } + } + pane size=1 borderless=true { + plugin location="status-bar" + } + } + } + swap_floating_layout name="staggered" { + floating_panes { + } + } + swap_floating_layout name="enlarged" { + floating_panes max_panes=10 { + pane cwd="/home/anon" { + height "90%" + width "90%" + x "5%" + y 1 + } + pane cwd="/home/anon" { + height "90%" + width "90%" + x "5%" + y 2 + } + pane cwd="/home/anon" { + height "90%" + width "90%" + x "5%" + y 3 + } + pane cwd="/home/anon" { + height "90%" + width "90%" + x "5%" + y 4 + } + pane cwd="/home/anon" { + height "90%" + width "90%" + x "5%" + y 5 + } + pane cwd="/home/anon" { + height "90%" + width "90%" + x "5%" + y 6 + } + pane cwd="/home/anon" { + height "90%" + width "90%" + x "5%" + y 7 + } + pane cwd="/home/anon" { + height "90%" + width "90%" + x "5%" + y 8 + } + pane cwd="/home/anon" { + height "90%" + width "90%" + x "5%" + y 9 + } + pane cwd="/home/anon" { + height "90%" + width "90%" + x 10 + y 10 + } + } + } + swap_floating_layout name="spread" { + floating_panes max_panes=1 { + pane cwd="/home/anon" { + x "50%" + y "50%" + } + } + floating_panes max_panes=2 { + pane cwd="/home/anon" { + width "45%" + x "1%" + y "25%" + } + pane cwd="/home/anon" { + width "45%" + x "50%" + y "25%" + } + } + floating_panes max_panes=3 { + pane cwd="/home/anon" { + height "45%" + width "45%" + y "55%" + } + pane cwd="/home/anon" { + width "45%" + x "1%" + y "1%" + } + pane cwd="/home/anon" { + width "45%" + x "50%" + y "1%" + } + } + floating_panes max_panes=4 { + pane cwd="/home/anon" { + height "45%" + width "45%" + x "1%" + y "55%" + } + pane cwd="/home/anon" { + height "45%" + width "45%" + x "50%" + y "55%" + } + pane cwd="/home/anon" { + height "45%" + width "45%" + x "1%" + y "1%" + } + pane cwd="/home/anon" { + height "45%" + width "45%" + x "50%" + y "1%" + } + } + } +} +