Compare commits

..

No commits in common. "868539cfad330a748e7478cdcab413eacead2cad" and "3178ccac2f01ff004adec4f7fb35c92d449406d0" have entirely different histories.

13 changed files with 259 additions and 441 deletions

View file

@ -15,7 +15,6 @@
"rundgelutschte",
"Törnplanung",
"Trintella",
"uuidv",
"vergenusswurzeln"
],
"python.testing.pytestArgs": [

View file

@ -1,7 +1,7 @@
from dotenv.main import load_dotenv
load_dotenv()
from .routers import users, comments, newsletters, health, reactions
from .routers import users, comments, newsletters, health
from backend.internal.database import create_db_and_tables
from fastapi import FastAPI
from fastapi_crons import Crons
@ -22,6 +22,5 @@ def on_startup():
app.include_router(users.router)
app.include_router(comments.router)
app.include_router(reactions.router)
app.include_router(newsletters.router)
app.include_router(health.router)

View file

@ -3,17 +3,3 @@
#Reference: https://isaacfei.com/posts/simple-like-system/
from sqlmodel import UUID
import uuid
from sqlmodel import table
from dataclasses import dataclass
from sqlmodel import Field
from sqlmodel import SQLModel
class BaseReaction(SQLModel):
pass
@dataclass
class Reaction(BaseReaction, table=True):
slug: str = Field(primary_key=True)
browser_id: str = Field(primary_key=True)

View file

@ -1,6 +1,6 @@
from fastapi import APIRouter
router = APIRouter(tags=["health"])
router = APIRouter()
@router.get("/health", include_in_schema=False)

View file

@ -23,7 +23,6 @@ router = APIRouter(
@router.post(
path="/approve",
tags=["newsletter"],
status_code=201
)
def approve_newsletter(secret: str = Form(), session: Session = Depends(get_session)):

View file

@ -1,50 +1,5 @@
from os import stat
from sqlmodel import select
from starlette.status import HTTP_400_BAD_REQUEST
from fastapi import HTTPException
from backend.models.reaction import Reaction
from backend.internal.database import get_session
from fastapi import Depends
from sqlmodel import Session
from fastapi import APIRouter
router = APIRouter(
prefix="/reactions",
tags=["reactions"]
)
@router.post("", status_code=201)
def create_reaction(reaction: Reaction, session: Session = Depends(get_session)):
print(reaction)
try:
session.add(reaction)
session.commit()
except Exception as e:
print(e)
session.rollback()
raise HTTPException(HTTP_400_BAD_REQUEST)
@router.get("/{slug}", status_code=200)
def get_reaction_count_for_post(slug: str, session: Session = Depends(get_session))-> int:
reactions = session.exec(select(Reaction).where(Reaction.slug == slug)).all()
print(reactions)
return len(reactions)
@router.get("/", status_code=200)
def have_i_reacted(slug:str, browser_id: str, session: Session = Depends(get_session)) -> bool:
result = session.exec(select(Reaction).where(Reaction.slug == slug, Reaction.browser_id == browser_id)).one_or_none()
if (result): return True
else: return False
@router.delete("", status_code=200)
def delete_reaction(reaction: Reaction, session: Session = Depends(get_session)) :
db_reaction = session.exec(select(Reaction).where(Reaction.slug == reaction.slug, Reaction.browser_id == reaction.browser_id)).one_or_none()
try:
session.delete(db_reaction)
session.commit()
except Exception as e:
print(e)
session.rollback()
raise HTTPException(HTTP_400_BAD_REQUEST)
# addReaction
# delete Reaction
# get Reactions by slug

View file

@ -26,7 +26,7 @@ from fastapi_limiter.depends import RateLimiter
router = APIRouter(
prefix="/users",
tags=["users"],
dependencies=[],
responses={404: {"description": "Not found"}},
)
@ -73,7 +73,7 @@ def register_user(new_user: NewUser, session: Session = Depends(get_session)):
@router.post(
path="/login",
status_code=200,
status_code=201,
dependencies=[Depends(RateLimiter(limiter=Limiter(Rate(3, Duration.SECOND * 30))))]
)
def login(user_code: str = Form(), session: Session = Depends(get_session)) -> str:
@ -94,18 +94,18 @@ def forgot_user_code(email: str = Form(), session: Session = Depends(get_session
pass # TODO: send Mail
@router.get(path="/me", status_code=200)
@router.get(path="/me", status_code=201)
def get_current_user_info(current_user: User = Depends(get_current_user)) -> UserInfo:
return UserInfo.model_validate(current_user)
@router.delete(path="/me", status_code=200)
@router.delete(path="/me", status_code=201)
def delete(current_user: User = Depends(get_current_user), session: Session = Depends(get_session)) :
session.delete(current_user)
session.commit()
@router.put(path="/me/subscription", status_code=200)
@router.put(path="/me/subscription", status_code=201)
def change_subscription(
subscription: bool = Form(),
current_user: User = Depends(get_current_user),

506
blog/package-lock.json generated
View file

@ -10,11 +10,9 @@
"@astrojs/mdx": "^7.0.8",
"@astrojs/preact": "^6.0.5",
"@astrojs/rss": "^4.0.19",
"@types/uuid": "^10.0.0",
"astro": "^7.2.2",
"jwt-decode": "^4.0.0",
"preact": "^10.29.8",
"uuid": "^14.0.2"
"preact": "^10.29.8"
},
"devDependencies": {
"@types/jsonwebtoken": "^9.0.10"
@ -2221,12 +2219,6 @@
"integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==",
"license": "MIT"
},
"node_modules/@types/uuid": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz",
"integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==",
"license": "MIT"
},
"node_modules/@ungap/structured-clone": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.3.3.tgz",
@ -6520,271 +6512,261 @@
"engines": {
"node": ">=18.12.0"
},
"node_modules/uuid": {
"version": "14.0.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-14.0.2.tgz",
"integrity": "sha512-xZe/16rV4aa+HGSOCiY2YeLT1OybRLrrkL/Rqaq7p7GMVXjFh+6wN4oMYgjFmnSnhY8t6Xpdl2l9qmnHYuMHwQ==",
"funding": [
"https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan"
],
"license": "MIT",
"bin": {
"uuid": "dist-node/bin/uuid"
}
"funding": {
"url": "https://github.com/sponsors/sxzz"
}
},
"node_modules/vfile": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz",
"integrity": "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==",
"license": "MIT",
"dependencies": {
"@types/unist": "^3.0.0",
"vfile-message": "^4.0.0"
},
"node_modules/vfile": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz",
"integrity": "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==",
"license": "MIT",
"dependencies": {
"@types/unist": "^3.0.0",
"vfile-message": "^4.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
}
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
}
},
"node_modules/vfile-location": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/vfile-location/-/vfile-location-5.0.3.tgz",
"integrity": "sha512-5yXvWDEgqeiYiBe1lbxYF7UMAIm/IcopxMHrMQDq3nvKcjPKIhZklUKL+AE7J7uApI4kwe2snsK+eI6UTj9EHg==",
"license": "MIT",
"dependencies": {
"@types/unist": "^3.0.0",
"vfile": "^6.0.0"
},
"node_modules/vfile-location": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/vfile-location/-/vfile-location-5.0.3.tgz",
"integrity": "sha512-5yXvWDEgqeiYiBe1lbxYF7UMAIm/IcopxMHrMQDq3nvKcjPKIhZklUKL+AE7J7uApI4kwe2snsK+eI6UTj9EHg==",
"license": "MIT",
"dependencies": {
"@types/unist": "^3.0.0",
"vfile": "^6.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
}
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
}
},
"node_modules/vfile-message": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-4.0.3.tgz",
"integrity": "sha512-QTHzsGd1EhbZs4AsQ20JX1rC3cOlt/IWJruk893DfLRr57lcnOeMaWG4K0JrRta4mIJZKth2Au3mM3u03/JWKw==",
"license": "MIT",
"dependencies": {
"@types/unist": "^3.0.0",
"unist-util-stringify-position": "^4.0.0"
},
"node_modules/vfile-message": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-4.0.3.tgz",
"integrity": "sha512-QTHzsGd1EhbZs4AsQ20JX1rC3cOlt/IWJruk893DfLRr57lcnOeMaWG4K0JrRta4mIJZKth2Au3mM3u03/JWKw==",
"license": "MIT",
"dependencies": {
"@types/unist": "^3.0.0",
"unist-util-stringify-position": "^4.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
}
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
}
},
"node_modules/vite": {
"version": "8.3.5",
"resolved": "https://registry.npmjs.org/vite/-/vite-8.3.5.tgz",
"integrity": "sha512-z1YpjieJ9g0ebTmQpLBv/oq9E3F9EIlOe+7LahW8SrE3LTiG3udBRUXQOlYXP9b+IC2q2phHeVxj9xGlw34OEQ==",
"license": "MIT",
"dependencies": {
"lightningcss": "^1.33.0",
"picomatch": "^4.0.7",
"postcss": "^8.5.30",
"rolldown": "~1.2.14",
"tinyglobby": "^0.2.17"
},
"node_modules/vite": {
"version": "8.3.5",
"resolved": "https://registry.npmjs.org/vite/-/vite-8.3.5.tgz",
"integrity": "sha512-z1YpjieJ9g0ebTmQpLBv/oq9E3F9EIlOe+7LahW8SrE3LTiG3udBRUXQOlYXP9b+IC2q2phHeVxj9xGlw34OEQ==",
"license": "MIT",
"dependencies": {
"lightningcss": "^1.33.0",
"picomatch": "^4.0.7",
"postcss": "^8.5.30",
"rolldown": "~1.2.14",
"tinyglobby": "^0.2.17"
},
"bin": {
"vite": "bin/vite.js"
},
"engines": {
"node": "^20.19.0 || >=22.12.0"
},
"funding": {
"url": "https://github.com/vitejs/vite?sponsor=1"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
},
"peerDependencies": {
"@types/node": "^20.19.0 || >=22.12.0",
"@vitejs/devtools": "^0.7.1 || ^0.8.0",
"esbuild": "^0.27.0 || ^0.28.0",
"jiti": ">=1.21.0",
"less": "^4.0.0",
"sass": "^1.70.0",
"sass-embedded": "^1.70.0",
"stylus": ">=0.54.8",
"sugarss": "^5.0.0",
"terser": "^5.16.0",
"tsx": "^4.8.1",
"yaml": "^2.4.2"
},
"peerDependenciesMeta": {
"@types/node": {
"optional": true
},
"@vitejs/devtools": {
"optional": true
},
"esbuild": {
"optional": true
},
"jiti": {
"optional": true
},
"less": {
"optional": true
},
"sass": {
"optional": true
},
"sass-embedded": {
"optional": true
},
"stylus": {
"optional": true
},
"sugarss": {
"optional": true
},
"terser": {
"optional": true
},
"tsx": {
"optional": true
},
"yaml": {
"optional": true
}
}
"bin": {
"vite": "bin/vite.js"
},
"node_modules/vite-prerender-plugin": {
"version": "0.5.13",
"resolved": "https://registry.npmjs.org/vite-prerender-plugin/-/vite-prerender-plugin-0.5.13.tgz",
"integrity": "sha512-IKSpYkzDBsKAxa05naRbj7GvNVMSdww/Z/E89oO3xndz+gWnOBOKOAbEXv7qDhktY/j3vHgJmoV1pPzqU2tx9g==",
"license": "MIT",
"dependencies": {
"kolorist": "^1.8.0",
"magic-string": "0.x >= 0.26.0",
"node-html-parser": "^6.1.12",
"simple-code-frame": "^1.3.0",
"source-map": "^0.7.4",
"stack-trace": "^1.0.0-pre2"
},
"peerDependencies": {
"vite": "5.x || 6.x || 7.x || 8.x"
}
"engines": {
"node": "^20.19.0 || >=22.12.0"
},
"node_modules/vitefu": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/vitefu/-/vitefu-1.1.3.tgz",
"integrity": "sha512-ub4okH7Z5KLjb6hDyjqrGXqWtWvoYdU3IGm/NorpgHncKoLTCfRIbvlhBm7r0YstIaQRYlp4yEbFqDcKSzXSSg==",
"license": "MIT",
"workspaces": [
"tests/deps/*",
"tests/projects/*",
"tests/projects/workspace/packages/*"
],
"peerDependencies": {
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
},
"peerDependenciesMeta": {
"vite": {
"optional": true
}
}
"funding": {
"url": "https://github.com/vitejs/vite?sponsor=1"
},
"node_modules/web-namespaces": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/web-namespaces/-/web-namespaces-2.0.1.tgz",
"integrity": "sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==",
"license": "MIT",
"funding": {
"optionalDependencies": {
"fsevents": "~2.3.3"
},
"peerDependencies": {
"@types/node": "^20.19.0 || >=22.12.0",
"@vitejs/devtools": "^0.7.1 || ^0.8.0",
"esbuild": "^0.27.0 || ^0.28.0",
"jiti": ">=1.21.0",
"less": "^4.0.0",
"sass": "^1.70.0",
"sass-embedded": "^1.70.0",
"stylus": ">=0.54.8",
"sugarss": "^5.0.0",
"terser": "^5.16.0",
"tsx": "^4.8.1",
"yaml": "^2.4.2"
},
"peerDependenciesMeta": {
"@types/node": {
"optional": true
},
"@vitejs/devtools": {
"optional": true
},
"esbuild": {
"optional": true
},
"jiti": {
"optional": true
},
"less": {
"optional": true
},
"sass": {
"optional": true
},
"sass-embedded": {
"optional": true
},
"stylus": {
"optional": true
},
"sugarss": {
"optional": true
},
"terser": {
"optional": true
},
"tsx": {
"optional": true
},
"yaml": {
"optional": true
}
}
},
"node_modules/vite-prerender-plugin": {
"version": "0.5.13",
"resolved": "https://registry.npmjs.org/vite-prerender-plugin/-/vite-prerender-plugin-0.5.13.tgz",
"integrity": "sha512-IKSpYkzDBsKAxa05naRbj7GvNVMSdww/Z/E89oO3xndz+gWnOBOKOAbEXv7qDhktY/j3vHgJmoV1pPzqU2tx9g==",
"license": "MIT",
"dependencies": {
"kolorist": "^1.8.0",
"magic-string": "0.x >= 0.26.0",
"node-html-parser": "^6.1.12",
"simple-code-frame": "^1.3.0",
"source-map": "^0.7.4",
"stack-trace": "^1.0.0-pre2"
},
"peerDependencies": {
"vite": "5.x || 6.x || 7.x || 8.x"
}
},
"node_modules/vitefu": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/vitefu/-/vitefu-1.1.3.tgz",
"integrity": "sha512-ub4okH7Z5KLjb6hDyjqrGXqWtWvoYdU3IGm/NorpgHncKoLTCfRIbvlhBm7r0YstIaQRYlp4yEbFqDcKSzXSSg==",
"license": "MIT",
"workspaces": [
"tests/deps/*",
"tests/projects/*",
"tests/projects/workspace/packages/*"
],
"peerDependencies": {
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
},
"peerDependenciesMeta": {
"vite": {
"optional": true
}
}
},
"node_modules/web-namespaces": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/web-namespaces/-/web-namespaces-2.0.1.tgz",
"integrity": "sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==",
"license": "MIT",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/wooorm"
}
},
"node_modules/xml-naming": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/xml-naming/-/xml-naming-0.1.0.tgz",
"integrity": "sha512-k8KO9hrMyNk6tUWqUfkTEZbezRRpONVOzUTnc97VnCvyj6Tf9lyUR9EDAIeiVLv56jsMcoXEwjW8Kv5yPY52lw==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/wooorm"
"url": "https://github.com/sponsors/NaturalIntelligence"
}
],
"license": "MIT",
"engines": {
"node": ">=16.0.0"
}
},
"node_modules/xxhash-wasm": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/xxhash-wasm/-/xxhash-wasm-1.1.0.tgz",
"integrity": "sha512-147y/6YNh+tlp6nd/2pWq38i9h6mz/EuQ6njIrmW8D1BS5nCqs0P6DG+m6zTGnNz5I+uhZ0SHxBs9BsPrwcKDA==",
"license": "MIT"
},
"node_modules/yallist": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
"license": "ISC"
},
"node_modules/yaml": {
"version": "2.9.1",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz",
"integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==",
"license": "ISC",
"bin": {
"yaml": "bin.mjs"
},
"node_modules/xml-naming": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/xml-naming/-/xml-naming-0.1.0.tgz",
"integrity": "sha512-k8KO9hrMyNk6tUWqUfkTEZbezRRpONVOzUTnc97VnCvyj6Tf9lyUR9EDAIeiVLv56jsMcoXEwjW8Kv5yPY52lw==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/NaturalIntelligence"
}
],
"license": "MIT",
"engines": {
"node": ">=16.0.0"
}
"engines": {
"node": ">= 14.6"
},
"node_modules/xxhash-wasm": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/xxhash-wasm/-/xxhash-wasm-1.1.0.tgz",
"integrity": "sha512-147y/6YNh+tlp6nd/2pWq38i9h6mz/EuQ6njIrmW8D1BS5nCqs0P6DG+m6zTGnNz5I+uhZ0SHxBs9BsPrwcKDA==",
"license": "MIT"
"funding": {
"url": "https://github.com/sponsors/eemeli"
}
},
"node_modules/yargs-parser": {
"version": "22.0.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-22.0.0.tgz",
"integrity": "sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw==",
"license": "ISC",
"engines": {
"node": "^20.19.0 || ^22.12.0 || >=23"
}
},
"node_modules/yocto-queue": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.2.tgz",
"integrity": "sha512-4LCcse/U2MHZ63HAJVE+v71o7yOdIe4cZ70Wpf8D/IyjDKYQLV5GD46B+hSTjJsvV5PztjvHoU580EftxjDZFQ==",
"license": "MIT",
"engines": {
"node": ">=12.20"
},
"node_modules/yallist": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
"license": "ISC"
},
"node_modules/yaml": {
"version": "2.9.1",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz",
"integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==",
"license": "ISC",
"bin": {
"yaml": "bin.mjs"
},
"engines": {
"node": ">= 14.6"
},
"funding": {
"url": "https://github.com/sponsors/eemeli"
}
},
"node_modules/yargs-parser": {
"version": "22.0.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-22.0.0.tgz",
"integrity": "sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw==",
"license": "ISC",
"engines": {
"node": "^20.19.0 || ^22.12.0 || >=23"
}
},
"node_modules/yocto-queue": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.2.tgz",
"integrity": "sha512-4LCcse/U2MHZ63HAJVE+v71o7yOdIe4cZ70Wpf8D/IyjDKYQLV5GD46B+hSTjJsvV5PztjvHoU580EftxjDZFQ==",
"license": "MIT",
"engines": {
"node": ">=12.20"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/zimmerframe": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/zimmerframe/-/zimmerframe-1.1.4.tgz",
"integrity": "sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ==",
"license": "MIT"
},
"node_modules/zod": {
"version": "4.6.7",
"resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz",
"integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
},
"node_modules/zwitch": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz",
"integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==",
"license": "MIT",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/wooorm"
}
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/zimmerframe": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/zimmerframe/-/zimmerframe-1.1.4.tgz",
"integrity": "sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ==",
"license": "MIT"
},
"node_modules/zod": {
"version": "4.6.7",
"resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz",
"integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
},
"node_modules/zwitch": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz",
"integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==",
"license": "MIT",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/wooorm"
}
}
}

