not working

This commit is contained in:
Jose Conde
2025-09-07 13:39:13 +02:00
commit 5f80c98ddd
48 changed files with 1376 additions and 0 deletions

45
.gitignore vendored Normal file
View File

@@ -0,0 +1,45 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Kotlin ###
.kotlin
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

17
.idea/gradle.xml generated Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="17" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

6
.idea/kotlinc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="2.2.0" />
</component>
</project>

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

27
Dockerfile Normal file
View File

@@ -0,0 +1,27 @@
# Use a JDK base image for building
FROM gradle:8.10.2-jdk17-alpine AS builder
# Set working directory
WORKDIR /app
# Copy build files
COPY build.gradle.kts settings.gradle.kts ./
COPY src ./src
# Build the application
RUN gradle build --no-daemon
# Use a lightweight JRE image for running
FROM eclipse-temurin:21-jre
# Set working directory
WORKDIR /app
# Copy the built JAR from the builder stage
COPY --from=builder /app/build/libs/*.jar app.jar
# Expose the port (default for Spring Boot)
EXPOSE 8080
# Run the application
ENTRYPOINT ["java", "-jar", "app.jar"]

54
build.gradle.kts Normal file
View File

@@ -0,0 +1,54 @@
plugins {
kotlin("jvm") version "2.2.0"
kotlin("plugin.spring") version "1.9.25"
id("org.springframework.boot") version "3.3.4"
id("io.spring.dependency-management") version "1.1.6"
kotlin("plugin.jpa") version "1.9.25"
}
group = "net.xintanalabs.rssotto"
version = "0.0.1-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
repositories {
mavenCentral()
}
dependencies {
//implementation("org.springframework.boot:spring-boot-starter-data-jpa")
//implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb:3.2.5")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.8.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
implementation("com.prof18.rssparser:rssparser:6.0.12")
implementation("org.mongodb:mongodb-driver-kotlin-coroutine:5.5.0")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.seleniumhq.selenium:selenium-java:4.25.0")
implementation("org.jsoup:jsoup:1.21.2")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.springframework.security:spring-security-test")
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(17)
}

1
gradle.properties Normal file
View File

@@ -0,0 +1 @@
kotlin.code.style=official

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,6 @@
#Mon Sep 01 16:24:52 CEST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

234
gradlew vendored Normal file
View File

@@ -0,0 +1,234 @@
#!/bin/sh
#
# Copyright © 2015-2021 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.
#
##############################################################################
#
# 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/master/subprojects/plugins/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
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# 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"'
# 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
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# 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
which java >/dev/null 2>&1 || 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
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
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" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
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
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# 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" "$@"

89
gradlew.bat vendored Normal file
View File

@@ -0,0 +1,89 @@
@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
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
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%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

4
settings.gradle.kts Normal file
View File

@@ -0,0 +1,4 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}
rootProject.name = "rssotto"

15
src/main/kotlin/Test.kt Normal file
View File

@@ -0,0 +1,15 @@
/*import com.prof18.rssparser.RssParser
import com.prof18.rssparser.model.RssChannel
import kotlinx.coroutines.runBlocking
import net.xintanalabs.rssotto.parser.RssottoParser
fun main(args: Array<String>) {
val rssParser: RssParser = RssParser()
val rss: RssottoParser = RssottoParser()
runBlocking {
//rss.getFeed("https://fselite.net/feed/")
rss.getFeed("https://www.thresholdx.net/news/rss.xml")
}
}*/

View File

@@ -0,0 +1,56 @@
package net.xintanalabs.rssotto.config
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeDriverService
import org.openqa.selenium.chrome.ChromeOptions
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter
import org.springframework.web.client.RestTemplate
import kotlinx.serialization.json.Json
import java.io.File
@Configuration
class AppConfig {
@Bean
fun restTemplate(): RestTemplate {
return RestTemplate()
}
@Bean
fun json(): Json {
return Json {
ignoreUnknownKeys = true
coerceInputValues = true
prettyPrint = true
}
}
@Bean
fun additionalMessageConverters(json: Json): List<KotlinSerializationJsonHttpMessageConverter> {
return listOf(KotlinSerializationJsonHttpMessageConverter(json))
}
@Bean(destroyMethod = "quit")
fun chromeDriver(): ChromeDriver {
// Set log file to suppress console output (optional)
val logFile = File("chromedriver.log")
val service = ChromeDriverService.Builder()
.withLogFile(logFile) // Redirect logs to a file
.withSilent(true) // Suppress console output
.withVerbose(false) // Explicitly disable verbose logging
.build()
// Optional: Set hideCommandPromptWindow for Windows
System.setProperty("webdriver.chrome.hideCommandPromptWindow", "true")
val options = ChromeOptions().apply {
addArguments("--headless")
addArguments("--disable-gpu")
addArguments("--no-sandbox")
addArguments("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124")
}
return ChromeDriver(service, options)
}
}

