Initial commit
This commit is contained in:
commit
ccc0ab104a
.gitattributes.gitignore
.mvn/wrapper
README.mdcompose.yamlmvnwmvnw.cmdpom.xmlsrc
main
java/se/su/dsv/seshat
resources
test/java/se/su/dsv/seshat
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
33
.gitignore
vendored
Normal file
33
.gitignore
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
19
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
19
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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
|
||||
#
|
||||
# http://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.
|
||||
wrapperVersion=3.3.2
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
|
163
README.md
Normal file
163
README.md
Normal file
@ -0,0 +1,163 @@
|
||||
# Seshat Audio Transcription App
|
||||
|
||||
> Seshat was the ancient Egyptian goddess of writing, knowledge, and wisdom. She played a key role in Egyptian mythology as a scribe and keeper of records, closely associated with Thoth, the god of wisdom and writing. While Thoth was often considered her counterpart or consort, Seshat had her own distinct identity and responsibilities.
|
||||
|
||||
Seshat Audio Transcription App is a web application that allows users to upload audio files, transcribe them
|
||||
using Whisper AI, and manage their files. Users can monitor the status of their uploaded files and perform bulk
|
||||
operations like downloading or deleting multiple files.
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
- **User Authentication**:
|
||||
- Register, login, and logout functionalities.
|
||||
- Secure access to user-specific files and operations.
|
||||
|
||||
- **File Upload**:
|
||||
- Upload audio files with an option to specify the file's language.
|
||||
- File metadata is stored, including upload time, file name, and language.
|
||||
|
||||
- **File Processing**:
|
||||
- Transcription powered by AI tools (e.g., Whisper AI).
|
||||
- Job status monitoring: `PENDING`, `PROCESSING`, `COMPLETED`, and `FAILED`.
|
||||
|
||||
- **File Management**:
|
||||
- Bulk download (returns a ZIP file) and delete functionalities.
|
||||
- Displays the status of uploaded files.
|
||||
|
||||
- **Responsive UI**:
|
||||
- Built with Thymeleaf, Bootstrap, and JavaScript for a seamless user experience.
|
||||
|
||||
---
|
||||
|
||||
## Technologies Used
|
||||
|
||||
- **Backend**:
|
||||
- Spring Boot (Java 17)
|
||||
- Spring Security
|
||||
- Spring Data JPA
|
||||
- Hibernate
|
||||
|
||||
- **Database**:
|
||||
- MariaDB (Dockerized using Docker Compose)
|
||||
|
||||
- **Frontend**:
|
||||
- Thymeleaf
|
||||
- Bootstrap
|
||||
- JavaScript
|
||||
|
||||
- **Other Tools**:
|
||||
- Whisper AI for transcription
|
||||
- Apache Commons IO for file management
|
||||
- BlockingQueue for job queuing
|
||||
|
||||
---
|
||||
|
||||
## How to Run
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Java 17 or later
|
||||
- Docker and Docker Compose
|
||||
- Maven
|
||||
|
||||
### Steps to Run
|
||||
|
||||
1. **Clone the Repository**:
|
||||
```bash
|
||||
git clone https://github.com/your-repo/seshat-app.git
|
||||
cd seshat-app
|
||||
|
||||
2. **Create necessary directories**:
|
||||
```bash
|
||||
mkdir -p /seshat/uploads
|
||||
mkdir -p /seshat/outputs
|
||||
|
||||
3. **Set ownership of the directories**:
|
||||
- Important: Replace `$USER` with the username that runs the application.
|
||||
```bash
|
||||
sudo chown -R $USER:$USER /seshat
|
||||
|
||||
## File Upload Workflow
|
||||
- **User Uploads File**:
|
||||
- Users upload audio files through the upload form.
|
||||
- The form includes a language selection dropdown.
|
||||
|
||||
- **Store File and Metadata**:
|
||||
- The uploaded file is stored in the user's directory.
|
||||
- Metadata such as the file name, upload time, and selected language is saved to the database.
|
||||
|
||||
- **Queue for Processing**:
|
||||
- Uploaded files are added to a job queue with a `PENDING` status.
|
||||
- The transcription process begins when a job is picked from the queue.
|
||||
|
||||
- **Transcription and Updates**:
|
||||
- The system calls Whisper AI to transcribe the audio.
|
||||
- The job status is updated to `PROCESSING`, `COMPLETED`, or `FAILED` based on the outcome.
|
||||
|
||||
## Bulk Operations
|
||||
|
||||
### Bulk Download
|
||||
|
||||
- Users can select multiple files for download.
|
||||
- The system creates a ZIP file containing the selected files and sends it to the user.
|
||||
|
||||
### Bulk Delete
|
||||
|
||||
- Users can select multiple files and delete them in one operation.
|
||||
- Deleted files are removed from both the database and storage.
|
||||
|
||||
## Database Schema
|
||||
|
||||
### FileMetadata Table
|
||||
|
||||
| Column | Type | Description |
|
||||
|--------------|----------------|------------------------------|
|
||||
| `id` | `BIGINT` | Unique identifier |
|
||||
| `file_name` | `VARCHAR(255)` | Original file name |
|
||||
| `file_path` | `TEXT` | Physical file location |
|
||||
| `language` | `VARCHAR(10)` | Language of the audio file |
|
||||
| `job_status` | `VARCHAR(20)` | Processing status |
|
||||
| `user_id` | `BIGINT` | Associated user ID |
|
||||
| `uploaded_at`| `DATETIME` | File upload timestamp |
|
||||
|
||||
## Development Notes
|
||||
|
||||
### Endpoints Overview
|
||||
|
||||
| HTTP Method | Endpoint | Description |
|
||||
|-------------|------------------------|---------------------------|
|
||||
| `POST` | `/files/upload` | Uploads a file |
|
||||
| `POST` | `/files/download-zip` | Bulk download as a ZIP |
|
||||
| `POST` | `/files/bulk-delete` | Bulk delete files |
|
||||
| `GET` | `/files/manage` | File management page |
|
||||
|
||||
|
||||
## Configuration
|
||||
- ** `application.properties`**:
|
||||
- spring.servlet.multipart.max-file-size=5GB
|
||||
- spring.servlet.multipart.max-request-size=5GB
|
||||
- app.upload-root=/seshat/uploads
|
||||
- app.output-root=/seshat/outputs
|
||||
|
||||
## Future Enhancements
|
||||
- **Single sign on**:
|
||||
- Implement OAuth2 for single sign-on.
|
||||
- **Video Transcription**:
|
||||
- Extend the app to support video files when and if whisper AI will support video files.
|
||||
- Extract audio from video files and transcribe the audio content.
|
||||
- **Real-time progress tracking for transcription jobs**:
|
||||
- Users can see the progress of their transcription jobs without refreshing the page.
|
||||
- **Multifile upload**:
|
||||
- Allow users to upload multiple files at once.
|
||||
- **Ability to select transcription output by format**:
|
||||
- Allow users to select the output format of the transcription (e.g., plain text, JSON, srt)
|
||||
- **Uploaded at date should also be the same on the generated files from the transcription**:
|
||||
- The date of the file should be the same as the uploaded date.
|
||||
- **Save the metadata of the input file**:
|
||||
- Save the metadata of the input file in the database.
|
||||
- So we can infer which generated file corresponds to which input file.
|
||||
## Contributors
|
||||
- **First demo version**:
|
||||
- Nikolaus Athanassiadis
|
14
compose.yaml
Normal file
14
compose.yaml
Normal file
@ -0,0 +1,14 @@
|
||||
services:
|
||||
mariadb:
|
||||
image: 'mariadb:latest'
|
||||
environment:
|
||||
- 'MARIADB_DATABASE=seshat'
|
||||
- 'MARIADB_PASSWORD=secret'
|
||||
- 'MARIADB_ROOT_PASSWORD=verysecret'
|
||||
- 'MARIADB_USER=myuser'
|
||||
ports:
|
||||
- '3306:3306'
|
||||
volumes:
|
||||
- mariadb_data:/var/lib/mysql
|
||||
volumes:
|
||||
mariadb_data:
|
259
mvnw
vendored
Executable file
259
mvnw
vendored
Executable file
@ -0,0 +1,259 @@
|
||||
#!/bin/sh
|
||||
# ----------------------------------------------------------------------------
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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
|
||||
#
|
||||
# http://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.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
|
||||
# MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
set -euf
|
||||
[ "${MVNW_VERBOSE-}" != debug ] || set -x
|
||||
|
||||
# OS specific support.
|
||||
native_path() { printf %s\\n "$1"; }
|
||||
case "$(uname)" in
|
||||
CYGWIN* | MINGW*)
|
||||
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
|
||||
native_path() { cygpath --path --windows "$1"; }
|
||||
;;
|
||||
esac
|
||||
|
||||
# set JAVACMD and JAVACCMD
|
||||
set_java_home() {
|
||||
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
|
||||
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"
|
||||
JAVACCMD="$JAVA_HOME/jre/sh/javac"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
JAVACCMD="$JAVA_HOME/bin/javac"
|
||||
|
||||
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
|
||||
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
|
||||
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
JAVACMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v java
|
||||
)" || :
|
||||
JAVACCMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v javac
|
||||
)" || :
|
||||
|
||||
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
|
||||
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# hash string like Java String::hashCode
|
||||
hash_string() {
|
||||
str="${1:-}" h=0
|
||||
while [ -n "$str" ]; do
|
||||
char="${str%"${str#?}"}"
|
||||
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
|
||||
str="${str#?}"
|
||||
done
|
||||
printf %x\\n $h
|
||||
}
|
||||
|
||||
verbose() { :; }
|
||||
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
|
||||
|
||||
die() {
|
||||
printf %s\\n "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
trim() {
|
||||
# MWRAPPER-139:
|
||||
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
|
||||
# Needed for removing poorly interpreted newline sequences when running in more
|
||||
# exotic environments such as mingw bash on Windows.
|
||||
printf "%s" "${1}" | tr -d '[:space:]'
|
||||
}
|
||||
|
||||
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
|
||||
while IFS="=" read -r key value; do
|
||||
case "${key-}" in
|
||||
distributionUrl) distributionUrl=$(trim "${value-}") ;;
|
||||
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
|
||||
esac
|
||||
done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
|
||||
case "${distributionUrl##*/}" in
|
||||
maven-mvnd-*bin.*)
|
||||
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
|
||||
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
|
||||
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
|
||||
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
|
||||
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
|
||||
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
|
||||
*)
|
||||
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
|
||||
distributionPlatform=linux-amd64
|
||||
;;
|
||||
esac
|
||||
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
|
||||
;;
|
||||
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
|
||||
*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
|
||||
esac
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
distributionUrlNameMain="${distributionUrlName%.*}"
|
||||
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
|
||||
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
|
||||
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
|
||||
|
||||
exec_maven() {
|
||||
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
|
||||
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
|
||||
}
|
||||
|
||||
if [ -d "$MAVEN_HOME" ]; then
|
||||
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
exec_maven "$@"
|
||||
fi
|
||||
|
||||
case "${distributionUrl-}" in
|
||||
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
|
||||
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
|
||||
esac
|
||||
|
||||
# prepare tmp dir
|
||||
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
|
||||
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
|
||||
trap clean HUP INT TERM EXIT
|
||||
else
|
||||
die "cannot create temp dir"
|
||||
fi
|
||||
|
||||
mkdir -p -- "${MAVEN_HOME%/*}"
|
||||
|
||||
# Download and Install Apache Maven
|
||||
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
verbose "Downloading from: $distributionUrl"
|
||||
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
# select .zip or .tar.gz
|
||||
if ! command -v unzip >/dev/null; then
|
||||
distributionUrl="${distributionUrl%.zip}.tar.gz"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
fi
|
||||
|
||||
# verbose opt
|
||||
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
|
||||
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
|
||||
|
||||
# normalize http auth
|
||||
case "${MVNW_PASSWORD:+has-password}" in
|
||||
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
esac
|
||||
|
||||
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
|
||||
verbose "Found wget ... using wget"
|
||||
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
|
||||
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
|
||||
verbose "Found curl ... using curl"
|
||||
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
|
||||
elif set_java_home; then
|
||||
verbose "Falling back to use Java to download"
|
||||
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
|
||||
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
cat >"$javaSource" <<-END
|
||||
public class Downloader extends java.net.Authenticator
|
||||
{
|
||||
protected java.net.PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
|
||||
}
|
||||
public static void main( String[] args ) throws Exception
|
||||
{
|
||||
setDefault( new Downloader() );
|
||||
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
|
||||
}
|
||||
}
|
||||
END
|
||||
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
|
||||
verbose " - Compiling Downloader.java ..."
|
||||
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
|
||||
verbose " - Running Downloader.java ..."
|
||||
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
|
||||
fi
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
if [ -n "${distributionSha256Sum-}" ]; then
|
||||
distributionSha256Result=false
|
||||
if [ "$MVN_CMD" = mvnd.sh ]; then
|
||||
echo "Checksum validation is not supported for maven-mvnd." >&2
|
||||
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
elif command -v sha256sum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
elif command -v shasum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
else
|
||||
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
|
||||
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ $distributionSha256Result = false ]; then
|
||||
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
|
||||
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# unzip and move
|
||||
if command -v unzip >/dev/null; then
|
||||
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
|
||||
else
|
||||
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
|
||||
fi
|
||||
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
|
||||
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
||||
|
||||
clean || :
|
||||
exec_maven "$@"
|
149
mvnw.cmd
vendored
Normal file
149
mvnw.cmd
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
<# : batch portion
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
|
||||
@SET __MVNW_CMD__=
|
||||
@SET __MVNW_ERROR__=
|
||||
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
|
||||
@SET PSModulePath=
|
||||
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
|
||||
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
|
||||
)
|
||||
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
|
||||
@SET __MVNW_PSMODULEP_SAVE=
|
||||
@SET __MVNW_ARG0_NAME__=
|
||||
@SET MVNW_USERNAME=
|
||||
@SET MVNW_PASSWORD=
|
||||
@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
|
||||
@echo Cannot start maven from wrapper >&2 && exit /b 1
|
||||
@GOTO :EOF
|
||||
: end batch / begin powershell #>
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
if ($env:MVNW_VERBOSE -eq "true") {
|
||||
$VerbosePreference = "Continue"
|
||||
}
|
||||
|
||||
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
|
||||
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
|
||||
if (!$distributionUrl) {
|
||||
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||
}
|
||||
|
||||
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
|
||||
"maven-mvnd-*" {
|
||||
$USE_MVND = $true
|
||||
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
|
||||
$MVN_CMD = "mvnd.cmd"
|
||||
break
|
||||
}
|
||||
default {
|
||||
$USE_MVND = $false
|
||||
$MVN_CMD = $script -replace '^mvnw','mvn'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
if ($env:MVNW_REPOURL) {
|
||||
$MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
|
||||
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
|
||||
}
|
||||
$distributionUrlName = $distributionUrl -replace '^.*/',''
|
||||
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
|
||||
$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
|
||||
if ($env:MAVEN_USER_HOME) {
|
||||
$MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
|
||||
}
|
||||
$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
|
||||
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
|
||||
|
||||
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
|
||||
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
exit $?
|
||||
}
|
||||
|
||||
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
|
||||
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
|
||||
}
|
||||
|
||||
# prepare tmp dir
|
||||
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
|
||||
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
|
||||
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
|
||||
trap {
|
||||
if ($TMP_DOWNLOAD_DIR.Exists) {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
}
|
||||
|
||||
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
|
||||
|
||||
# Download and Install Apache Maven
|
||||
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
Write-Verbose "Downloading from: $distributionUrl"
|
||||
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
|
||||
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
|
||||
}
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
|
||||
if ($distributionSha256Sum) {
|
||||
if ($USE_MVND) {
|
||||
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
|
||||
}
|
||||
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
|
||||
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
|
||||
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
|
||||
}
|
||||
}
|
||||
|
||||
# unzip and move
|
||||
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
|
||||
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
|
||||
try {
|
||||
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
|
||||
} catch {
|
||||
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
|
||||
Write-Error "fail to move MAVEN_HOME"
|
||||
}
|
||||
} finally {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
102
pom.xml
Normal file
102
pom.xml
Normal file
@ -0,0 +1,102 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>se.su.dsv</groupId>
|
||||
<artifactId>seshat</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>seshat</name>
|
||||
<description>seshat</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<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-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.thymeleaf.extras</groupId>
|
||||
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-docker-compose</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</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>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
24
src/main/java/se/su/dsv/seshat/Application.java
Normal file
24
src/main/java/se/su/dsv/seshat/Application.java
Normal file
@ -0,0 +1,24 @@
|
||||
package se.su.dsv.seshat;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import se.su.dsv.seshat.services.JobProcessorService;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private JobProcessorService jobProcessorService;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
jobProcessorService.addPendingJobsToQueue();
|
||||
}
|
||||
|
||||
}
|
13
src/main/java/se/su/dsv/seshat/ServletInitializer.java
Normal file
13
src/main/java/se/su/dsv/seshat/ServletInitializer.java
Normal file
@ -0,0 +1,13 @@
|
||||
package se.su.dsv.seshat;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(Application.class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package se.su.dsv.seshat.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
|
||||
httpSecurity.csrf(AbstractHttpConfigurer::disable)
|
||||
.authorizeHttpRequests(authorize -> authorize
|
||||
.requestMatchers("/css/**", "/js/**", "/register", "/login").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.formLogin(login -> login
|
||||
.loginPage("/login")
|
||||
.defaultSuccessUrl("/files/manage", true)
|
||||
.permitAll()
|
||||
)
|
||||
.logout(logout -> logout
|
||||
.logoutSuccessUrl("/login?logout")
|
||||
.permitAll()
|
||||
);
|
||||
return httpSecurity.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BCryptPasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
}
|
145
src/main/java/se/su/dsv/seshat/controllers/FileController.java
Normal file
145
src/main/java/se/su/dsv/seshat/controllers/FileController.java
Normal file
@ -0,0 +1,145 @@
|
||||
package se.su.dsv.seshat.controllers;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import se.su.dsv.seshat.entities.AppUser;
|
||||
import se.su.dsv.seshat.entities.FileMetadata;
|
||||
import se.su.dsv.seshat.services.JobProcessorService;
|
||||
import se.su.dsv.seshat.services.StorageService;
|
||||
import se.su.dsv.seshat.services.UserService;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Controller
|
||||
public class FileController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(FileController.class);
|
||||
private final StorageService storageService;
|
||||
private final UserService userService;
|
||||
private final JobProcessorService jobProcessorService;
|
||||
|
||||
public FileController(StorageService storageService, UserService userService, JobProcessorService jobProcessorService) {
|
||||
this.storageService = storageService;
|
||||
this.userService = userService;
|
||||
this.jobProcessorService = jobProcessorService;
|
||||
}
|
||||
|
||||
@GetMapping("/files/manage")
|
||||
public String showFileManagementPage(Authentication authentication, Model model) {
|
||||
AppUser user = userService.getUserByUsername(authentication.getName());
|
||||
List<FileMetadata> files = storageService.getUserTranscriptons(user);
|
||||
List<FileMetadata> uploaded = storageService.getUserUplaods(user);
|
||||
|
||||
List<FileMetadata> statuses = uploaded.stream()
|
||||
.filter(file -> file.getJobStatus() != null)
|
||||
.toList();
|
||||
|
||||
model.addAttribute("files", files);
|
||||
model.addAttribute("statuses", statuses);
|
||||
|
||||
return "file-management";
|
||||
}
|
||||
|
||||
@PostMapping("/files/upload")
|
||||
public String uploadFile(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam(name = "language", defaultValue = "auto") String language,
|
||||
Authentication authentication,
|
||||
Model model) {
|
||||
try {
|
||||
AppUser user = userService.getUserByUsername(authentication.getName());
|
||||
FileMetadata fileMetadata = storageService.storeFile(user, file, language);
|
||||
logger.info("File {} uploaded and stored by user {}", file.getOriginalFilename(), user.getUsername());
|
||||
if(fileMetadata != null) {
|
||||
jobProcessorService.addJob(fileMetadata);
|
||||
logger.info("Added job for file {}", fileMetadata.getFileName());
|
||||
}
|
||||
model.addAttribute("message", "File uploaded successfully. Transcription will start shortly.");
|
||||
|
||||
} catch (Exception e) {
|
||||
model.addAttribute("error", "File upload failed: " + e.getMessage());
|
||||
}
|
||||
|
||||
// Reload the file list
|
||||
return "redirect:/files/manage";
|
||||
}
|
||||
|
||||
// Browsers do not support DELETE method so for individual file deletion we use GET
|
||||
@GetMapping("files/download/{id}")
|
||||
public ResponseEntity<Resource> downloadFile(@PathVariable("id") Long id) {
|
||||
try {
|
||||
File file = storageService.getFile(id);
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName())
|
||||
.contentLength(file.length())
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.body(new FileSystemResource(file));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/files/download-zip")
|
||||
public ResponseEntity<Resource> downloadSelectedFilesAsZip(
|
||||
@RequestParam("selectedFiles") List<Long> fileIds,
|
||||
Authentication authentication) {
|
||||
try {
|
||||
AppUser user = userService.getUserByUsername(authentication.getName());
|
||||
File zipFile = storageService.createZipFromFiles(fileIds, user);
|
||||
|
||||
// Set a custom file name
|
||||
String zipFileName = String.format("transcribed-files-%s.zip", LocalDate.now());
|
||||
|
||||
// Return the ZIP file with a custom header
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + zipFileName + "\"")
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.body(new FileSystemResource(zipFile));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/files/delete/{id}")
|
||||
public String deleteFile(@PathVariable("id") Long id, Authentication authentication, Model model) {
|
||||
try {
|
||||
AppUser user = userService.getUserByUsername(authentication.getName());
|
||||
boolean success = storageService.deleteFile(id, user.getUsername());
|
||||
if (success) {
|
||||
model.addAttribute("message", "File deleted successfully.");
|
||||
} else {
|
||||
model.addAttribute("error", "You are not authorized to delete this file.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error deleting file with ID {}: {}", id, e.getMessage());
|
||||
model.addAttribute("error", "Failed to delete the file: " + e.getMessage());
|
||||
}
|
||||
|
||||
return "redirect:/files/manage";
|
||||
}
|
||||
|
||||
@PostMapping("/files/bulk-delete")
|
||||
public String deleteSelectedFiles(@RequestParam("selectedFiles") List<Long> fileIds, Authentication authentication) {
|
||||
AppUser user = userService.getUserByUsername(authentication.getName());
|
||||
storageService.bulkDeleteFiles(fileIds, user);
|
||||
return "redirect:/files/manage";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package se.su.dsv.seshat.controllers;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class LoginController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String showHomePage(Authentication authentication) {
|
||||
if (authentication != null) {
|
||||
return "redirect:/files/manage";
|
||||
}
|
||||
return "redirect:/login";
|
||||
}
|
||||
|
||||
@GetMapping("/login")
|
||||
public String showLoginPage(Model model, String error, String logout) {
|
||||
if (error != null) {
|
||||
model.addAttribute("error", "Invalid username or password");
|
||||
}
|
||||
if (logout != null) {
|
||||
model.addAttribute("message", "Logged out successfully");
|
||||
}
|
||||
return "login";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package se.su.dsv.seshat.controllers;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import se.su.dsv.seshat.services.UserService;
|
||||
|
||||
@Controller
|
||||
public class RegistrationController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public RegistrationController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/register")
|
||||
public String showRegistrationForm() {
|
||||
return "register";
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public String registerUser(@RequestParam String username,
|
||||
@RequestParam String email,
|
||||
@RequestParam String password,
|
||||
Model model) {
|
||||
try{
|
||||
userService.registerUser(username, email, password);
|
||||
return "redirect:/login";
|
||||
} catch (IllegalArgumentException e) {
|
||||
model.addAttribute("error", "Registration failed: " + e.getMessage());
|
||||
return "register";
|
||||
}
|
||||
}
|
||||
}
|
136
src/main/java/se/su/dsv/seshat/entities/AppUser.java
Normal file
136
src/main/java/se/su/dsv/seshat/entities/AppUser.java
Normal file
@ -0,0 +1,136 @@
|
||||
package se.su.dsv.seshat.entities;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "app_user")
|
||||
public class AppUser {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false, unique = true)
|
||||
private String username;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String password;
|
||||
|
||||
@Column(nullable = false, unique = true)
|
||||
private String email;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String roles; // Roles will be stored in a comma separated string (e.g. "USER,ADMIN")
|
||||
|
||||
@Column(nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt = LocalDateTime.now();
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<FileMetadata> files = new ArrayList<>();
|
||||
|
||||
public AppUser() {}
|
||||
|
||||
public AppUser(String username, String password, String email, String roles) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(String roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public List<FileMetadata> getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
public void setFiles(List<FileMetadata> files) {
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AppUser appUser)) return false;
|
||||
return Objects.equals(id, appUser.id)
|
||||
&& Objects.equals(username, appUser.username)
|
||||
&& Objects.equals(password, appUser.password)
|
||||
&& Objects.equals(email, appUser.email)
|
||||
&& Objects.equals(roles, appUser.roles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, username, password, email, roles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AppUser{" +
|
||||
"id=" + id +
|
||||
", username='" + username + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", roles='" + roles + '\'' +
|
||||
", createdAt=" + createdAt +
|
||||
", files=" + files +
|
||||
'}';
|
||||
}
|
||||
}
|
92
src/main/java/se/su/dsv/seshat/entities/DeletedFile.java
Normal file
92
src/main/java/se/su/dsv/seshat/entities/DeletedFile.java
Normal file
@ -0,0 +1,92 @@
|
||||
package se.su.dsv.seshat.entities;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class DeletedFile {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String filePath;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDateTime deletionTime;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String deletedBy;
|
||||
|
||||
public DeletedFile() {}
|
||||
|
||||
public DeletedFile(String filePath, String deletedBy) {
|
||||
this.filePath = filePath;
|
||||
this.deletedBy = deletedBy;
|
||||
this.deletionTime = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public LocalDateTime getDeletionTime() {
|
||||
return deletionTime;
|
||||
}
|
||||
|
||||
public void setDeletionTime(LocalDateTime deletionTime) {
|
||||
this.deletionTime = deletionTime;
|
||||
}
|
||||
|
||||
public String getDeletedBy() {
|
||||
return deletedBy;
|
||||
}
|
||||
|
||||
public void setDeletedBy(String deletedBy) {
|
||||
this.deletedBy = deletedBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof DeletedFile that)) return false;
|
||||
return Objects.equals(id, that.id)
|
||||
&& Objects.equals(filePath, that.filePath)
|
||||
&& Objects.equals(deletionTime, that.deletionTime)
|
||||
&& Objects.equals(deletedBy, that.deletedBy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, filePath, deletionTime, deletedBy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeletedFile{" +
|
||||
"id=" + id +
|
||||
", filePath='" + filePath + '\'' +
|
||||
", deletionTime=" + deletionTime +
|
||||
", deletedBy='" + deletedBy + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
147
src/main/java/se/su/dsv/seshat/entities/FileMetadata.java
Normal file
147
src/main/java/se/su/dsv/seshat/entities/FileMetadata.java
Normal file
@ -0,0 +1,147 @@
|
||||
package se.su.dsv.seshat.entities;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "file_metadata")
|
||||
public class FileMetadata {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String fileName;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String filePath;
|
||||
|
||||
private String language;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private AppUser user;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDateTime uploadedAt = LocalDateTime.now();
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name ="job_status", nullable = false, length = 20)
|
||||
private JobStatus jobStatus = JobStatus.PENDING;
|
||||
|
||||
@Column
|
||||
private String outputDirectory;
|
||||
|
||||
public FileMetadata() {}
|
||||
|
||||
public FileMetadata(String fileName, AppUser user) {
|
||||
this.fileName = fileName;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public AppUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(AppUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public LocalDateTime getUploadedAt() {
|
||||
return uploadedAt;
|
||||
}
|
||||
|
||||
public void setUploadedAt(LocalDateTime uploadedAt) {
|
||||
this.uploadedAt = uploadedAt;
|
||||
}
|
||||
|
||||
public JobStatus getJobStatus() {
|
||||
return jobStatus;
|
||||
}
|
||||
|
||||
public void setJobStatus(JobStatus jobStatus) {
|
||||
this.jobStatus = jobStatus;
|
||||
}
|
||||
|
||||
public String getOutputDirectory() {
|
||||
return outputDirectory;
|
||||
}
|
||||
|
||||
public void setOutputDirectory(String outputDirectory) {
|
||||
this.outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof FileMetadata that)) return false;
|
||||
return Objects.equals(id, that.id)
|
||||
&& Objects.equals(fileName, that.fileName)
|
||||
&& Objects.equals(filePath, that.filePath)
|
||||
&& Objects.equals(user, that.user)
|
||||
&& Objects.equals(uploadedAt, that.uploadedAt)
|
||||
&& jobStatus == that.jobStatus
|
||||
&& Objects.equals(outputDirectory, that.outputDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, fileName, filePath, user, uploadedAt, jobStatus, outputDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FileMetadata{" +
|
||||
"id=" + id +
|
||||
", fileName='" + fileName + '\'' +
|
||||
", filePath='" + filePath + '\'' +
|
||||
", uploadedAt=" + uploadedAt +
|
||||
", outputDirectory='" + outputDirectory + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
8
src/main/java/se/su/dsv/seshat/entities/JobStatus.java
Normal file
8
src/main/java/se/su/dsv/seshat/entities/JobStatus.java
Normal file
@ -0,0 +1,8 @@
|
||||
package se.su.dsv.seshat.entities;
|
||||
|
||||
public enum JobStatus {
|
||||
PENDING,
|
||||
PROCESSING,
|
||||
COMPLETED,
|
||||
FAILED
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package se.su.dsv.seshat.repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import se.su.dsv.seshat.entities.AppUser;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface AppUserRepository extends JpaRepository<AppUser, Long> {
|
||||
Optional<AppUser> findByUsername(String username);
|
||||
boolean existsByUsername(String username);
|
||||
boolean existsByEmail(String email);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package se.su.dsv.seshat.repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import se.su.dsv.seshat.entities.DeletedFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DeletedFileRepository extends JpaRepository<DeletedFile, Long> {
|
||||
List<DeletedFile> findByDeletedBy(String deletedBy);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package se.su.dsv.seshat.repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import se.su.dsv.seshat.entities.AppUser;
|
||||
import se.su.dsv.seshat.entities.FileMetadata;
|
||||
import se.su.dsv.seshat.entities.JobStatus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FileMetadataRepository extends JpaRepository<FileMetadata, Long> {
|
||||
List<FileMetadata> findByUserId(Long userId);
|
||||
|
||||
List<FileMetadata> findByJobStatus(JobStatus jobStatus);
|
||||
|
||||
List<FileMetadata> findByUserIdAndJobStatus(Long userId, String jobStatus);
|
||||
|
||||
boolean existsByFilePathAndUser(String filePath, AppUser user);
|
||||
|
||||
FileMetadata findByIdAndUserId(Long fileId, Long id);
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package se.su.dsv.seshat.services;
|
||||
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import se.su.dsv.seshat.entities.AppUser;
|
||||
import se.su.dsv.seshat.repositories.AppUserRepository;
|
||||
|
||||
@Service
|
||||
public class CustomUserDetailService implements UserDetailsService {
|
||||
|
||||
private final AppUserRepository appUserRepository;
|
||||
|
||||
public CustomUserDetailService(AppUserRepository appUserRepository) {
|
||||
this.appUserRepository = appUserRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
AppUser appUser = appUserRepository.findByUsername(username)
|
||||
.orElseThrow(() -> new UsernameNotFoundException("User not found: " + username));
|
||||
return User.builder()
|
||||
.username(appUser.getUsername())
|
||||
.password(appUser.getPassword())
|
||||
.roles(appUser.getRoles().split(","))
|
||||
.build();
|
||||
}
|
||||
}
|
137
src/main/java/se/su/dsv/seshat/services/JobProcessorService.java
Normal file
137
src/main/java/se/su/dsv/seshat/services/JobProcessorService.java
Normal file
@ -0,0 +1,137 @@
|
||||
package se.su.dsv.seshat.services;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.orm.ObjectOptimisticLockingFailureException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import se.su.dsv.seshat.entities.DeletedFile;
|
||||
import se.su.dsv.seshat.entities.FileMetadata;
|
||||
import se.su.dsv.seshat.entities.JobStatus;
|
||||
import se.su.dsv.seshat.repositories.DeletedFileRepository;
|
||||
import se.su.dsv.seshat.repositories.FileMetadataRepository;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Service
|
||||
public class JobProcessorService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(JobProcessorService.class);
|
||||
|
||||
private final BlockingQueue<FileMetadata> jobQueue = new LinkedBlockingQueue<>();
|
||||
private final FileMetadataRepository fileMetadataRepository;
|
||||
private final Transcriber transcriber;
|
||||
private final StorageService storageService;
|
||||
private final DeletedFileRepository deletedFileRepository;
|
||||
|
||||
@Value("${app.output-root}")
|
||||
private String outputRoot;
|
||||
|
||||
public JobProcessorService(FileMetadataRepository fileMetadataRepository,
|
||||
Transcriber transcriber,
|
||||
StorageService storageService,
|
||||
DeletedFileRepository deletedFileRepository
|
||||
) {
|
||||
this.fileMetadataRepository = fileMetadataRepository;
|
||||
this.transcriber = transcriber;
|
||||
this.storageService = storageService;
|
||||
this.deletedFileRepository = deletedFileRepository;
|
||||
}
|
||||
|
||||
public void addJob(FileMetadata fileMetadata) {
|
||||
jobQueue.offer(fileMetadata);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public synchronized void startProecessing() {
|
||||
Thread worker = new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
FileMetadata job = jobQueue.take();
|
||||
processJob(job);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
worker.setDaemon(true);
|
||||
worker.start();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addPendingJobsToQueue() {
|
||||
List<FileMetadata> pendingJobs = fileMetadataRepository.findByJobStatus(JobStatus.PENDING);
|
||||
for (FileMetadata job : pendingJobs) {
|
||||
jobQueue.offer(job);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void processJob(FileMetadata job) {
|
||||
int retries = 3;
|
||||
|
||||
while (retries > 0) {
|
||||
try {
|
||||
FileMetadata managedJob = fileMetadataRepository.findById(job.getId())
|
||||
.orElseThrow(() -> new EntityNotFoundException("Job not found"));
|
||||
|
||||
managedJob.setJobStatus(JobStatus.PROCESSING);
|
||||
fileMetadataRepository.saveAndFlush(managedJob);
|
||||
boolean transcribe = transcriber.transcribe(managedJob.getFilePath(), managedJob.getOutputDirectory(), managedJob.getLanguage());
|
||||
|
||||
if (transcribe) {
|
||||
logger.info("Transcription successful for file: {}", managedJob.getFileName());
|
||||
storageService.addTranscribedFilesToDatabase(managedJob.getUser(), managedJob.getOutputDirectory());
|
||||
cleanupFile(managedJob);
|
||||
fileMetadataRepository.delete(managedJob); // Delete the job after successful transcription
|
||||
break;
|
||||
} else {
|
||||
logger.info("Transcription failed for file: {}", managedJob.getFileName());
|
||||
managedJob.setJobStatus(JobStatus.FAILED);
|
||||
fileMetadataRepository.saveAndFlush(managedJob);
|
||||
break;
|
||||
}
|
||||
} catch (ObjectOptimisticLockingFailureException e) {
|
||||
retries--;
|
||||
if (retries == 0) {
|
||||
// Log and handle the failure
|
||||
logger.error("Failed to process job after retries: {}", job.getId(), e);
|
||||
throw e; // Re-throw the exception after exhausting retries
|
||||
}
|
||||
logger.warn("Retrying job processing due to optimistic locking failure. Remaining retries: {}", retries);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean cleanupFile(FileMetadata jobFile) {
|
||||
String filePath = jobFile.getFilePath();
|
||||
File file = new File(filePath);
|
||||
if(file.exists()) {
|
||||
if(file.delete()) {
|
||||
recordFileDeletion(filePath, "JobProcessorService");
|
||||
logger.info("File deleted successfully: {}", filePath);
|
||||
return true;
|
||||
} else {
|
||||
logger.error("Failed to delete file: {}", filePath);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void recordFileDeletion(String filePath, String jobProcessorService) {
|
||||
DeletedFile deletedFile = new DeletedFile();
|
||||
deletedFile.setFilePath(filePath);
|
||||
deletedFile.setDeletedBy(jobProcessorService);
|
||||
deletedFile.setDeletionTime(LocalDateTime.now());
|
||||
deletedFileRepository.save(deletedFile);
|
||||
}
|
||||
}
|
203
src/main/java/se/su/dsv/seshat/services/StorageService.java
Normal file
203
src/main/java/se/su/dsv/seshat/services/StorageService.java
Normal file
@ -0,0 +1,203 @@
|
||||
package se.su.dsv.seshat.services;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import se.su.dsv.seshat.entities.AppUser;
|
||||
import se.su.dsv.seshat.entities.DeletedFile;
|
||||
import se.su.dsv.seshat.entities.FileMetadata;
|
||||
import se.su.dsv.seshat.repositories.DeletedFileRepository;
|
||||
import se.su.dsv.seshat.repositories.FileMetadataRepository;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@Service
|
||||
public class StorageService {
|
||||
|
||||
private final DeletedFileRepository deletedFileRepository;
|
||||
@Value("${app.upload-root}")
|
||||
private String uploadRoot;
|
||||
|
||||
@Value("${app.output-root}")
|
||||
private String outputRoot;
|
||||
|
||||
private final FileMetadataRepository fileMetadataRepository;
|
||||
|
||||
public StorageService(FileMetadataRepository fileMetadataRepository, DeletedFileRepository deletedFileRepository) {
|
||||
this.fileMetadataRepository = fileMetadataRepository;
|
||||
this.deletedFileRepository = deletedFileRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addTranscribedFilesToDatabase(AppUser user, String outputDirectory) {
|
||||
File userOutputDirectory = new File(outputDirectory);
|
||||
if(!userOutputDirectory.exists() || !userOutputDirectory.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
File[] files = userOutputDirectory.listFiles();
|
||||
if(files == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(File file : files) {
|
||||
if(file.isFile()) {
|
||||
String fileName = file.getName();
|
||||
String filePath = file.getAbsolutePath();
|
||||
|
||||
boolean exists = fileMetadataRepository.existsByFilePathAndUser(filePath, user);
|
||||
if(!exists) {
|
||||
FileMetadata fileMetadata = new FileMetadata();
|
||||
fileMetadata.setFileName(fileName);
|
||||
fileMetadata.setFilePath(filePath);
|
||||
fileMetadata.setUser(user);
|
||||
fileMetadata.setJobStatus(null);
|
||||
fileMetadataRepository.save(fileMetadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public FileMetadata storeFile(AppUser user, MultipartFile fileToStore, String language) throws IOException {
|
||||
if(fileToStore == null || fileToStore.isEmpty()) {
|
||||
throw new IllegalArgumentException("File is null or empty");
|
||||
}
|
||||
|
||||
// To prevent directory traversal attacks, we sanitize the filename
|
||||
String originalFilename = fileToStore.getOriginalFilename();
|
||||
if (originalFilename == null) {
|
||||
throw new IllegalArgumentException("File name is empty or null");
|
||||
}
|
||||
String sanitizedFilename = sanitizeFilename(originalFilename);
|
||||
|
||||
// Users upload directory
|
||||
Path userUploadDir = Paths.get(uploadRoot, user.getUsername());
|
||||
|
||||
try {
|
||||
if(!Files.exists(userUploadDir)) {
|
||||
Files.createDirectories(userUploadDir); // Create user directory if it does not exist
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Failed to create user directory: " + e.getMessage());
|
||||
}
|
||||
|
||||
// Store the file
|
||||
Path filePath = userUploadDir.resolve(sanitizedFilename);
|
||||
|
||||
try {
|
||||
Files.copy(fileToStore.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
FileMetadata metadata = new FileMetadata();
|
||||
metadata.setFileName(sanitizedFilename);
|
||||
metadata.setFilePath(filePath.toString());
|
||||
if(language != null && !language.isEmpty()) {
|
||||
metadata.setLanguage(language);
|
||||
} else {
|
||||
metadata.setLanguage("auto");
|
||||
}
|
||||
metadata.setOutputDirectory(outputRoot + File.separator + user.getUsername());
|
||||
metadata.setUser(user);
|
||||
return fileMetadataRepository.save(metadata);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Failed to store file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public List<FileMetadata> getUserTranscriptons(AppUser user) {
|
||||
return fileMetadataRepository.findByUserId(user.getId())
|
||||
.stream()
|
||||
.filter(file -> file.getFilePath().startsWith(outputRoot))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<FileMetadata> getUserUplaods(AppUser user) {
|
||||
return fileMetadataRepository.findByUserId(user.getId())
|
||||
.stream()
|
||||
.filter(file -> file.getFilePath().startsWith(uploadRoot))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public File getFile(Long id) {
|
||||
FileMetadata fileMetadata = fileMetadataRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("File not found"));
|
||||
return new File(fileMetadata.getFilePath());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean deleteFile(Long id, String deletedBy) {
|
||||
FileMetadata fileMetadata = fileMetadataRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("File not found"));
|
||||
File file = new File(fileMetadata.getFilePath());
|
||||
if(file.exists()) {
|
||||
if(file.delete()) {
|
||||
try {
|
||||
DeletedFile deletedFile = new DeletedFile();
|
||||
deletedFile.setFilePath(fileMetadata.getFilePath());
|
||||
deletedFile.setDeletedBy(deletedBy);
|
||||
deletedFile.setDeletionTime(LocalDateTime.now());
|
||||
deletedFileRepository.save(deletedFile);
|
||||
fileMetadataRepository.delete(fileMetadata);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void bulkDeleteFiles(List<Long> fileIds, AppUser user) {
|
||||
for(Long id : fileIds) {
|
||||
deleteFile(id, user.getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
public File createZipFromFiles(List<Long> fileIds, AppUser user) throws IOException {
|
||||
// Temporary ZIP file
|
||||
File zipFile = File.createTempFile("selected_files", ".zip");
|
||||
|
||||
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile))) {
|
||||
for (Long fileId : fileIds) {
|
||||
FileMetadata fileMetadata = fileMetadataRepository.findById(fileId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("File not found"));
|
||||
|
||||
// Ensure file belongs to user
|
||||
if (!fileMetadata.getUser().getId().equals(user.getId())) {
|
||||
throw new SecurityException("Unauthorized access to file ID: " + fileId);
|
||||
}
|
||||
|
||||
// Get the file
|
||||
File file = new File(fileMetadata.getFilePath());
|
||||
if (file.exists()) {
|
||||
Path filePath = file.toPath();
|
||||
|
||||
// Add new entry for the file in the ZIP
|
||||
zos.putNextEntry(new ZipEntry(file.getName()));
|
||||
|
||||
// Copy file contents to the ZIP
|
||||
Files.copy(filePath, zos);
|
||||
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
return zipFile;
|
||||
}
|
||||
|
||||
private String sanitizeFilename(String filename) {
|
||||
return filename.replaceAll("[^a-zA-Z0-9.-]", "_");
|
||||
}
|
||||
}
|
59
src/main/java/se/su/dsv/seshat/services/Transcriber.java
Normal file
59
src/main/java/se/su/dsv/seshat/services/Transcriber.java
Normal file
@ -0,0 +1,59 @@
|
||||
package se.su.dsv.seshat.services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Service
|
||||
public class Transcriber {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Transcriber.class);
|
||||
private static final String MODEL_PATH = System.getProperty("user.home") + "/playground/whisper.cpp/models";
|
||||
private static final String WHISPER_WORKING_DIRECTORY = System.getProperty("user.home") + "/git/python-whisper/";
|
||||
|
||||
String[] activateVirtualEnv = {"/bin/bash", "-c", "source activate"};
|
||||
ProcessBuilder startVirtualEnv = new ProcessBuilder(activateVirtualEnv);
|
||||
|
||||
private void setStartVirtualEnv() {
|
||||
startVirtualEnv.directory(new File(WHISPER_WORKING_DIRECTORY + "env/bin/"));
|
||||
startVirtualEnv.inheritIO();
|
||||
try {
|
||||
Process p = startVirtualEnv.start();
|
||||
p.waitFor();
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to activate virtual environment: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean transcribe(String inputFilePath, String outputDirectory, String language) {
|
||||
setStartVirtualEnv();
|
||||
StringBuilder whisperCommandOptions = new StringBuilder("env/bin/whisper ")
|
||||
.append(inputFilePath)
|
||||
.append(" --model_dir ")
|
||||
.append(MODEL_PATH)
|
||||
.append(" --model medium --output_dir ")
|
||||
.append(outputDirectory);
|
||||
if(language != null && !language.equalsIgnoreCase("auto")) {
|
||||
whisperCommandOptions.append(" --language ")
|
||||
.append(language);
|
||||
}
|
||||
logger.info("Whisper will run with the following options: '{}'", whisperCommandOptions);
|
||||
String[] whisperCommand = {"/bin/bash", "-c", whisperCommandOptions.toString()};
|
||||
ProcessBuilder transcribeProcess = new ProcessBuilder(whisperCommand);
|
||||
|
||||
transcribeProcess.directory(new File(WHISPER_WORKING_DIRECTORY));
|
||||
transcribeProcess.inheritIO();
|
||||
try {
|
||||
Process p = transcribeProcess.start();
|
||||
logger.info("Transcription process started for file '{}' audio language '{}'", inputFilePath, language);
|
||||
int exitCode = p.waitFor();
|
||||
return exitCode == 0; // Returns true if the process was successful, false otherwise
|
||||
} catch (IOException | InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
35
src/main/java/se/su/dsv/seshat/services/UserService.java
Normal file
35
src/main/java/se/su/dsv/seshat/services/UserService.java
Normal file
@ -0,0 +1,35 @@
|
||||
package se.su.dsv.seshat.services;
|
||||
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import se.su.dsv.seshat.entities.AppUser;
|
||||
import se.su.dsv.seshat.repositories.AppUserRepository;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final AppUserRepository appUserRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
public UserService(AppUserRepository appUserRepository, PasswordEncoder passwordEncoder) {
|
||||
this.appUserRepository = appUserRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
public void registerUser(String username, String email,String password) {
|
||||
if (appUserRepository.existsByUsername(username)) {
|
||||
throw new IllegalArgumentException("Username already exists");
|
||||
}
|
||||
if (appUserRepository.existsByEmail(email)) {
|
||||
throw new IllegalArgumentException("Email already exists");
|
||||
}
|
||||
|
||||
AppUser newUser = new AppUser(username, passwordEncoder.encode(password), email, "USER");
|
||||
appUserRepository.save(newUser);
|
||||
}
|
||||
|
||||
public AppUser getUserByUsername(String username) {
|
||||
return appUserRepository.findByUsername(username)
|
||||
.orElseThrow(() -> new IllegalArgumentException("User not found"));
|
||||
}
|
||||
}
|
19
src/main/resources/application.properties
Normal file
19
src/main/resources/application.properties
Normal file
@ -0,0 +1,19 @@
|
||||
# Application properties
|
||||
spring.application.name=seshat
|
||||
server.port=8181
|
||||
spring.servlet.multipart.max-file-size=5GB
|
||||
spring.servlet.multipart.max-request-size=5GB
|
||||
|
||||
app.upload-root=/seshat/uploads
|
||||
app.output-root=/seshat/outputs
|
||||
app.api-url=http://localhost:8181/seshat/api
|
||||
|
||||
# Database properties (local development)
|
||||
spring.datasource.url=jdbc:mariadb://localhost:3306/seshat
|
||||
spring.datasource.username=myuser
|
||||
spring.datasource.password=secret
|
||||
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
|
||||
|
||||
# JPA properties
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.show-sql=false
|
37
src/main/resources/static/css/styles.css
Normal file
37
src/main/resources/static/css/styles.css
Normal file
@ -0,0 +1,37 @@
|
||||
/* Sticky footer layout */
|
||||
/* Header Styling */
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.header .app-title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.header .user-menu {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.header .user-menu i {
|
||||
margin-right: 0.5rem;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%; /* Ensure the height of the body is at least the viewport height */
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
main {
|
||||
flex: 1; /* Pushes the footer to the bottom */
|
||||
}
|
0
src/main/resources/static/js/script.js
Normal file
0
src/main/resources/static/js/script.js
Normal file
149
src/main/resources/templates/file-management.html
Normal file
149
src/main/resources/templates/file-management.html
Normal file
@ -0,0 +1,149 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>File Management - Seshat App</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.9.1/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" th:href="@{/css/styles.css}">
|
||||
</head>
|
||||
<body>
|
||||
<header class="header bg-primary text-white py-3">
|
||||
<div class="container d-flex justify-content-between align-items-center">
|
||||
<h1 class="app-title mb-0">Seshat Audio Transcriber</h1>
|
||||
<div th:if="${#authentication.name != 'anonymousUser'}" class="dropdown">
|
||||
<a class="user-menu text-white text-decoration-none dropdown-toggle" href="#" id="userMenu" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="bi bi-person-circle"></i>
|
||||
<span th:text="${#authentication.name}">Username</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userMenu">
|
||||
<li><a class="dropdown-item" th:href="@{/logout}">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="container mt-4">
|
||||
<h2>File Management</h2>
|
||||
|
||||
<!-- File Upload Section -->
|
||||
<section>
|
||||
<h3>Upload File</h3>
|
||||
<form th:action="@{/files/upload}" method="post" enctype="multipart/form-data">
|
||||
<div class="mb-3">
|
||||
<label for="file" class="form-label">Choose File</label>
|
||||
<input type="file" id="file" name="file" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="language" class="form-label">Select Language</label>
|
||||
<select id="language" name="language" class="form-select" required>
|
||||
<option value="auto" disabled selected>Language of Audio file</option>
|
||||
<option value="English">English</option>
|
||||
<option value="Swedish">Swedish</option>
|
||||
<option value="Greek">Greek</option>
|
||||
<option value="French">French</option>
|
||||
<option value="German">German</option>
|
||||
<option value="Spanish">Spanish</option>
|
||||
<!-- Add other languages as needed -->
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Upload</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<!-- File Status Section -->
|
||||
<section th:if="${statuses != null && !statuses.isEmpty()}" class="mt-5">
|
||||
<h3>File Upload Statuses</h3>
|
||||
<ul class="list-group">
|
||||
<li th:each="status : ${statuses}" class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<span th:text="${status.fileName}">File Name</span>
|
||||
<span class="badge bg-primary" th:text="${status.jobStatus}">Status</span>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<hr>
|
||||
|
||||
<!-- File Browsing Section -->
|
||||
<section>
|
||||
<h3>Your Files</h3>
|
||||
<form id="bulk-actions-form" method="post">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<input type="checkbox" id="select-all" />
|
||||
</th>
|
||||
<th>File Name</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="file : ${files}">
|
||||
<td>
|
||||
<input type="checkbox" name="selectedFiles" th:value="${file.id}" />
|
||||
</td>
|
||||
<td th:text="${file.fileName}"></td>
|
||||
<td>
|
||||
<a th:href="@{/files/download/{id}(id=${file.id})}" class="btn btn-primary">Download</a>
|
||||
<a th:href="@{/files/delete/{id}(id=${file.id})}" class="btn btn-danger">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-flex justify-content-between mt-3">
|
||||
<button type="button" class="btn btn-primary" onclick="downloadSelected()">Download Selected</button>
|
||||
<button type="button" class="btn btn-danger" onclick="deleteSelected()">Delete Selected</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
<footer class="bg-dark text-white text-center py-3">
|
||||
<p>© 2024 Seshat App</p>
|
||||
</footer>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
// Select/Deselect all checkboxes
|
||||
document.getElementById('select-all').addEventListener('change', function() {
|
||||
const checkboxes = document.querySelectorAll('input[name="selectedFiles"]');
|
||||
checkboxes.forEach(checkbox => checkbox.checked = this.checked);
|
||||
});
|
||||
|
||||
// Handle bulk download
|
||||
function downloadSelected() {
|
||||
const selectedFiles = Array.from(document.querySelectorAll('input[name="selectedFiles"]:checked'))
|
||||
.map(checkbox => checkbox.value);
|
||||
if (selectedFiles.length === 0) {
|
||||
alert('No files selected.');
|
||||
return;
|
||||
}
|
||||
const form = document.getElementById('bulk-actions-form');
|
||||
form.action = '/files/download-zip'; // Backend endpoint for bulk download
|
||||
form.method = 'post';
|
||||
form.submit();
|
||||
clearCheckboxes();
|
||||
}
|
||||
|
||||
function clearCheckboxes() {
|
||||
const checkboxes = document.querySelectorAll('input[name="selectedFiles"], #select-all');
|
||||
checkboxes.forEach(checkbox => (checkbox.checked = false));
|
||||
}
|
||||
|
||||
// Handle bulk delete
|
||||
function deleteSelected() {
|
||||
const selectedFiles = Array.from(document.querySelectorAll('input[name="selectedFiles"]:checked'))
|
||||
.map(checkbox => checkbox.value);
|
||||
if (selectedFiles.length === 0) {
|
||||
alert('No files selected.');
|
||||
return;
|
||||
}
|
||||
if (confirm('Are you sure you want to delete the selected files?')) {
|
||||
const form = document.getElementById('bulk-actions-form');
|
||||
form.action = '/files/bulk-delete'; // Backend endpoint for bulk delete
|
||||
form.submit();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
40
src/main/resources/templates/login.html
Normal file
40
src/main/resources/templates/login.html
Normal file
@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - Seshat App</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" th:href="@{/css/styles.css}">
|
||||
</head>
|
||||
<body>
|
||||
<header class="bg-primary text-white text-center py-3">
|
||||
<div class="container d-flex justify-content-between align-items-center">
|
||||
<h1 class="app-title mb-0">Seshat Audio Transcriber</h1>
|
||||
</div>
|
||||
</header>
|
||||
<main class="container mt-4">
|
||||
<h2>Login</h2>
|
||||
<form th:action="@{/login}" method="post" class="mb-4">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" id="username" name="username" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" id="password" name="password" class="form-control" required>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between">
|
||||
<!-- Login Button -->
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
|
||||
<!-- Register Button -->
|
||||
<a href="/register" class="btn btn-secondary ms-auto">Register</a>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
<footer class="bg-dark text-white text-center py-3">
|
||||
<p>© 2024 Seshat App</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
38
src/main/resources/templates/register.html
Normal file
38
src/main/resources/templates/register.html
Normal file
@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Register - Seshat App</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" th:href="@{/css/styles.css}">
|
||||
</head>
|
||||
<body>
|
||||
<header class="bg-primary text-white text-center py-3">
|
||||
<div class="container d-flex justify-content-between align-items-center">
|
||||
<h1 class="app-title mb-0">Seshat Audio Transcriber</h1>
|
||||
</div>
|
||||
</header>
|
||||
<main class="container mt-4">
|
||||
<h2>Register</h2>
|
||||
<form th:action="@{/register}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" id="username" name="username" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email</label>
|
||||
<input type="email" id="email" name="email" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" id="password" name="password" class="form-control" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Register</button>
|
||||
</form>
|
||||
</main>
|
||||
<footer class="bg-dark text-white text-center py-3">
|
||||
<p>© 2024 Seshat App</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
13
src/test/java/se/su/dsv/seshat/SeshatApplicationTests.java
Normal file
13
src/test/java/se/su/dsv/seshat/SeshatApplicationTests.java
Normal file
@ -0,0 +1,13 @@
|
||||
package se.su.dsv.seshat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class SeshatApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user