Compare commits
14 Commits
446ec752b4
...
64bd7d56e5
| Author | SHA1 | Date | |
|---|---|---|---|
| 64bd7d56e5 | |||
|
|
5ca4253b44 | ||
|
|
eb75f86d45 | ||
|
|
395e2a84bd | ||
|
|
3fb60227df | ||
|
|
9a4eb77c56 | ||
|
|
02c1765214 | ||
|
|
ee93e15af8 | ||
|
|
d31026a606 | ||
|
|
4dca2af645 | ||
|
|
63b5786e43 | ||
|
|
497d804244 | ||
|
|
9ca1464899 | ||
|
|
8f6fda2e61 |
@@ -121,11 +121,12 @@ jobs:
|
|||||||
|
|
||||||
- name: OSV-Scanner (SCA)
|
- name: OSV-Scanner (SCA)
|
||||||
run: |
|
run: |
|
||||||
|
cd "$GITHUB_WORKSPACE"
|
||||||
curl -L -o osv-scanner https://github.com/google/osv-scanner/releases/latest/download/osv-scanner_linux_amd64
|
curl -L -o osv-scanner https://github.com/google/osv-scanner/releases/latest/download/osv-scanner_linux_amd64
|
||||||
chmod +x osv-scanner
|
chmod +x osv-scanner
|
||||||
./osv-scanner --version
|
./osv-scanner --version
|
||||||
test -f ./package-lock.json
|
test -f "$GITHUB_WORKSPACE/package-lock.json"
|
||||||
./osv-scanner scan -L ./package-lock.json --config ./.osv-scanner.toml
|
./osv-scanner scan -L "$GITHUB_WORKSPACE/package-lock.json" --config "$GITHUB_WORKSPACE/.osv-scanner.toml"
|
||||||
|
|
||||||
deploy-production:
|
deploy-production:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
@@ -117,7 +117,7 @@
|
|||||||
<div class="hidden min-w-0 flex-1 lg:flex items-center h-6 border-t border-primary-700/20">
|
<div class="hidden min-w-0 flex-1 lg:flex items-center h-6 border-t border-primary-700/20">
|
||||||
<div
|
<div
|
||||||
v-if="currentSubmenu"
|
v-if="currentSubmenu"
|
||||||
:class="currentSubmenu === 'mannschaften' ? 'relative min-w-0 flex-1' : 'flex min-w-0 items-center gap-1 overflow-x-auto whitespace-nowrap'"
|
:class="currentSubmenu === 'mannschaften' ? 'relative min-w-0 flex-1' : currentSubmenu === 'intern' ? 'flex min-w-0 items-center gap-1' : 'flex min-w-0 items-center gap-1 overflow-x-auto whitespace-nowrap'"
|
||||||
>
|
>
|
||||||
<!-- Newsletter Submenu -->
|
<!-- Newsletter Submenu -->
|
||||||
<template v-if="currentSubmenu === 'newsletter'">
|
<template v-if="currentSubmenu === 'newsletter'">
|
||||||
@@ -290,7 +290,8 @@
|
|||||||
|
|
||||||
<!-- Intern Submenu -->
|
<!-- Intern Submenu -->
|
||||||
<template v-if="currentSubmenu === 'intern'">
|
<template v-if="currentSubmenu === 'intern'">
|
||||||
<NuxtLink
|
<div class="flex min-w-0 flex-1 items-center gap-1 overflow-x-auto whitespace-nowrap">
|
||||||
|
<NuxtLink
|
||||||
to="/mitgliederbereich"
|
to="/mitgliederbereich"
|
||||||
class="px-2.5 py-1 text-xs font-semibold text-white hover:bg-primary-700/50 rounded transition-all"
|
class="px-2.5 py-1 text-xs font-semibold text-white hover:bg-primary-700/50 rounded transition-all"
|
||||||
active-class="bg-primary-600"
|
active-class="bg-primary-600"
|
||||||
@@ -310,7 +311,7 @@
|
|||||||
class="px-2.5 py-1 text-xs text-gray-300 hover:text-white hover:bg-primary-700/50 rounded transition-all"
|
class="px-2.5 py-1 text-xs text-gray-300 hover:text-white hover:bg-primary-700/50 rounded transition-all"
|
||||||
active-class="text-white bg-primary-600"
|
active-class="text-white bg-primary-600"
|
||||||
>
|
>
|
||||||
QTTR
|
TTR / QTTR
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
to="/mitgliederbereich/news"
|
to="/mitgliederbereich/news"
|
||||||
@@ -354,9 +355,10 @@
|
|||||||
Kontaktanfragen
|
Kontaktanfragen
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</template>
|
</template>
|
||||||
|
</div>
|
||||||
<template v-if="isAdmin">
|
<template v-if="isAdmin">
|
||||||
<div class="h-3 w-px bg-primary-700" />
|
<div class="h-3 w-px shrink-0 bg-primary-700" />
|
||||||
<div class="relative inline-block">
|
<div class="relative shrink-0 inline-block">
|
||||||
<button
|
<button
|
||||||
class="px-2.5 py-1 text-xs text-yellow-300 hover:text-white hover:bg-primary-700/50 rounded transition-all flex items-center"
|
class="px-2.5 py-1 text-xs text-yellow-300 hover:text-white hover:bg-primary-700/50 rounded transition-all flex items-center"
|
||||||
:class="route.path.startsWith('/cms') ? 'text-white bg-primary-600' : ''"
|
:class="route.path.startsWith('/cms') ? 'text-white bg-primary-600' : ''"
|
||||||
@@ -441,6 +443,13 @@
|
|||||||
>
|
>
|
||||||
Einstellungen
|
Einstellungen
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
|
<NuxtLink
|
||||||
|
to="/cms/mytischtennis"
|
||||||
|
class="block px-4 py-2 text-sm text-gray-300 hover:bg-primary-600 hover:text-white transition-colors"
|
||||||
|
@click="showCmsDropdown = false"
|
||||||
|
>
|
||||||
|
myTischtennis
|
||||||
|
</NuxtLink>
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
to="/cms/benutzer"
|
to="/cms/benutzer"
|
||||||
class="block px-4 py-2 text-sm text-gray-300 hover:bg-primary-600 hover:text-white transition-colors"
|
class="block px-4 py-2 text-sm text-gray-300 hover:bg-primary-600 hover:text-white transition-colors"
|
||||||
@@ -757,7 +766,7 @@
|
|||||||
class="block px-4 py-2 text-sm text-gray-400 hover:text-white hover:bg-primary-700/50 rounded-lg transition-colors"
|
class="block px-4 py-2 text-sm text-gray-400 hover:text-white hover:bg-primary-700/50 rounded-lg transition-colors"
|
||||||
@click="isMobileMenuOpen = false"
|
@click="isMobileMenuOpen = false"
|
||||||
>
|
>
|
||||||
QTTR
|
TTR / QTTR
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
to="/mitgliederbereich/news"
|
to="/mitgliederbereich/news"
|
||||||
@@ -858,6 +867,13 @@
|
|||||||
>
|
>
|
||||||
Einstellungen
|
Einstellungen
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
|
<NuxtLink
|
||||||
|
to="/cms/mytischtennis"
|
||||||
|
class="block px-4 py-2 text-sm text-yellow-300 hover:text-white hover:bg-primary-700/50 rounded-lg transition-colors"
|
||||||
|
@click="isMobileMenuOpen = false"
|
||||||
|
>
|
||||||
|
myTischtennis
|
||||||
|
</NuxtLink>
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
v-if="canManageUsers"
|
v-if="canManageUsers"
|
||||||
to="/cms/benutzer"
|
to="/cms/benutzer"
|
||||||
|
|||||||
@@ -102,6 +102,18 @@ install_dependencies_if_needed() {
|
|||||||
printf '%s\n' "$current_lock_hash" > "$lock_hash_file"
|
printf '%s\n' "$current_lock_hash" > "$lock_hash_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_playwright_browser() {
|
||||||
|
if [ ! -d "node_modules/playwright" ]; then
|
||||||
|
echo " Playwright ist nicht installiert; Browser-Installation wird übersprungen"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Muss mit demselben Benutzer laufen, der später den PM2-Prozess startet;
|
||||||
|
# Playwright legt den Browser im benutzerspezifischen Cache ab.
|
||||||
|
echo " Installing/verifying Playwright Chromium browser..."
|
||||||
|
npx playwright install chromium
|
||||||
|
}
|
||||||
|
|
||||||
use_project_node() {
|
use_project_node() {
|
||||||
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
|
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
|
||||||
if [ -s "$NVM_DIR/nvm.sh" ]; then
|
if [ -s "$NVM_DIR/nvm.sh" ]; then
|
||||||
@@ -278,6 +290,7 @@ echo "3. Installing dependencies..."
|
|||||||
use_project_node
|
use_project_node
|
||||||
ensure_node_version
|
ensure_node_version
|
||||||
install_dependencies_if_needed
|
install_dependencies_if_needed
|
||||||
|
install_playwright_browser
|
||||||
|
|
||||||
# 4. Stop running apps before replacing build artifacts
|
# 4. Stop running apps before replacing build artifacts
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -115,6 +115,18 @@ install_dependencies_if_needed() {
|
|||||||
printf '%s\n' "$current_lock_hash" > "$lock_hash_file"
|
printf '%s\n' "$current_lock_hash" > "$lock_hash_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_playwright_browser() {
|
||||||
|
if [ ! -d "node_modules/playwright" ]; then
|
||||||
|
echo " Playwright ist nicht installiert; Browser-Installation wird übersprungen"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Muss mit demselben Benutzer laufen, der später den PM2-Prozess startet;
|
||||||
|
# Playwright legt den Browser im benutzerspezifischen Cache ab.
|
||||||
|
echo " Installing/verifying Playwright Chromium browser..."
|
||||||
|
npx playwright install chromium
|
||||||
|
}
|
||||||
|
|
||||||
use_project_node() {
|
use_project_node() {
|
||||||
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
|
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
|
||||||
if [ -s "$NVM_DIR/nvm.sh" ]; then
|
if [ -s "$NVM_DIR/nvm.sh" ]; then
|
||||||
@@ -284,6 +296,7 @@ echo "3. Installing dependencies..."
|
|||||||
use_project_node
|
use_project_node
|
||||||
ensure_node_version
|
ensure_node_version
|
||||||
install_dependencies_if_needed
|
install_dependencies_if_needed
|
||||||
|
install_playwright_browser
|
||||||
|
|
||||||
# 4. Stop running app before replacing build artifacts
|
# 4. Stop running app before replacing build artifacts
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
53
package-lock.json
generated
53
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "harheimertc-website",
|
"name": "harheimertc-website",
|
||||||
"version": "1.8.7",
|
"version": "1.8.8",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "harheimertc-website",
|
"name": "harheimertc-website",
|
||||||
"version": "1.8.7",
|
"version": "1.8.8",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pinia/nuxt": "^0.11.2",
|
"@pinia/nuxt": "^0.11.2",
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
"pdf-lib": "^1.17.1",
|
"pdf-lib": "^1.17.1",
|
||||||
"pdf-parse": "^2.4.5",
|
"pdf-parse": "^2.4.5",
|
||||||
"pinia": "^3.0.3",
|
"pinia": "^3.0.3",
|
||||||
|
"playwright": "^1.62.1",
|
||||||
"quill": "2.0.2",
|
"quill": "2.0.2",
|
||||||
"sharp": "^0.35.3",
|
"sharp": "^0.35.3",
|
||||||
"vue": "^3.5.22"
|
"vue": "^3.5.22"
|
||||||
@@ -8527,6 +8528,50 @@
|
|||||||
"pathe": "^2.0.3"
|
"pathe": "^2.0.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/playwright": {
|
||||||
|
"version": "1.62.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.62.1.tgz",
|
||||||
|
"integrity": "sha512-0M+L3LAD8/nm554LOla9Ayx0j0tmFZ0FBcoQ7F1VuVHpM/XpiC8RcDzBQB8W5+hA8L22THxELzeF+2WcUzvcLg==",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"playwright-core": "1.62.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"playwright": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"fsevents": "2.3.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/playwright-core": {
|
||||||
|
"version": "1.62.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.62.1.tgz",
|
||||||
|
"integrity": "sha512-wPYSwEBJY9GHraISXqyqtx0na0LpO3XEX7jNDhntbex7tzUS7kLnZsOlFruFJB4Hi/rhDMjXGqHewDZ68nYZVw==",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bin": {
|
||||||
|
"playwright-core": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/playwright/node_modules/fsevents": {
|
||||||
|
"version": "2.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||||
|
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/portfinder": {
|
"node_modules/portfinder": {
|
||||||
"version": "1.0.38",
|
"version": "1.0.38",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
@@ -9225,7 +9270,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/qs": {
|
"node_modules/qs": {
|
||||||
"version": "6.15.3",
|
"version": "6.16.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz",
|
||||||
|
"integrity": "sha512-h6fhOIaRrID2CbEY2fqs+7t+UXZo+MLAnU5gRIq85uFtdiUPCdsApMlHhXogKVM4HM2DVbIjGNTTYH2OcmP1vA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
"pdf-lib": "^1.17.1",
|
"pdf-lib": "^1.17.1",
|
||||||
"pdf-parse": "^2.4.5",
|
"pdf-parse": "^2.4.5",
|
||||||
"pinia": "^3.0.3",
|
"pinia": "^3.0.3",
|
||||||
|
"playwright": "^1.62.1",
|
||||||
"quill": "2.0.2",
|
"quill": "2.0.2",
|
||||||
"sharp": "^0.35.3",
|
"sharp": "^0.35.3",
|
||||||
"vue": "^3.5.22"
|
"vue": "^3.5.22"
|
||||||
@@ -67,6 +68,7 @@
|
|||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"@peculiar/x509": "1.13.0",
|
"@peculiar/x509": "1.13.0",
|
||||||
"esbuild": "0.28.1"
|
"esbuild": "0.28.1",
|
||||||
|
"qs": "6.16.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,6 +201,20 @@
|
|||||||
</p>
|
</p>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
|
|
||||||
|
<NuxtLink
|
||||||
|
v-if="authStore.hasAnyRole('admin', 'vorstand')"
|
||||||
|
to="/cms/mytischtennis"
|
||||||
|
class="bg-white p-6 rounded-xl shadow-lg border border-gray-100 hover:shadow-xl transition-all group"
|
||||||
|
>
|
||||||
|
<div class="flex items-center mb-4">
|
||||||
|
<div class="w-12 h-12 bg-teal-100 rounded-lg flex items-center justify-center group-hover:bg-teal-600 transition-colors">
|
||||||
|
<RefreshCw :size="24" class="text-teal-600 group-hover:text-white" />
|
||||||
|
</div>
|
||||||
|
<h2 class="ml-4 text-xl font-semibold text-gray-900">myTischtennis</h2>
|
||||||
|
</div>
|
||||||
|
<p class="text-gray-600">Vereinszugang und TTR-Synchronisierung</p>
|
||||||
|
</NuxtLink>
|
||||||
|
|
||||||
<!-- Benutzerverwaltung (Admin ODER Vorstand) -->
|
<!-- Benutzerverwaltung (Admin ODER Vorstand) -->
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
v-if="authStore.hasAnyRole('admin', 'vorstand')"
|
v-if="authStore.hasAnyRole('admin', 'vorstand')"
|
||||||
@@ -249,7 +263,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { Newspaper, Calendar, Users, UserCog, Settings, Layout, Mail, ShieldAlert } from 'lucide-vue-next'
|
import { Newspaper, Calendar, Users, UserCog, Settings, Layout, Mail, ShieldAlert, RefreshCw } from 'lucide-vue-next'
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
|
|||||||
48
pages/cms/mytischtennis.vue
Normal file
48
pages/cms/mytischtennis.vue
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<template>
|
||||||
|
<div class="min-h-screen bg-gray-50 py-10">
|
||||||
|
<div class="max-w-2xl mx-auto px-4">
|
||||||
|
<h1 class="text-3xl font-display font-bold text-gray-900">myTischtennis-Verbindung</h1>
|
||||||
|
<p class="mt-2 text-gray-600">Vereinszugang für den geschützten Import aktueller TTR- und QTTR-Werte.</p>
|
||||||
|
<form class="mt-8 bg-white rounded-xl shadow-lg p-6 space-y-5" @submit.prevent="save">
|
||||||
|
<div class="rounded-lg bg-amber-50 border border-amber-200 p-4 text-sm text-amber-900">
|
||||||
|
Das Passwort wird verschlüsselt auf dem Server gespeichert und nie wieder angezeigt. Zugriff haben ausschließlich Admin und Vorstand.
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-gray-700 mb-1">myTischtennis-E-Mail</label>
|
||||||
|
<input v-model.trim="form.email" type="email" required autocomplete="username" class="w-full rounded-lg border border-gray-300 px-3 py-2">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-gray-700 mb-1">Passwort</label>
|
||||||
|
<input v-model="form.password" type="password" required autocomplete="current-password" class="w-full rounded-lg border border-gray-300 px-3 py-2">
|
||||||
|
</div>
|
||||||
|
<div class="grid sm:grid-cols-2 gap-4">
|
||||||
|
<label class="block text-sm font-medium text-gray-700">Verband<input v-model.trim="form.association" required class="mt-1 w-full rounded-lg border border-gray-300 px-3 py-2"></label>
|
||||||
|
<label class="block text-sm font-medium text-gray-700">Vereinsnummer<input v-model.trim="form.clubId" required class="mt-1 w-full rounded-lg border border-gray-300 px-3 py-2"></label>
|
||||||
|
</div>
|
||||||
|
<p v-if="status.configured" class="text-sm text-gray-600">Hinterlegt: {{ status.email }} · letzter erfolgreicher Abruf: {{ formattedLastImport }}</p>
|
||||||
|
<p v-if="status.lastImportError" class="rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-800">
|
||||||
|
Letzter Abruf fehlgeschlagen: {{ status.lastImportError }}
|
||||||
|
</p>
|
||||||
|
<p v-if="message" class="text-sm" :class="error ? 'text-red-700' : 'text-green-700'">{{ message }}</p>
|
||||||
|
<div class="flex gap-3 flex-wrap">
|
||||||
|
<button :disabled="busy" class="rounded-lg bg-primary-600 px-4 py-2 font-semibold text-white disabled:opacity-60">Zugang speichern</button>
|
||||||
|
<button type="button" :disabled="busy || !status.configured" class="rounded-lg border border-primary-600 px-4 py-2 font-semibold text-primary-700 disabled:opacity-60" @click="runImport">Jetzt abrufen</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, onMounted, reactive, ref } from 'vue'
|
||||||
|
definePageMeta({ middleware: 'auth' })
|
||||||
|
useHead({ title: 'myTischtennis-Verbindung – CMS' })
|
||||||
|
const form = reactive({ email: '', password: '', association: 'HeTTV', clubId: '43030' })
|
||||||
|
const status = ref({ configured: false })
|
||||||
|
const busy = ref(false); const message = ref(''); const error = ref(false)
|
||||||
|
const formattedLastImport = computed(() => status.value.lastSuccessfulImportAt ? new Intl.DateTimeFormat('de-DE', { dateStyle: 'medium', timeStyle: 'short' }).format(new Date(status.value.lastSuccessfulImportAt)) : 'noch nie')
|
||||||
|
async function load() { status.value = await $fetch('/api/cms/mytischtennis') }
|
||||||
|
async function save() { busy.value = true; message.value = ''; error.value = false; try { status.value = await $fetch('/api/cms/mytischtennis', { method: 'PUT', body: form }); form.password = ''; message.value = 'Zugang verschlüsselt gespeichert.' } catch { error.value = true; message.value = 'Zugang konnte nicht gespeichert werden.' } finally { busy.value = false } }
|
||||||
|
async function runImport() { busy.value = true; message.value = ''; error.value = false; try { const result = await $fetch('/api/cms/mytischtennis/import', { method: 'POST' }); message.value = `${result.rowCount} Werte wurden aktualisiert.`; await load() } catch (caught) { error.value = true; message.value = caught?.data?.message || 'Abruf fehlgeschlagen. Details stehen im Serverlog.'; await load().catch(() => {}) } finally { busy.value = false } }
|
||||||
|
onMounted(load)
|
||||||
|
</script>
|
||||||
@@ -3,18 +3,11 @@
|
|||||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 space-y-8">
|
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 space-y-8">
|
||||||
<div>
|
<div>
|
||||||
<h1 class="text-4xl sm:text-5xl font-display font-bold text-gray-900 mb-4">
|
<h1 class="text-4xl sm:text-5xl font-display font-bold text-gray-900 mb-4">
|
||||||
QTTR-Werte
|
TTR- und QTTR-Werte
|
||||||
</h1>
|
</h1>
|
||||||
<div class="w-24 h-1 bg-primary-600 mb-6" />
|
<div class="w-24 h-1 bg-primary-600 mb-6" />
|
||||||
<p class="text-lg text-gray-700 max-w-3xl">
|
<p class="text-lg text-gray-700 max-w-3xl">
|
||||||
Aus technischen Gründen sind nur die QTTR-Werte verfügbar. Für TTR bitte auf
|
Aktuelle TTR- und QTTR-Werte des Harheimer TC. Der Abruf erfolgt über die geschützte Vereinsverbindung.
|
||||||
<a
|
|
||||||
:href="externalUrl"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
class="text-primary-600 hover:text-primary-800 underline"
|
|
||||||
>myTischtennis</a>
|
|
||||||
wechseln.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -37,13 +30,13 @@
|
|||||||
v-if="pending"
|
v-if="pending"
|
||||||
class="py-12 text-center text-gray-500"
|
class="py-12 text-center text-gray-500"
|
||||||
>
|
>
|
||||||
Lade QTTR-Werte...
|
Lade TTR- und QTTR-Werte...
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-else-if="error"
|
v-else-if="error"
|
||||||
class="rounded-lg border border-red-200 bg-red-50 p-4 text-red-800"
|
class="rounded-lg border border-red-200 bg-red-50 p-4 text-red-800"
|
||||||
>
|
>
|
||||||
{{ error.statusMessage || error.message || 'QTTR-Werte konnten nicht geladen werden.' }}
|
{{ error.statusMessage || error.message || 'TTR- und QTTR-Werte konnten nicht geladen werden.' }}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-else
|
v-else
|
||||||
@@ -61,6 +54,9 @@
|
|||||||
<th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500">
|
<th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500">
|
||||||
Verein
|
Verein
|
||||||
</th>
|
</th>
|
||||||
|
<th class="px-4 py-3 text-right text-xs font-semibold uppercase tracking-wider text-gray-500">
|
||||||
|
TTR
|
||||||
|
</th>
|
||||||
<th class="px-4 py-3 text-right text-xs font-semibold uppercase tracking-wider text-gray-500">
|
<th class="px-4 py-3 text-right text-xs font-semibold uppercase tracking-wider text-gray-500">
|
||||||
QTTR
|
QTTR
|
||||||
</th>
|
</th>
|
||||||
@@ -83,6 +79,9 @@
|
|||||||
<td class="px-4 py-3 text-sm text-gray-700">
|
<td class="px-4 py-3 text-sm text-gray-700">
|
||||||
{{ row.clubName || 'Harheimer TC' }}
|
{{ row.clubName || 'Harheimer TC' }}
|
||||||
</td>
|
</td>
|
||||||
|
<td class="px-4 py-3 text-right text-lg font-semibold text-gray-900 tabular-nums">
|
||||||
|
{{ row.currentTtr ?? '–' }}
|
||||||
|
</td>
|
||||||
<td class="px-4 py-3 text-right text-lg font-semibold text-gray-900 tabular-nums">
|
<td class="px-4 py-3 text-right text-lg font-semibold text-gray-900 tabular-nums">
|
||||||
{{ row.currentQttr ?? '–' }}
|
{{ row.currentQttr ?? '–' }}
|
||||||
</td>
|
</td>
|
||||||
@@ -99,7 +98,6 @@
|
|||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
const externalUrl = 'https://www.mytischtennis.de/rankings/andro-rangliste?continent=all&country=Deutschland&all-players=on&as=DE.WE.R4.07&di=DE.WE.R4.07.04&area=DE.WE.R4.07.04.43&clubnr-search=Harheimer+TC&clubnr=43030&fednickname=HeTTV&gender=all¤t-ranking=yes&ttr-range=100%3B3000&birth-range=1926%3B2021'
|
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
middleware: 'auth',
|
middleware: 'auth',
|
||||||
@@ -126,7 +124,7 @@ function isMaleGender(value) {
|
|||||||
|
|
||||||
function isFemaleGender(value) {
|
function isFemaleGender(value) {
|
||||||
const gender = normalizeName(value)
|
const gender = normalizeName(value)
|
||||||
return gender.startsWith('w') || gender.includes('weib') || gender.includes('frau')
|
return gender.startsWith('w') || gender.includes('weib') || gender.includes('frau') || gender.includes('female')
|
||||||
}
|
}
|
||||||
|
|
||||||
function isOwnRow(playerName) {
|
function isOwnRow(playerName) {
|
||||||
@@ -180,6 +178,6 @@ function formatDate(value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useHead({
|
useHead({
|
||||||
title: 'QTTR-Werte - Harheimer TC'
|
title: 'TTR- und QTTR-Werte - Harheimer TC'
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
10
server/api/cms/mytischtennis.get.js
Normal file
10
server/api/cms/mytischtennis.get.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { getUserFromToken, hasAnyRole } from '../../utils/auth.js'
|
||||||
|
import { publicConnectionStatus, readMyTischtennisConnection } from '../../utils/mytischtennis-connection.js'
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const token = getCookie(event, 'auth_token') || getHeader(event, 'authorization')?.replace(/^Bearer\s+/i, '')
|
||||||
|
const user = token ? await getUserFromToken(token) : null
|
||||||
|
if (!user) throw createError({ statusCode: 401, statusMessage: 'Nicht authentifiziert' })
|
||||||
|
if (!hasAnyRole(user, 'admin', 'vorstand')) throw createError({ statusCode: 403, statusMessage: 'Keine Berechtigung' })
|
||||||
|
return publicConnectionStatus(await readMyTischtennisConnection())
|
||||||
|
})
|
||||||
17
server/api/cms/mytischtennis.put.js
Normal file
17
server/api/cms/mytischtennis.put.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { getUserFromToken, hasAnyRole } from '../../utils/auth.js'
|
||||||
|
import { readMyTischtennisConnection, saveMyTischtennisConnection, publicConnectionStatus } from '../../utils/mytischtennis-connection.js'
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const token = getCookie(event, 'auth_token') || getHeader(event, 'authorization')?.replace(/^Bearer\s+/i, '')
|
||||||
|
const user = token ? await getUserFromToken(token) : null
|
||||||
|
if (!user) throw createError({ statusCode: 401, statusMessage: 'Nicht authentifiziert' })
|
||||||
|
if (!hasAnyRole(user, 'admin', 'vorstand')) throw createError({ statusCode: 403, statusMessage: 'Keine Berechtigung' })
|
||||||
|
const body = await readBody(event)
|
||||||
|
if (!/^\S+@\S+\.\S+$/.test(String(body.email || '')) || String(body.password || '').length < 1) {
|
||||||
|
throw createError({ statusCode: 400, statusMessage: 'E-Mail und Passwort sind erforderlich.' })
|
||||||
|
}
|
||||||
|
const previous = await readMyTischtennisConnection()
|
||||||
|
const connection = { ...previous, email: body.email.trim(), password: body.password, association: String(body.association || 'HeTTV'), clubId: String(body.clubId || '43030') }
|
||||||
|
await saveMyTischtennisConnection(connection)
|
||||||
|
return publicConnectionStatus(connection)
|
||||||
|
})
|
||||||
24
server/api/cms/mytischtennis/import.post.js
Normal file
24
server/api/cms/mytischtennis/import.post.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { getUserFromToken, hasAnyRole } from '../../../utils/auth.js'
|
||||||
|
import { importQttrValues } from '../../../utils/qttr-import.js'
|
||||||
|
import { readMyTischtennisConnection, saveMyTischtennisConnection } from '../../../utils/mytischtennis-connection.js'
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const token = getCookie(event, 'auth_token') || getHeader(event, 'authorization')?.replace(/^Bearer\s+/i, '')
|
||||||
|
const user = token ? await getUserFromToken(token) : null
|
||||||
|
if (!user) throw createError({ statusCode: 401, statusMessage: 'Nicht authentifiziert' })
|
||||||
|
if (!hasAnyRole(user, 'admin', 'vorstand')) throw createError({ statusCode: 403, statusMessage: 'Keine Berechtigung' })
|
||||||
|
const connection = await readMyTischtennisConnection()
|
||||||
|
if (!connection) throw createError({ statusCode: 409, statusMessage: 'Keine myTischtennis-Verbindung eingerichtet.' })
|
||||||
|
try {
|
||||||
|
const result = await importQttrValues({ connection })
|
||||||
|
return { success: true, rowCount: result.rowCount, importedAt: result.importedAt }
|
||||||
|
} catch (error) {
|
||||||
|
const fullDetail = String(error.stack || error.message || error)
|
||||||
|
const detail = fullDetail.slice(0, 500)
|
||||||
|
// Vollständig nur ins serverseitige PM2-Log schreiben; im CMS wird der Fehler
|
||||||
|
// bewusst gekürzt gespeichert, damit Browser-/Systempfade nicht öffentlich werden.
|
||||||
|
console.error('[mytischtennis] TTR-Abruf fehlgeschlagen:', fullDetail)
|
||||||
|
await saveMyTischtennisConnection({ ...connection, lastImportError: detail })
|
||||||
|
throw createError({ statusCode: 502, message: 'TTR-Abruf fehlgeschlagen. Details stehen im Serverlog.' })
|
||||||
|
}
|
||||||
|
})
|
||||||
170
server/utils/mytischtennis-client.js
Normal file
170
server/utils/mytischtennis-client.js
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
import { chromium } from 'playwright'
|
||||||
|
|
||||||
|
const BASE_URL = 'https://www.mytischtennis.de'
|
||||||
|
const HEADERS = { 'accept-language': 'de-DE,de;q=0.9', 'user-agent': 'Harheimer-TC-Vereinsverwaltung/1.0' }
|
||||||
|
|
||||||
|
function findAuthCookie(headers) {
|
||||||
|
const raw = headers.getSetCookie?.() || (headers.get('set-cookie') ? [headers.get('set-cookie')] : [])
|
||||||
|
return raw.find(value => value.startsWith('sb-10-auth-token='))?.split(';')[0] || null
|
||||||
|
}
|
||||||
|
|
||||||
|
function findEntries(value) {
|
||||||
|
if (!value || typeof value !== 'object') return null
|
||||||
|
if (Array.isArray(value.entries)) return value.entries
|
||||||
|
for (const child of Object.values(value)) {
|
||||||
|
const result = findEntries(child)
|
||||||
|
if (result) return result
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loginDirect(email, password) {
|
||||||
|
const page = await fetch(`${BASE_URL}/login?next=%2F`, { headers: HEADERS })
|
||||||
|
const html = await page.text()
|
||||||
|
if (/captcha/i.test(html)) throw new Error('CAPTCHA_REQUIRED')
|
||||||
|
const xsrf = html.match(/name=["']xsrf["'][^>]*value=["']([^"']+)/i)?.[1]
|
||||||
|
const form = new URLSearchParams({ email, password, intent: 'login' })
|
||||||
|
if (xsrf) form.set('xsrf', xsrf)
|
||||||
|
const result = await fetch(`${BASE_URL}/login?next=%2F&_data=routes%2F_auth%2B%2Flogin`, {
|
||||||
|
method: 'POST', headers: { ...HEADERS, 'content-type': 'application/x-www-form-urlencoded' }, body: form, redirect: 'manual'
|
||||||
|
})
|
||||||
|
const cookie = findAuthCookie(result.headers)
|
||||||
|
if (!cookie) throw new Error('Direkter myTischtennis-Login fehlgeschlagen.')
|
||||||
|
return cookie
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loginWithBrowser(email, password) {
|
||||||
|
const browser = await chromium.launch({
|
||||||
|
headless: true,
|
||||||
|
args: ['--no-sandbox', '--disable-dev-shm-usage']
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
const page = await browser.newPage()
|
||||||
|
// Das myTT-CAPTCHA wird erst nach dem Laden der Seite erzeugt. Der Ablauf
|
||||||
|
// entspricht der erprobten Integration im Trainingstagebuch.
|
||||||
|
const acceptConsentDialog = async (waitMs = 0) => {
|
||||||
|
if (waitMs) await page.waitForTimeout(waitMs)
|
||||||
|
for (const selector of [
|
||||||
|
'#onetrust-accept-btn-handler', 'button:has-text("Alle akzeptieren")',
|
||||||
|
'button:has-text("Akzeptieren")', 'button:has-text("Einverstanden")',
|
||||||
|
'button:has-text("Zustimmen")', '[data-testid="accept-button"]', '.cmp-accept-all', '.accept-all-btn'
|
||||||
|
]) {
|
||||||
|
try {
|
||||||
|
const button = page.locator(selector).first()
|
||||||
|
if (await button.count()) { await button.click({ timeout: 2_500 }); await page.waitForTimeout(800); return true }
|
||||||
|
} catch { /* try next CMP selector */ }
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
await page.goto(BASE_URL, { waitUntil: 'domcontentloaded', timeout: 30_000 }).catch(() => {})
|
||||||
|
if (!await acceptConsentDialog()) await acceptConsentDialog(2_500)
|
||||||
|
await page.goto(`${BASE_URL}/login?next=%2F`, { waitUntil: 'domcontentloaded', timeout: 45_000 })
|
||||||
|
if (!await acceptConsentDialog()) await acceptConsentDialog(1_500)
|
||||||
|
await page.locator('input[name="email"]').fill(email)
|
||||||
|
await page.locator('input[name="password"]').fill(password)
|
||||||
|
|
||||||
|
// Exakt wie in trainingstagebuch: Das Widget wird nach dem DOM-Load
|
||||||
|
// nachgeladen; ein sofortiges count() würde es häufig übersehen.
|
||||||
|
await page.waitForSelector('private-captcha', { timeout: 8_000 }).catch(() => {})
|
||||||
|
const captchaHost = page.locator('private-captcha').first()
|
||||||
|
const hasCaptcha = await captchaHost.count() > 0
|
||||||
|
console.info('[mytischtennis] CAPTCHA widget detected:', hasCaptcha)
|
||||||
|
if (hasCaptcha) {
|
||||||
|
await page.waitForTimeout(1_200)
|
||||||
|
// Ein echter Playwright-Klick erzeugt im Gegensatz zu element.click() ein
|
||||||
|
// vertrauenswürdiges Pointer-Ereignis für das Widget.
|
||||||
|
await captchaHost.click({ timeout: 5_000, force: true }).catch(error => {
|
||||||
|
console.warn('[mytischtennis] CAPTCHA pointer click failed:', error.message)
|
||||||
|
})
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const host = document.querySelector('private-captcha')
|
||||||
|
const checkbox = host?.shadowRoot?.querySelector('#pc-checkbox')
|
||||||
|
if (!checkbox) return
|
||||||
|
checkbox.click()
|
||||||
|
checkbox.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
checkbox.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForFunction(() => {
|
||||||
|
const token = document.querySelector('input[name="captcha"]')?.value?.trim() || ''
|
||||||
|
const clicked = document.querySelector('input[name="captcha_clicked"]')?.value?.toLowerCase() || ''
|
||||||
|
return token.length > 80 && (clicked === 'true' || clicked === '1')
|
||||||
|
}, { timeout: 32_000 }).catch(() => {})
|
||||||
|
const captchaState = await page.evaluate(() => {
|
||||||
|
const host = document.querySelector('private-captcha')
|
||||||
|
const checkbox = host?.shadowRoot?.querySelector('#pc-checkbox')
|
||||||
|
const token = document.querySelector('input[name="captcha"]')?.value?.trim() || ''
|
||||||
|
return {
|
||||||
|
tokenLength: token.length,
|
||||||
|
clicked: document.querySelector('input[name="captcha_clicked"]')?.value || null,
|
||||||
|
shadowRoot: Boolean(host?.shadowRoot),
|
||||||
|
checkboxFound: Boolean(checkbox),
|
||||||
|
checkboxChecked: Boolean(checkbox?.checked),
|
||||||
|
widgetState: host?.getAttribute('data-state') || null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.info('[mytischtennis] CAPTCHA state after wait:', captchaState)
|
||||||
|
const captchaReady = captchaState.tokenLength > 80
|
||||||
|
if (!captchaReady) throw new Error('CAPTCHA konnte nicht automatisch gelöst werden.')
|
||||||
|
await page.waitForTimeout(2_500)
|
||||||
|
}
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const form = document.querySelector('form[action*="/login"]')
|
||||||
|
if (!form) return
|
||||||
|
let intent = form.querySelector('input[name="intent"]')
|
||||||
|
if (!intent) {
|
||||||
|
intent = document.createElement('input')
|
||||||
|
intent.setAttribute('type', 'hidden')
|
||||||
|
intent.setAttribute('name', 'intent')
|
||||||
|
form.appendChild(intent)
|
||||||
|
}
|
||||||
|
intent.setAttribute('value', 'login')
|
||||||
|
})
|
||||||
|
const submit = page.locator('button[type="submit"][name="intent"][value="login"]').first()
|
||||||
|
const genericSubmit = page.locator('button[type="submit"], input[type="submit"]').first()
|
||||||
|
if (await submit.count()) await submit.click({ noWaitAfter: true })
|
||||||
|
else if (await genericSubmit.count()) await genericSubmit.click({ noWaitAfter: true })
|
||||||
|
else await page.locator('form').evaluate(form => form.requestSubmit())
|
||||||
|
let cookie = null
|
||||||
|
let cookieNames = []
|
||||||
|
let loginPageText = ''
|
||||||
|
for (let attempt = 0; attempt < 40; attempt += 1) {
|
||||||
|
const cookies = await page.context().cookies()
|
||||||
|
cookieNames = cookies.map(item => item.name)
|
||||||
|
cookie = cookies.find(item => item.name === 'sb-10-auth-token' || /^sb-\d+-auth-token$/.test(item.name) || item.name.includes('auth-token'))
|
||||||
|
if (cookie) break
|
||||||
|
if (attempt % 4 === 0) {
|
||||||
|
loginPageText = await page.locator('body').innerText().catch(() => '')
|
||||||
|
}
|
||||||
|
await page.waitForTimeout(500)
|
||||||
|
}
|
||||||
|
if (!cookie) {
|
||||||
|
console.warn('[mytischtennis] Login after solved CAPTCHA did not create a session', {
|
||||||
|
url: page.url(), cookieNames, pageText: loginPageText.slice(0, 1_000)
|
||||||
|
})
|
||||||
|
throw new Error('myTischtennis-Login nach gelöstem CAPTCHA fehlgeschlagen.')
|
||||||
|
}
|
||||||
|
return `${cookie.name}=${cookie.value}`
|
||||||
|
} finally { await browser.close() }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchClubRankings(connection, currentRanking = 'yes') {
|
||||||
|
let cookie
|
||||||
|
try { cookie = await loginDirect(connection.email, connection.password) } catch (error) {
|
||||||
|
if (error.message !== 'CAPTCHA_REQUIRED') throw error
|
||||||
|
cookie = await loginWithBrowser(connection.email, connection.password)
|
||||||
|
}
|
||||||
|
const url = new URL('/rankings/andro-rangliste', BASE_URL)
|
||||||
|
url.search = new URLSearchParams({ 'all-players': 'on', clubnr: connection.clubId, fednickname: connection.association, 'current-ranking': currentRanking, 'results-per-page': '100', page: '0', _data: 'routes/$' })
|
||||||
|
console.info('[mytischtennis] Ranking request URL:', url.toString())
|
||||||
|
const response = await fetch(url, { headers: { ...HEADERS, cookie, accept: 'application/json', referer: `${BASE_URL}/` } })
|
||||||
|
if (!response.ok) throw new Error(`Ranglisten-Abruf fehlgeschlagen (HTTP ${response.status}).`)
|
||||||
|
const entries = findEntries(await response.json())
|
||||||
|
if (!entries) throw new Error('myTischtennis hat keine Ranglisten-Daten geliefert.')
|
||||||
|
console.info('[mytischtennis] Ranking response:', {
|
||||||
|
currentRanking,
|
||||||
|
entryCount: entries.length,
|
||||||
|
entryKeys: Object.keys(entries[0] || {})
|
||||||
|
})
|
||||||
|
return entries
|
||||||
|
}
|
||||||
44
server/utils/mytischtennis-connection.js
Normal file
44
server/utils/mytischtennis-connection.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import { promises as fs } from 'fs'
|
||||||
|
import { encryptObject, decryptObject } from './encryption.js'
|
||||||
|
import { getServerDataPath } from './paths.js'
|
||||||
|
|
||||||
|
const FILE = getServerDataPath('mytischtennis-connection.json')
|
||||||
|
|
||||||
|
function encryptionKey() {
|
||||||
|
const key = process.env.ENCRYPTION_KEY
|
||||||
|
if (!key) throw new Error('ENCRYPTION_KEY ist für die myTischtennis-Verbindung erforderlich.')
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function readMyTischtennisConnection() {
|
||||||
|
try {
|
||||||
|
const stored = JSON.parse(await fs.readFile(FILE, 'utf8'))
|
||||||
|
return decryptObject(stored.encrypted, encryptionKey())
|
||||||
|
} catch (error) {
|
||||||
|
if (error?.code === 'ENOENT') return null
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveMyTischtennisConnection(connection) {
|
||||||
|
const payload = {
|
||||||
|
version: 1,
|
||||||
|
encrypted: encryptObject(connection, encryptionKey())
|
||||||
|
}
|
||||||
|
await fs.mkdir(getServerDataPath(), { recursive: true })
|
||||||
|
await fs.writeFile(FILE, `${JSON.stringify(payload)}\n`, { encoding: 'utf8', mode: 0o600 })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function publicConnectionStatus(connection) {
|
||||||
|
if (!connection) return { configured: false }
|
||||||
|
const email = String(connection.email || '')
|
||||||
|
const [name, domain] = email.split('@')
|
||||||
|
return {
|
||||||
|
configured: true,
|
||||||
|
email: name ? `${name.slice(0, 2)}${'•'.repeat(Math.max(1, name.length - 2))}${domain ? `@${domain}` : ''}` : null,
|
||||||
|
association: connection.association || null,
|
||||||
|
clubId: connection.clubId || null,
|
||||||
|
lastSuccessfulImportAt: connection.lastSuccessfulImportAt || null,
|
||||||
|
lastImportError: connection.lastImportError || null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import { promises as fs } from 'fs'
|
import { promises as fs } from 'fs'
|
||||||
import { getServerDataPath } from './paths.js'
|
import { getServerDataPath } from './paths.js'
|
||||||
|
import { fetchClubRankings } from './mytischtennis-client.js'
|
||||||
|
import { readMyTischtennisConnection, saveMyTischtennisConnection } from './mytischtennis-connection.js'
|
||||||
|
|
||||||
const QTTR_URL = 'https://www.mytischtennis.de/rankings/andro-rangliste?continent=all&country=Deutschland&all-players=on&as=DE.WE.R4.07&di=DE.WE.R4.07.04&area=DE.WE.R4.07.04.43&clubnr-search=Harheimer+TC&clubnr=43030&fednickname=HeTTV&gender=all¤t-ranking=no&ttr-range=100%3B3000&birth-range=1926%3B2021'
|
const QTTR_URL = 'https://www.mytischtennis.de/rankings/andro-rangliste?continent=all&country=Deutschland&all-players=on&as=DE.WE.R4.07&di=DE.WE.R4.07.04&area=DE.WE.R4.07.04.43&clubnr-search=Harheimer+TC&clubnr=43030&fednickname=HeTTV&gender=all¤t-ranking=no&ttr-range=100%3B3000&birth-range=1926%3B2021'
|
||||||
const OUTPUT_FILE = getServerDataPath('qttr-values.json')
|
const OUTPUT_FILE = getServerDataPath('qttr-values.json')
|
||||||
@@ -59,8 +61,8 @@ function toNumberOrNull(value) {
|
|||||||
|
|
||||||
function normalizeGender(value) {
|
function normalizeGender(value) {
|
||||||
const normalized = String(value || '').trim().toLowerCase()
|
const normalized = String(value || '').trim().toLowerCase()
|
||||||
if (normalized === 'm' || normalized === 'männlich') return 'männlich'
|
if (['m', 'männlich', 'maennlich', 'male', 'man'].includes(normalized)) return 'männlich'
|
||||||
if (normalized === 'w' || normalized === 'weiblich') return 'weiblich'
|
if (['w', 'weiblich', 'female', 'woman', 'f'].includes(normalized)) return 'weiblich'
|
||||||
return normalized || null
|
return normalized || null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +162,9 @@ function deriveQttrFields(headers, cells) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function importQttrValues(options = {}) {
|
export async function importQttrValues(options = {}) {
|
||||||
|
const connection = options.connection ?? await readMyTischtennisConnection()
|
||||||
|
if (connection) return importAuthenticatedTtrValues(connection)
|
||||||
|
|
||||||
const url = options.url || QTTR_URL
|
const url = options.url || QTTR_URL
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -207,4 +212,42 @@ export async function importQttrValues(options = {}) {
|
|||||||
rowCount: parsedRows.length,
|
rowCount: parsedRows.length,
|
||||||
...payload
|
...payload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function importAuthenticatedTtrValues(connection) {
|
||||||
|
const [ttrEntries, qttrEntries] = await Promise.all([
|
||||||
|
fetchClubRankings(connection, 'yes'),
|
||||||
|
fetchClubRankings(connection, 'no')
|
||||||
|
])
|
||||||
|
const qttrByPlayer = new Map(qttrEntries.map(entry => [
|
||||||
|
String(entry.personId || `${entry.firstname || ''}|${entry.lastname || ''}`).toLowerCase(), entry
|
||||||
|
]))
|
||||||
|
const rows = ttrEntries.map((entry, index) => {
|
||||||
|
const key = String(entry.personId || `${entry.firstname || ''}|${entry.lastname || ''}`).toLowerCase()
|
||||||
|
const qttrEntry = qttrByPlayer.get(key)
|
||||||
|
return ({
|
||||||
|
rank: toNumberOrNull(entry.rank ?? entry.ranking ?? index + 1),
|
||||||
|
playerNumber: toNumberOrNull(entry.playernr ?? entry.player_number ?? entry.nuid),
|
||||||
|
gender: normalizeGender(entry.gender ?? entry.sex ?? entry.genderCode ?? entry.gender_code),
|
||||||
|
playerName: `${entry.firstname ?? entry.first_name ?? ''} ${entry.lastname ?? entry.last_name ?? ''}`.trim() || entry.name || null,
|
||||||
|
clubName: entry.clubname ?? entry.club_name ?? 'Harheimer TC',
|
||||||
|
currentQttr: toNumberOrNull(qttrEntry?.fedRank ?? qttrEntry?.qttr ?? entry.qttr),
|
||||||
|
currentTtr: toNumberOrNull(entry.fedRank ?? entry.ttr ?? entry.current_ttr),
|
||||||
|
previousQttr: null,
|
||||||
|
valuesByHeader: entry,
|
||||||
|
rawCells: []
|
||||||
|
})
|
||||||
|
}).filter(row => row.playerName && (row.currentTtr != null || row.currentQttr != null))
|
||||||
|
|
||||||
|
if (!rows.length) throw new Error('Keine verwertbaren TTR-Werte in der myTischtennis-Rangliste gefunden.')
|
||||||
|
const importedAt = new Date().toISOString()
|
||||||
|
const payload = {
|
||||||
|
format: 'harheimertc.qttr.v2', importedAt,
|
||||||
|
source: { type: 'mytischtennis-authenticated', association: connection.association, clubId: connection.clubId },
|
||||||
|
title: 'Aktuelle myTischtennis-Rangliste', headerCount: 0, rowCount: rows.length, headers: [], rows
|
||||||
|
}
|
||||||
|
await fs.mkdir(getServerDataPath(), { recursive: true })
|
||||||
|
await fs.writeFile(OUTPUT_FILE, `${JSON.stringify(payload, null, 2)}\n`, 'utf8')
|
||||||
|
await saveMyTischtennisConnection({ ...connection, lastSuccessfulImportAt: importedAt, lastImportError: null })
|
||||||
|
return { outputFile: OUTPUT_FILE, tableCount: 1, ...payload }
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user