View File

@@ -0,0 +1,11 @@
package net.xintanalabs.rssotto
import kotlinx.serialization.Serializable
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.bind.ConstructorBinding
@Serializable
@ConfigurationProperties(prefix = "version-checker")
data class ApplicationConfig(
val intervalMinutes: Int
)

View File

@@ -0,0 +1,12 @@
package net.xintanalabs.rssotto
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
class RssotoApplication
fun main(args: Array<String>) {
runApplication<RssotoApplication>(*args)
}

View File

@@ -0,0 +1,37 @@
package net.xintanalabs.rssotto.components.checkers
import kotlinx.serialization.json.*
import net.xintanalabs.rssotto.model.Source
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.awaitBody
import org.springframework.web.reactive.function.client.awaitExchange
@Component
class ApiChecker(private val webClient: WebClient) : IVersionChecker {
override suspend fun getLatestVersion(paramsDict: Map<String, String>, source: Source): String {
val url = paramsDict["url"]?.takeIf { it.isNotEmpty() }
?: throw IllegalArgumentException("API URL required")
val jsonPath = paramsDict["jsonPath"]?.takeIf { it.isNotEmpty() }
?: throw IllegalArgumentException("jsonPath required")
val response = webClient.get()
.uri(url)
.awaitExchange { it.awaitBody<String>() }
?: throw Exception("Empty API response")
val jsonDoc = Json.parseToJsonElement(response)
var element: JsonElement = jsonDoc
jsonPath.split('.').forEach { key ->
element = (element as? JsonObject)?.get(key)
?: throw Exception("JSON key '$key' not found in response")
}
if (element !is JsonPrimitive || !element.isString) {
throw Exception("JSON value for '$jsonPath' is not a string")
}
return element.content.trim()
}
}

View File

@@ -0,0 +1,19 @@
package net.xintanalabs.rssotto.components.checkers
import net.xintanalabs.rssotto.components.checkers.scrape.ScrapeChecker
import org.springframework.stereotype.Component
@Component
class CheckerFactory(
private val apiChecker: ApiChecker,
private val scrapeChecker: ScrapeChecker
) {
fun createChecker(type: String): IVersionChecker {
val parts = type.split(":")
return when (parts[0].lowercase()) {
"scrape" -> scrapeChecker
"api" -> apiChecker
else -> throw IllegalArgumentException("Unknown checker type: $type")
}
}
}

View File

@@ -0,0 +1,7 @@
package net.xintanalabs.rssotto.components.checkers
import net.xintanalabs.rssotto.model.Source
interface IVersionChecker {
suspend fun getLatestVersion(paramsDict: Map<String, String>, source: Source): String
}

View File