View file

@ -15,11 +15,9 @@
"@astrojs/mdx": "^7.0.8",
"@astrojs/preact": "^6.0.5",
"@astrojs/rss": "^4.0.19",
"@types/uuid": "^10.0.0",
"astro": "^7.2.2",
"jwt-decode": "^4.0.0",
"preact": "^10.29.8",
"uuid": "^14.0.2"
"preact": "^10.29.8"
},
"devDependencies": {
"@types/jsonwebtoken": "^9.0.10"

View file

@ -1,67 +0,0 @@
import { useEffect, useState } from "preact/hooks"
import { api, BROWSER_ID, type Reaction } from "../lib/api"
import { v7 as uuidv7 } from 'uuid';
export default function Reaction({ slug }: { slug: string }) {
const [reaction, setReaction] = useState<Reaction>({ slug: slug, browser_id: "" })
const [reactionCount, setReactionCount] = useState(0)
const [haveReacted, setHaveReacted] = useState(false)
useEffect(() => {
let browserId = localStorage.getItem(BROWSER_ID)
if (!browserId) {
browserId = uuidv7()
localStorage.setItem(BROWSER_ID, browserId)
}
api.haveIReacted({ ...reaction, browser_id: browserId }).then((response: boolean) => {
setHaveReacted(response)
})
api.reactionCount(slug).then((count) => {
setReactionCount(count)
})
setReaction(prev => ({ ...prev, browser_id: browserId }))
}, [])
const handleReaction = () => {
let hasError = false
if (!haveReacted) {
try { api.createReaction(reaction) }
catch (e) { hasError = true }
finally {
if (!hasError) {
setHaveReacted(true)
setReactionCount(prev => prev + 1)
}
}
} else {
try { api.deleteReaction(reaction) }
catch (e) { hasError = true }
finally {
if (!hasError) {
setHaveReacted(false)
setReactionCount(prev => prev - 1)
}
}
}
}
return (
<button onClick={handleReaction}
style="
font-size: 1rem;
width: 100%;
padding:8px;
font-family:Arial, Helvetica, sans-serif;
">
{haveReacted ? "♥ Yeah!" : "Hattest du Spaß beim Lesen?"} {reactionCount}
</button>
)
}

View file

@ -1,9 +1,10 @@
import { useEffect, useState } from 'preact/hooks';
import { api, type User } from '../lib/api';
import React from 'preact/compat';
import { navigateBack, isEmailValid } from './Util';
export default function RegisterForm() {
const [user, setUser] = useState<User>({ 'email': '', 'name': '', 'subscription': true });
const [user, setUser] = React.useState<User>({ 'email': '', 'name': '', 'subscription': true });
const [error, setError] = useState('');
const handleRegistration = async () => {

View file

@ -5,7 +5,6 @@ import Main from "./Main.astro";
import { formatLocalizedDateString } from "../lib/formatDate";
import type { PostData } from "../content.config";
import NavBack from "../islands/NavBack";
import Reaction from "../islands/Reaction";
interface Props {
postData: PostData;
@ -35,9 +34,6 @@ const localeDate = formatLocalizedDateString(postData.date);
</div>
<article class="markdown-content">
<slot />
<div id="react">
<Reaction slug={postData.slug} client:load />
</div>
<NavBack client:load />
<p class="disclaimer">
Disclaimer: Dieser Artikel ist ausschließlich privat und wird nicht

View file

@ -1,20 +1,12 @@
import { v7 as uuidv7, type UUIDTypes } from 'uuid';
export interface User {
email: string;
name: string;
subscription: boolean;
}
export interface Reaction {
slug: string,
browser_id: UUIDTypes
}
const API_BASE = import.meta.env.PUBLIC_API_URL;
export const AUTH_TOKEN_KEY = 'authToken'
export const USER_KEY = 'user'
export const BROWSER_ID = 'browser_id'
@ -99,28 +91,6 @@ class BlauwasserAPI {
body: formData
})
}
async createReaction(reaction: Reaction): Promise<void> {
return await this.fetchAPI('/reactions', {
method: 'POST',
body: JSON.stringify(reaction)
})
}
async deleteReaction(reaction: Reaction): Promise<void> {
return await this.fetchAPI('/reactions', {
method: 'DELETE',
body: JSON.stringify(reaction)
})
}
async reactionCount(slug: string): Promise<number> {
return await this.fetchAPI(`/reactions/${slug}`, { method: 'GET' })
}
async haveIReacted(reaction: Reaction): Promise<boolean> {
return await this.fetchAPI(`/reactions/?slug=${reaction.slug}&browser_id=${reaction.browser_id}`, {method: 'GET'})
}
}