initial commit
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
/gradlew text eol=lf
|
||||||
|
*.bat text eol=crlf
|
||||||
|
*.jar binary
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
name: Deploy AutoDJ Bot
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main # Пайплайн запустится только при пуше в ветку main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
# Укажи лейбл твоего раннера (часто это ubuntu-latest или windows-latest)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build and Run with Docker Compose
|
||||||
|
run: |
|
||||||
|
docker compose up -d --build
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
name: Nightly Music Discovery
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
# Запускаем каждый день в 03:00 ночи
|
||||||
|
- cron: '0 3 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
# Позволяет запускать пайплайн вручную кнопкой из UI Gitea
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
trigger-backend:
|
||||||
|
runs-on: ubuntu-latest # actrunner подхватит этот лейбл
|
||||||
|
steps:
|
||||||
|
- name: Send Webhook to Spring Boot
|
||||||
|
run: |
|
||||||
|
# Используем IP ноутбука в локальной сети (или localhost, если бежит в host network)
|
||||||
|
curl -X POST http://192.168.x.x:8080/api/internal/trigger-discovery \
|
||||||
|
-H "X-Internal-Token: ${{ secrets.INTERNAL_API_TOKEN }}"
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
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/
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Этап 1: Сборка
|
||||||
|
FROM gradle:8.7-jdk21-alpine AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
# Копируем файлы сборки
|
||||||
|
COPY build.gradle settings.gradle ./
|
||||||
|
COPY src ./src
|
||||||
|
# Собираем jar файл без запуска тестов
|
||||||
|
RUN gradle clean bootJar -x test
|
||||||
|
|
||||||
|
# Этап 2: Запуск (используем образ с актуальной Java)
|
||||||
|
FROM openjdk:25-slim-node
|
||||||
|
WORKDIR /app
|
||||||
|
# Копируем собранный jar из первого этапа
|
||||||
|
COPY --from=builder /app/build/libs/*.jar app.jar
|
||||||
|
|
||||||
|
# Создаем папку для базы данных и временных аудиофайлов
|
||||||
|
RUN mkdir -p /app/data /app/tmp_music
|
||||||
|
|
||||||
|
ENTRYPOINT ["java", "-jar", "app.jar"]
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'org.springframework.boot' version '4.0.6'
|
||||||
|
id 'io.spring.dependency-management' version '1.1.7'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'org.redjinald'
|
||||||
|
version = '0.0.1-SNAPSHOT'
|
||||||
|
description = 'autodj_backend'
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(25)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-amqp'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-flyway'
|
||||||
|
implementation 'org.telegram:telegrambots-spring-boot-starter:6.9.7.1'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
|
implementation 'org.xerial:sqlite-jdbc'
|
||||||
|
implementation 'org.hibernate.orm:hibernate-community-dialects'
|
||||||
|
compileOnly 'org.projectlombok:lombok'
|
||||||
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-starter-amqp-test'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-starter-flyway-test'
|
||||||
|
testCompileOnly 'org.projectlombok:lombok'
|
||||||
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||||
|
testAnnotationProcessor 'org.projectlombok:lombok'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('test') {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
rabbitmq:
|
||||||
|
image: rabbitmq:3-management-alpine
|
||||||
|
container_name: autodj_rabbitmq
|
||||||
|
ports:
|
||||||
|
- "5672:5672" # Порт для Spring Boot
|
||||||
|
- "15672:15672" # Web-интерфейс (заходи через браузер: localhost:15672)
|
||||||
|
volumes:
|
||||||
|
- rabbitmq_data:/var/lib/rabbitmq
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
autodj-bot:
|
||||||
|
build: .
|
||||||
|
container_name: autodj_backend
|
||||||
|
depends_on:
|
||||||
|
- rabbitmq
|
||||||
|
environment:
|
||||||
|
- DB_PATH=/app/data/music_review.db
|
||||||
|
- RABBITMQ_HOST=rabbitmq
|
||||||
|
- BOT_TOKEN=8849605262:AAFcwQYqbFq72cypWNubV2gBfGz25BIZDy0
|
||||||
|
- BOT_USERNAME=redjinald_dj_bot
|
||||||
|
volumes:
|
||||||
|
- ./bot_data:/app/data
|
||||||
|
# Прокидываем папку Navidrome с твоего диска C: внутрь контейнера (замени путь на свой)
|
||||||
|
- /home/redjinald/navidrome:/music
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
rabbitmq_data:
|
||||||
Vendored
BIN
Binary file not shown.
+9
@@ -0,0 +1,9 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
retries=0
|
||||||
|
retryBackOffMs=500
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
@@ -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/3d91ce3b8caaf77ad09f381f43615b715b53f72c/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" "$@"
|
||||||
Vendored
+82
@@ -0,0 +1,82 @@
|
|||||||
|
@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, and ensure extensions are enabled
|
||||||
|
setlocal EnableExtensions
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
"%COMSPEC%" /c exit 1
|
||||||
|
|
||||||
|
: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
|
||||||
|
|
||||||
|
"%COMSPEC%" /c exit 1
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||||
|
@rem which allows us to clear the local environment before executing the java command
|
||||||
|
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
|
||||||
|
|
||||||
|
:exitWithErrorLevel
|
||||||
|
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||||
|
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = 'autodj_backend'
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.redjinald.autodj_backend;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class AutodjBackendApplication {
|
||||||
|
|
||||||
|
static void main(String[] args) {
|
||||||
|
SpringApplication.run(AutodjBackendApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
package org.redjinald.autodj_backend.bot;
|
||||||
|
|
||||||
|
import org.redjinald.autodj_backend.entity.ReviewQueue;
|
||||||
|
import org.redjinald.autodj_backend.repository.ReviewQueueRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.updatingmessages.DeleteMessage;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageMedia;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.media.InputMediaAudio;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.send.SendAudio;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.InputFile;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AutoDjBot extends TelegramLongPollingBot {
|
||||||
|
|
||||||
|
private final String botUsername;
|
||||||
|
private final ReviewQueueRepository reviewRepository;
|
||||||
|
|
||||||
|
// Внедряем зависимости через конструктор (Spring сделает это автоматически)
|
||||||
|
public AutoDjBot(
|
||||||
|
@Value("${telegram.bot.token}") String botToken,
|
||||||
|
@Value("${telegram.bot.username}") String botUsername,
|
||||||
|
ReviewQueueRepository reviewRepository) {
|
||||||
|
super(botToken);
|
||||||
|
this.botUsername = botUsername;
|
||||||
|
this.reviewRepository = reviewRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBotUsername() {
|
||||||
|
return botUsername;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpdateReceived(Update update) {
|
||||||
|
// 1. Обработка текстовых команд (например, /review)
|
||||||
|
if (update.hasMessage() && update.getMessage().hasText()) {
|
||||||
|
String messageText = update.getMessage().getText();
|
||||||
|
Long chatId = update.getMessage().getChatId();
|
||||||
|
|
||||||
|
if ("/review".equals(messageText)) {
|
||||||
|
startReviewSession(chatId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2. Обработка нажатий на Inline-кнопки [🔥 Добавить] / [🗑 Пропустить]
|
||||||
|
else if (update.hasCallbackQuery()) {
|
||||||
|
handleCallback(update.getCallbackQuery());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private InlineKeyboardMarkup getReviewKeyboard(Long trackId) {
|
||||||
|
InlineKeyboardButton addBtn = new InlineKeyboardButton();
|
||||||
|
addBtn.setText("🔥 Добавить");
|
||||||
|
addBtn.setCallbackData("add:" + trackId); // Укладываемся в лимит 64 байта
|
||||||
|
|
||||||
|
InlineKeyboardButton skipBtn = new InlineKeyboardButton();
|
||||||
|
skipBtn.setText("🗑 Пропустить");
|
||||||
|
skipBtn.setCallbackData("skip:" + trackId);
|
||||||
|
|
||||||
|
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||||
|
row.add(addBtn);
|
||||||
|
row.add(skipBtn);
|
||||||
|
|
||||||
|
List<List<InlineKeyboardButton>> rows = new ArrayList<>();
|
||||||
|
rows.add(row);
|
||||||
|
|
||||||
|
InlineKeyboardMarkup markup = new InlineKeyboardMarkup();
|
||||||
|
markup.setKeyboard(rows);
|
||||||
|
return markup;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startReviewSession(Long chatId) {
|
||||||
|
Optional<ReviewQueue> nextTrackOpt = reviewRepository.findFirstByStatusOrderByCreatedAtAsc("pending");
|
||||||
|
|
||||||
|
if (nextTrackOpt.isPresent()) {
|
||||||
|
ReviewQueue track = nextTrackOpt.get();
|
||||||
|
File audioFile = new File(track.getTmpFilePath());
|
||||||
|
|
||||||
|
if (!audioFile.exists()) {
|
||||||
|
// Защита от дурака: если файл удалился, помечаем ошибку и рекурсивно ищем следующий
|
||||||
|
track.setStatus("error");
|
||||||
|
reviewRepository.save(track);
|
||||||
|
startReviewSession(chatId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SendAudio sendAudio = new SendAudio();
|
||||||
|
sendAudio.setChatId(chatId.toString());
|
||||||
|
sendAudio.setAudio(new InputFile(audioFile));
|
||||||
|
|
||||||
|
// Красивая подпись под треком
|
||||||
|
String caption = String.format("🎵 *%s*\n👤 %s", track.getTitle(), track.getArtist());
|
||||||
|
sendAudio.setCaption(caption);
|
||||||
|
sendAudio.setParseMode("Markdown");
|
||||||
|
sendAudio.setReplyMarkup(getReviewKeyboard(Long.valueOf(track.getId())));
|
||||||
|
|
||||||
|
try {
|
||||||
|
execute(sendAudio);
|
||||||
|
} catch (TelegramApiException e) {
|
||||||
|
e.printStackTrace(); // В проде здесь должен быть логгер (Slf4j)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sendEmptyQueueMessage(chatId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendEmptyQueueMessage(Long chatId) {
|
||||||
|
SendMessage message = new SendMessage();
|
||||||
|
message.setChatId(chatId.toString());
|
||||||
|
message.setText("🎉 Очередь пуста! Все добавленные треки отправлены в Navidrome.");
|
||||||
|
try {
|
||||||
|
execute(message);
|
||||||
|
} catch (TelegramApiException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleCallback(CallbackQuery callbackQuery) {
|
||||||
|
String callData = callbackQuery.getData();
|
||||||
|
Long chatId = callbackQuery.getMessage().getChatId();
|
||||||
|
Integer messageId = callbackQuery.getMessage().getMessageId();
|
||||||
|
|
||||||
|
String[] parts = callData.split(":");
|
||||||
|
if (parts.length != 2) return;
|
||||||
|
|
||||||
|
String action = parts[0];
|
||||||
|
Integer trackId = Integer.parseInt(parts[1]);
|
||||||
|
|
||||||
|
reviewRepository.findById(trackId).ifPresent(track -> {
|
||||||
|
track.setStatus(action.equals("add") ? "accepted" : "rejected");
|
||||||
|
track.setProcessedAt(LocalDateTime.now());
|
||||||
|
reviewRepository.save(track);
|
||||||
|
});
|
||||||
|
|
||||||
|
Optional<ReviewQueue> nextTrackOpt = reviewRepository.findFirstByStatusOrderByCreatedAtAsc("pending");
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (nextTrackOpt.isPresent()) {
|
||||||
|
ReviewQueue track = nextTrackOpt.get();
|
||||||
|
File audioFile = new File(track.getTmpFilePath());
|
||||||
|
|
||||||
|
InputMediaAudio mediaAudio = new InputMediaAudio();
|
||||||
|
mediaAudio.setMedia(audioFile, audioFile.getName());
|
||||||
|
mediaAudio.setCaption(String.format("🎵 *%s*\n👤 %s", track.getTitle(), track.getArtist()));
|
||||||
|
mediaAudio.setParseMode("Markdown");
|
||||||
|
|
||||||
|
EditMessageMedia editMedia = new EditMessageMedia();
|
||||||
|
editMedia.setChatId(chatId.toString());
|
||||||
|
editMedia.setMessageId(messageId);
|
||||||
|
editMedia.setMedia(mediaAudio);
|
||||||
|
editMedia.setReplyMarkup(getReviewKeyboard(Long.valueOf(track.getId())));
|
||||||
|
|
||||||
|
execute(editMedia);
|
||||||
|
} else {
|
||||||
|
DeleteMessage deleteMessage = new DeleteMessage(chatId.toString(), messageId);
|
||||||
|
execute(deleteMessage);
|
||||||
|
|
||||||
|
sendEmptyQueueMessage(chatId);
|
||||||
|
}
|
||||||
|
} catch (TelegramApiException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.redjinald.autodj_backend.config;
|
||||||
|
|
||||||
|
import org.redjinald.autodj_backend.bot.AutoDjBot;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.telegram.telegrambots.meta.TelegramBotsApi;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||||
|
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class BotConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TelegramBotsApi telegramBotsApi(AutoDjBot autoDjBot) throws TelegramApiException {
|
||||||
|
// Создаем API и явно регистрируем нашего бота
|
||||||
|
TelegramBotsApi api = new TelegramBotsApi(DefaultBotSession.class);
|
||||||
|
api.registerBot(autoDjBot);
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.redjinald.autodj_backend.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.Queue;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RabbitConfig {
|
||||||
|
|
||||||
|
public static final String DISCOVERY_TASKS_QUEUE = "discovery_tasks";
|
||||||
|
public static final String DOWNLOAD_TASKS_QUEUE = "download_tasks";
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Queue discoveryTasksQueue() {
|
||||||
|
return new Queue(DISCOVERY_TASKS_QUEUE, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Queue downloadTasksQueue() {
|
||||||
|
return new Queue(DOWNLOAD_TASKS_QUEUE, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.redjinald.autodj_backend.controller;
|
||||||
|
|
||||||
|
import org.redjinald.autodj_backend.config.RabbitConfig;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/internal")
|
||||||
|
public class DiscoveryTriggerController {
|
||||||
|
|
||||||
|
private final RabbitTemplate rabbitTemplate;
|
||||||
|
private final String internalToken;
|
||||||
|
|
||||||
|
public DiscoveryTriggerController(RabbitTemplate rabbitTemplate, @Value("${app.internal-token:my-secret-token}") String internalToken) {
|
||||||
|
this.rabbitTemplate = rabbitTemplate;
|
||||||
|
this.internalToken = internalToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/trigger-discovery")
|
||||||
|
public ResponseEntity<String> triggerDiscovery(@RequestHeader("X-Internal-Token") String token) {
|
||||||
|
if (!internalToken.equals(token)) {
|
||||||
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Invalid token");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Кидаем пустое сообщение или какой-то payload в очередь для AI-воркера
|
||||||
|
rabbitTemplate.convertAndSend(RabbitConfig.DISCOVERY_TASKS_QUEUE, "START_NIGHTLY_DISCOVERY");
|
||||||
|
|
||||||
|
return ResponseEntity.ok("Discovery task queued in RabbitMQ");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.redjinald.autodj_backend.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "review_queue")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class ReviewQueue {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private String artist;
|
||||||
|
|
||||||
|
@Column(name = "source_url")
|
||||||
|
private String sourceUrl;
|
||||||
|
|
||||||
|
@Column(name = "tmp_file_path")
|
||||||
|
private String tmpFilePath;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Builder.Default
|
||||||
|
private String status = "pending";
|
||||||
|
|
||||||
|
// База сама ставит дату при создании, поэтому Hibernate не должен ее инсертить
|
||||||
|
@Column(name = "created_at", insertable = false, updatable = false)
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Column(name = "processed_at")
|
||||||
|
private LocalDateTime processedAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.redjinald.autodj_backend.repository;
|
||||||
|
|
||||||
|
import org.redjinald.autodj_backend.entity.ReviewQueue;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ReviewQueueRepository extends JpaRepository<ReviewQueue, Integer> {
|
||||||
|
Optional<ReviewQueue> findFirstByStatusOrderByCreatedAtAsc(String status);
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
# Берем путь из переменной БД или создаем локально
|
||||||
|
url: jdbc:sqlite:${DB_PATH:music_review.db}
|
||||||
|
driver-class-name: org.sqlite.JDBC
|
||||||
|
|
||||||
|
jpa:
|
||||||
|
database-platform: org.hibernate.community.dialect.SQLiteDialect
|
||||||
|
hibernate:
|
||||||
|
ddl-auto: validate
|
||||||
|
show-sql: true
|
||||||
|
|
||||||
|
flyway:
|
||||||
|
enabled: true
|
||||||
|
baseline-on-migrate: true
|
||||||
|
|
||||||
|
rabbitmq:
|
||||||
|
# Подхватываем хост из переменной (для докера) или используем localhost
|
||||||
|
host: ${RABBITMQ_HOST:localhost}
|
||||||
|
port: 5672
|
||||||
|
username: guest
|
||||||
|
password: guest
|
||||||
|
|
||||||
|
telegram:
|
||||||
|
bot:
|
||||||
|
username: ${BOT_USERNAME:redjinald_dj_bot}
|
||||||
|
token: ${BOT_TOKEN:8849605262:AAFcwQYqbFq72cypWNubV2gBfGz25BIZDy0}
|
||||||
|
|
||||||
|
app:
|
||||||
|
internal-token: "redjinald_dj_bot"
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE review_queue (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
artist TEXT,
|
||||||
|
source_url TEXT,
|
||||||
|
tmp_file_path TEXT,
|
||||||
|
status TEXT NOT NULL DEFAULT 'pending',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
processed_at TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_review_queue_status ON review_queue(status);
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.redjinald.autodj_backend;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class AutodjBackendApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user