@@ -0,0 +1,70 @@
package net.xintanalabs.rssotto.components.checkers
import kotlinx.coroutines.*
import net.xintanalabs.rssotto.ApplicationConfig
import net.xintanalabs.rssotto.model.App
import net.xintanalabs.rssotto.model.CheckerType
import net.xintanalabs.rssotto.model.Source
import net.xintanalabs.rssotto.services.AppService
import net.xintanalabs.rssotto.services.CheckerTypeService
import net.xintanalabs.rssotto.services.SourceService
import org.slf4j.LoggerFactory
import org.springframework.scheduling.annotation.Async
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
@Component
class VersionCheckTask(
private val config: ApplicationConfig,
private val appService: AppService,
private val sourceService: SourceService,
private val checkerTypeService: CheckerTypeService
//private val versionService: VersionService
) {
private val logger = LoggerFactory.getLogger(VersionCheckTask::class.java)
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
//@Scheduled(fixedRateString = "\${version-checker.interval-minutes}000", initialDelay = 1000)
//@Async
fun checkVersions() {
scope.launch {
val apps: List<App> = appService.getAllApps()
var sources: List<Source> = sourceService.getAllSources()
var checkerTypes: List<CheckerType> = checkerTypeService.getAllCheckerTypes()
logger.info("Starting version check task for ${apps.size} sources")
apps.map { app ->
// async {
// try {
/*
val source: Source? = sources.find { s -> s.id == app.source }
if (source != null) {
val checkerType: CheckerType? = checkerTypes.find { ct -> ct.id == source.checkerType }
app.params
val params = mutableMapOf<String, String>()
app.url.let { params["url"] = it }
app.jsonPath?.let { params["jsonPath"] = it }
app.regex?.let { params["regex"] = it }
app.mode?.let { params["mode"] = it }
val sourceDef = SourceDef(
defaults = mapOf(
"regex" to (app.regex ?: ""),
"mode" to (app.mode ?: "default")
)
)
val version = versionService.checkVersion(app.type, params, sourceDef)
logger.info("Version for ${app.url} (${app.type}): $version")*/
// Optionally save to DB (if using JPA)
}
//} catch (e: Exception) {
//logger.error("Failed to check version for ${app.url}: ${e.message}", e)
//}
// }
// }.awaitAll()
}
}
}

View File

@@ -0,0 +1,38 @@
package net.xintanalabs.rssotto.components.checkers
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeDriverService
import org.openqa.selenium.chrome.ChromeOptions
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.client.RestTemplate
import org.springframework.web.reactive.function.client.WebClient
import java.io.File
@Configuration
class WebConfig {
@Bean
fun restTemplate(): RestTemplate = RestTemplate()
@Bean
fun webClient(): WebClient = WebClient.builder().build()
@Bean
fun chromeDriver(): ChromeDriver {
val logFile = File("chromedriver.log")
val service = ChromeDriverService.Builder()
.withLogFile(logFile) // Redirect logs to a file
.withSilent(true) // Suppress console output
.withVerbose(false) // Explicitly disable verbose logging
.build()
val options = ChromeOptions().apply {
addArguments("--headless")
addArguments("--disable-gpu")
addArguments("--no-sandbox")
addArguments("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/91.0.4472.124")
}
return ChromeDriver(service, options)
}
}

View File

@@ -0,0 +1,13 @@
package net.xintanalabs.rssotto.components.checkers.scrape
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.stereotype.Component
import org.springframework.web.client.RestTemplate
@Component("default")
class DefaultScrapeFetcher(private val restTemplate: RestTemplate) : IScrapeFetcher{
override suspend fun fetch(url: String): String {
return restTemplate.getForObject(url, String::class.java)
?: throw Exception("Empty response from URL")
}
}

View File

@@ -0,0 +1,5 @@
package net.xintanalabs.rssotto.components.checkers.scrape
interface IScrapeFetcher {
suspend fun fetch(url: String): String
}

View File

@@ -0,0 +1,20 @@
package net.xintanalabs.rssotto.components.checkers.scrape
import org.jsoup.Jsoup
import org.springframework.stereotype.Component
@Component("jsoup")
class JSoupFetcher: IScrapeFetcher {
override suspend fun fetch(url: String): String {
return try {
Jsoup.connect(url)
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
.header("Accept-Language", "en-US,en;q=0.5")
.get()
.html()
} catch (e: Exception) {
throw RuntimeException("Error fetching ${url}", e)
}
}
}

View File

@@ -0,0 +1,43 @@
package net.xintanalabs.rssotto.components.checkers.scrape
import kotlinx.coroutines.delay
import net.xintanalabs.rssotto.components.checkers.IVersionChecker
import net.xintanalabs.rssotto.model.Source
import org.openqa.selenium.chrome.ChromeDriver
import org.springframework.stereotype.Component
import org.springframework.web.client.RestTemplate
import java.util.regex.Pattern
@Component
class ScrapeChecker(
private val restTemplate: RestTemplate,
private val chromeDriver: ChromeDriver
) : IVersionChecker {
override suspend fun getLatestVersion(paramsDict: Map<String, String>, source: Source): String {
val url = paramsDict["url"]?.takeIf { it.isNotEmpty() }
?: throw IllegalArgumentException("URL required")
val mode = getValueOrDefault(paramsDict, "mode", source)
val fetcher: IScrapeFetcher = when (mode) {
"selenium" -> SeleniumFetcher(chromeDriver)
"jsoup" -> JSoupFetcher()
else -> DefaultScrapeFetcher(restTemplate)
}
val response = fetcher.fetch(url)
val cleanedResponse = response.replace(">\\s+<".toRegex(), "><")
val regex = getValueOrDefault(paramsDict, "regex", source)
val match = Pattern.compile(regex).matcher(cleanedResponse)
if (!match.find() || match.groupCount() < 1) {
throw Exception("No match with regex in response")
}
return match.group(1)
}
private fun getValueOrDefault(dict: Map<String, String>, key: String, source: Source): String {
return dict[key]?.takeIf { it.isNotEmpty() }
?: source.defaults[key]
?: ""
}
}

View File

@@ -0,0 +1,19 @@
package net.xintanalabs.rssotto.components.checkers.scrape
import kotlinx.coroutines.delay
import org.openqa.selenium.chrome.ChromeDriver
import org.springframework.stereotype.Component
@Component("selenium")
class SeleniumFetcher(private val chromeDriver: ChromeDriver): IScrapeFetcher {
override suspend fun fetch(url: String): String {
try {
chromeDriver.get(url)
delay(2000) // Consider WebDriverWait for robustness
return chromeDriver.pageSource
} finally {
// Note: Don't quit driver here since it's Spring-managed
}
}
}

View File

@@ -0,0 +1,9 @@
package net.xintanalabs.rssotto.constants
object Constants {
const val API_BASE_PATH_V0: String = "/api/v0"
const val COLLECTION_TYPES: String = "types"
const val COLLECTION_APPS: String = "apps"
const val COLLECTION_SOURCES: String = "sources"
const val COLLECTION_CHECKER_TYPES: String = "checkerTypes"
}

View File

@@ -0,0 +1,27 @@
package net.xintanalabs.rssotto.controller
import net.xintanalabs.rssotto.constants.Constants
import org.springframework.web.bind.annotation.*
data class Addon(val id: Long, val name: String, val version: String)
@RestController
@RequestMapping("${Constants.API_BASE_PATH_V0}/addons")
class AddonController {
private val addons = mutableListOf(
Addon(1, "PMDG Boeing 737", "1.5.2"),
Addon(2, "PMDG Boeing 777", "2.1.1")
)
@GetMapping
fun getAllAddons(): List<Addon> = addons
@GetMapping("/{id}")
fun getAddonById(@PathVariable id: Long): Addon? = addons.find { it.id == id }
@PostMapping
fun createAddon(@RequestBody addon: Addon): Addon {
addons.add(addon)
return addon
}
}

View File

@@ -0,0 +1,30 @@
package net.xintanalabs.rssotto.controller
import net.xintanalabs.rssotto.constants.Constants
import net.xintanalabs.rssotto.model.App
import net.xintanalabs.rssotto.services.AppService
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.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("${Constants.API_BASE_PATH_V0}/apps")
class AppController (private val appService: AppService){
@PostMapping
suspend fun createApp(@RequestBody app: App): App {
return appService.createApp(app)
}
@GetMapping("/{id}")
suspend fun getApp(@PathVariable id: String): App? {
return appService.getAppById(id)
}
@GetMapping
suspend fun getAllApps(): List<App> {
return appService.getAllApps()
}
}

View File

@@ -0,0 +1,31 @@
package net.xintanalabs.rssotto.controller
import net.xintanalabs.rssotto.constants.Constants
import net.xintanalabs.rssotto.model.CheckerType
import net.xintanalabs.rssotto.services.CheckerTypeService
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.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("${Constants.API_BASE_PATH_V0}/checkerTypes")
class CheckerTypeController(private val checkerTypeService: CheckerTypeService) {
@PostMapping
suspend fun createCheckerType(@RequestBody checkerType: CheckerType): CheckerType {
return checkerTypeService.create(checkerType)
}
@GetMapping
suspend fun getAllCheckerTypes(): List<CheckerType> {
return checkerTypeService.getAllCheckerTypes()
}
@GetMapping("/{id}")
suspend fun getType(@PathVariable id: String): CheckerType? {
return checkerTypeService.getCheckerTypeById(id)
}
}

View File

@@ -0,0 +1,24 @@
package net.xintanalabs.rssotto.controller
import net.xintanalabs.rssotto.constants.Constants
import net.xintanalabs.rssotto.model.Source
import net.xintanalabs.rssotto.services.SourceService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("${Constants.API_BASE_PATH_V0}/sources")
class SourceController(private val sourceService: SourceService) {
@PostMapping
suspend fun createSource(@RequestBody source: Source): Source {
return sourceService.createSource(source)
}
@GetMapping
suspend fun getAllSources(): List<Source> {
return sourceService.getAllSources()
}
}

View File

@@ -0,0 +1,31 @@
package net.xintanalabs.rssotto.controller
import net.xintanalabs.rssotto.constants.Constants
import net.xintanalabs.rssotto.model.Type
import net.xintanalabs.rssotto.services.TypeService
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.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("${Constants.API_BASE_PATH_V0}/types")
class TypeController(private val typeService: TypeService) {
@PostMapping
suspend fun createType(@RequestBody type: Type): Type {
return typeService.createType(type)
}
@GetMapping
suspend fun getAllTypes(): List<Type> {
return typeService.getAllTypes()
}
@GetMapping("/{id}")
suspend fun getType(@PathVariable id: String): Type? {
return typeService.getTypeById(id)
}
}

View File

@@ -0,0 +1,70 @@
package net.xintanalabs.rssotto.db.mongodb
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
import org.springframework.data.mongodb.core.MongoTemplate
import org.springframework.data.mongodb.core.aggregation.Aggregation
import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
import org.springframework.data.mongodb.core.query.Update
import org.springframework.stereotype.Component
@Component
class MongoDBClient(private val mongoTemplate: MongoTemplate) {
// Insert a single document
suspend fun <T : Any> insert(collectionName: String, document: T, clazz: Class<T>): T {
return mongoTemplate.insert(document, collectionName)
}
// Insert multiple documents
suspend fun <T : Any> insertMany(collectionName: String, documents: List<T>, clazz: Class<T>): List<T> {
return mongoTemplate.insert(documents, collectionName).toList()
}
// Find one document by a field
suspend fun <T : Any> findOne(collectionName: String, field: String, value: Any, clazz: Class<T>): T? {
val query = Query(Criteria.where(field).`is`(value))
return mongoTemplate.findOne(query, clazz, collectionName)
}
// Find all documents in a collection
suspend fun <T : Any> findAll(collectionName: String, clazz: Class<T>): Flow<T> {
return mongoTemplate.findAll(clazz, collectionName).asFlow()
}
// Find documents with a custom filter
suspend fun <T : Any> findByFilter(collectionName: String, criteria: Criteria, clazz: Class<T>): Flow<T> {
val query = Query(criteria)
return mongoTemplate.find(query, clazz, collectionName).asFlow()
}
// Update one document
suspend fun <T : Any> updateOne(collectionName: String, field: String, value: Any, updateFields: Map<String, Any>, clazz: Class<T>): Long {
val query = Query(Criteria.where(field).`is`(value))
val update = Update().apply {
updateFields.forEach { (k, v) -> set(k, v) }
}
return mongoTemplate.updateFirst(query, update, clazz, collectionName).modifiedCount
}
// Delete one document
suspend fun <T : Any> deleteOne(collectionName: String, field: String, value: Any, clazz: Class<T>): Long {
val query = Query(Criteria.where(field).`is`(value))
return mongoTemplate.remove(query, clazz, collectionName).deletedCount
}
suspend fun <T: Any, R: Any> aggregate(
collectionName: String,
aggregation: Aggregation,
inputType: Class<T>,
outputType: Class<R>
): Flow<R> {
return try {
val results = mongoTemplate.aggregate(aggregation, collectionName, outputType)
results.asFlow()
} catch (e: Exception) {
throw RuntimeException("Aggregation failed: ${e.message}", e)
}
}
}

View File

@@ -0,0 +1,23 @@
package net.xintanalabs.rssotto.model
import com.fasterxml.jackson.annotation.JsonInclude
import org.springframework.data.annotation.Id
@JsonInclude(JsonInclude.Include.NON_NULL)
data class App(
@Id val id: String? = null,
val uid: String,
val name: String,
val type: String,
val source: String,
val params: Map<String, String>,
val fields: Map<String, String>,
val downloadUrl: String,
val currentVersion: String,
val latestVersion: String,
val status: AppStatus,
val createdAt: Long = 0,
val updatedAt: Long = 0,
val lastCheckedAt: Long = 0
)

View File

@@ -0,0 +1,7 @@
package net.xintanalabs.rssotto.model
enum class AppStatus {
NONE,
ERROR,
UPDATE_AVAILABLE
}

View File

@@ -0,0 +1,11 @@
package net.xintanalabs.rssotto.model
import com.fasterxml.jackson.annotation.JsonInclude
import org.springframework.data.annotation.Id
@JsonInclude(JsonInclude.Include.NON_NULL)
data class CheckerType(
@Id val id: String? = null,
val name: String,
val params: List<Field>
)

View File

@@ -0,0 +1,14 @@
package net.xintanalabs.rssotto.model
import com.fasterxml.jackson.annotation.JsonInclude
import org.springframework.data.annotation.Id
@JsonInclude(JsonInclude.Include.NON_NULL)
data class Field(
@Id val id: String? = null,
val name: String,
val label: String,
val type: String,
val required: Boolean = false,
val controlType: String? = null
)

View File

@@ -0,0 +1,12 @@
package net.xintanalabs.rssotto.model
import com.fasterxml.jackson.annotation.JsonInclude
import org.springframework.data.annotation.Id
@JsonInclude(JsonInclude.Include.NON_NULL)
data class Source(
@Id val id: String? = null,
val name: String,
val checkerType: String,
val defaults: Map<String, String> = mapOf()
)

View File

@@ -0,0 +1,16 @@
package net.xintanalabs.rssotto.model
import com.fasterxml.jackson.annotation.JsonInclude
import org.springframework.data.annotation.Id
@JsonInclude(JsonInclude.Include.NON_NULL)
data class Type(
@Id val id: String? = null,
val shortName: String,
val path: String,
val name: String,
val file: String,
val fileType: String,
val key: String,
val fields: List<Field>
)

View File

@@ -0,0 +1,24 @@
package net.xintanalabs.rssotto.parser
import com.prof18.rssparser.RssParser
import com.prof18.rssparser.RssParserBuilder
class RssottoParser() {
private val parser = RssParserBuilder().build()
suspend fun getFeed(channelUrl: String) {
val channel = parser.getRssChannel(channelUrl)
println(channel.title)
println(channel.lastBuildDate)
println(channel.items.size)
for (item in channel.items) {
if (item.title?.lowercase()?.contains("pmdg") == true || item.description?.lowercase()?.contains("pmdg") == true) {
println("- " + item.title)
println(item)
println(item.description)
}
}
}
}

View File

@@ -0,0 +1,71 @@
package net.xintanalabs.rssotto.services
import net.xintanalabs.rssotto.db.mongodb.MongoDBClient
import kotlinx.coroutines.flow.toList
import net.xintanalabs.rssotto.constants.Constants
import net.xintanalabs.rssotto.model.App
import net.xintanalabs.rssotto.model.AppStatus
import org.springframework.stereotype.Service
@Service
class AppService(private val mongoDBClient: MongoDBClient) {
private val collection: String = Constants.COLLECTION_APPS
suspend fun createApp(app: App): App {
return mongoDBClient.insert(collection, app, App::class.java)
}
suspend fun getAllApps(): List<App> {
try {
return mongoDBClient.findAll(collection, App::class.java).toList()
} catch (e: Exception) {
throw RuntimeException("Failed to find all documents: ${e.message}", e)
}
}
suspend fun getAppById(id: String): App? {
return mongoDBClient.findOne(collection, "uid", id, App::class.java)
}
suspend fun deleteApp(id: String): Long {
return mongoDBClient.deleteOne(collection, "uid", id, App::class.java)
}
suspend fun updateAppDetails(id: String, newName: String?, newStatus: AppStatus?): Long {
val updateFields = mutableMapOf<String, Any>()
newName?.let { updateFields["name"] = it }
newStatus?.let { updateFields["status"] = it }
updateFields["updatedAt"] = System.currentTimeMillis()
return try {
mongoDBClient.updateOne(
collectionName = "apps",
field = "_id",
value = id,
updateFields = updateFields,
clazz = App::class.java
)
} catch (e: Exception) {
throw RuntimeException("Failed to update app: ${e.message}", e)
}
}
suspend fun updateStatus(id: String, status: AppStatus): Long {
try {
val updateFields = mapOf<String, Any>(
"status" to status,
"lastCheckedAt" to System.currentTimeMillis()
)
return mongoDBClient.updateOne(
collection,
"uid",
id,
updateFields,
App::class.java
)
} catch (e: Exception) {
throw RuntimeException("Failed to update user: ${e.message}", e)
}
}
}

View File

@@ -0,0 +1,24 @@
package net.xintanalabs.rssotto.services
import net.xintanalabs.rssotto.constants.Constants
import net.xintanalabs.rssotto.db.mongodb.MongoDBClient
import net.xintanalabs.rssotto.model.CheckerType
import org.springframework.stereotype.Service
@Service
class CheckerTypeService (mongoDBClient: MongoDBClient) : ServiceBase<CheckerType>(mongoDBClient){
override val collection: String = Constants.COLLECTION_CHECKER_TYPES
override val entityClass: Class<CheckerType> = CheckerType::class.java
suspend fun createCheckerType(checkerType: CheckerType): CheckerType {
return create(checkerType)
}
suspend fun getAllCheckerTypes(): List<CheckerType> {
return getAll()
}
suspend fun getCheckerTypeById(id: String): CheckerType? {
return getById(id)
}
}

View File

@@ -0,0 +1,31 @@
package net.xintanalabs.rssotto.services
import kotlinx.coroutines.flow.toList
import net.xintanalabs.rssotto.db.mongodb.MongoDBClient
import org.springframework.beans.factory.annotation.Autowired
abstract class ServiceBase<T: Any> @Autowired constructor(protected val mongoDBClient: MongoDBClient) {
protected abstract val collection: String
protected abstract val entityClass: Class<T>
protected val idField: String = "id"
suspend fun create(entity: T): T {
return mongoDBClient.insert(collection, entity, entityClass)
}
suspend fun getAll(): List<T> {
return mongoDBClient.findAll(collection, entityClass).toList()
}
suspend fun getById(id: String): T? {
return mongoDBClient.findOne(collection, idField, id, entityClass)
}
suspend fun delete(id: String): Long {
return mongoDBClient.deleteOne(collection, idField, id, entityClass)
}
suspend fun update(id: String, updateFields: Map<String, Any>): Long {
return mongoDBClient.updateOne(collection, idField, id, updateFields, entityClass)
}
}

View File

@@ -0,0 +1,24 @@
package net.xintanalabs.rssotto.services
import net.xintanalabs.rssotto.constants.Constants
import net.xintanalabs.rssotto.db.mongodb.MongoDBClient
import net.xintanalabs.rssotto.model.Source
import org.springframework.stereotype.Service
@Service
class SourceService(mongoDBClient: MongoDBClient): ServiceBase<Source>(mongoDBClient) {
override val collection: String = Constants.COLLECTION_SOURCES
override val entityClass: Class<Source> = Source::class.java
suspend fun createSource(source: Source): Source {
return create(source)
}
suspend fun getAllSources(): List<Source> {
return getAll()
}
suspend fun getSourceById(id: String): Source? {
return getById(id)
}
}

View File

@@ -0,0 +1,25 @@
package net.xintanalabs.rssotto.services
import kotlinx.coroutines.flow.toList
import net.xintanalabs.rssotto.constants.Constants
import net.xintanalabs.rssotto.db.mongodb.MongoDBClient
import net.xintanalabs.rssotto.model.Type
import org.springframework.stereotype.Service
@Service
class TypeService(mongoDBClient: MongoDBClient) : ServiceBase<Type>(mongoDBClient) {
override val collection: String = Constants.COLLECTION_TYPES
override val entityClass: Class<Type> = Type::class.java
suspend fun createType(type: Type): Type {
return create(type)
}
suspend fun getAllTypes(): List<Type> {
return getAll()
}
suspend fun getTypeById(id: String): Type? {
return getById(id)
}
}

View File

@@ -0,0 +1,8 @@
server.port=8080
spring.data.mongodb.uri=mongodb://root:A%3Ay(nW%3C06Gu%5D*Q8%5DA%40j)@192.168.1.115:27017/
spring.data.mongodb.database=rssotto
logging.level.org.springframework.data.mongodb=DEBUG
version-checker.interval-minutes=5