Compare commits
8 Commits
b20cf0a9d2
...
beta
| Author | SHA1 | Date | |
|---|---|---|---|
| 52e3d680f7 | |||
| 00bccfa8b6 | |||
| aa3532dd83 | |||
| 4ec2351241 | |||
| 6480478167 | |||
| 3739e11016 | |||
| 132e02e06e | |||
| cc79685eaf |
11
.dockerignore
Normal file
11
.dockerignore
Normal file
@@ -0,0 +1,11 @@
|
||||
.git
|
||||
.env
|
||||
*.log
|
||||
data/*
|
||||
!data/branding/
|
||||
!data/branding/**
|
||||
frontend/node_modules/
|
||||
frontend/.next/
|
||||
backend/__pycache__/
|
||||
**/__pycache__/
|
||||
**/*.pyc
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,8 @@
|
||||
.env
|
||||
.venv/
|
||||
data/
|
||||
!data/branding/
|
||||
!data/branding/**
|
||||
backend/__pycache__/
|
||||
**/__pycache__/
|
||||
*.pyc
|
||||
|
||||
@@ -5,10 +5,11 @@ WORKDIR /app
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
COPY requirements.txt .
|
||||
COPY backend/requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY app ./app
|
||||
COPY backend/app ./app
|
||||
COPY data/branding /app/data/branding
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Any, Dict
|
||||
|
||||
from fastapi import APIRouter, HTTPException, UploadFile, File
|
||||
from fastapi.responses import FileResponse
|
||||
from PIL import Image
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
router = APIRouter(prefix="/branding", tags=["branding"])
|
||||
|
||||
@@ -23,8 +23,52 @@ def _resize_image(image: Image.Image, max_size: int = 300) -> Image.Image:
|
||||
return image
|
||||
|
||||
|
||||
def _load_font(size: int) -> ImageFont.ImageFont:
|
||||
candidates = [
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
||||
]
|
||||
for path in candidates:
|
||||
if os.path.exists(path):
|
||||
try:
|
||||
return ImageFont.truetype(path, size)
|
||||
except OSError:
|
||||
continue
|
||||
return ImageFont.load_default()
|
||||
|
||||
|
||||
def _ensure_default_branding() -> None:
|
||||
if os.path.exists(_LOGO_PATH) and os.path.exists(_FAVICON_PATH):
|
||||
return
|
||||
_ensure_branding_dir()
|
||||
if not os.path.exists(_LOGO_PATH):
|
||||
image = Image.new("RGBA", (300, 300), (12, 18, 28, 255))
|
||||
draw = ImageDraw.Draw(image)
|
||||
font = _load_font(160)
|
||||
text = "M"
|
||||
box = draw.textbbox((0, 0), text, font=font)
|
||||
text_w = box[2] - box[0]
|
||||
text_h = box[3] - box[1]
|
||||
draw.text(
|
||||
((300 - text_w) / 2, (300 - text_h) / 2 - 6),
|
||||
text,
|
||||
font=font,
|
||||
fill=(255, 255, 255, 255),
|
||||
)
|
||||
image.save(_LOGO_PATH, format="PNG")
|
||||
if not os.path.exists(_FAVICON_PATH):
|
||||
favicon = Image.open(_LOGO_PATH).copy()
|
||||
favicon.thumbnail((64, 64))
|
||||
try:
|
||||
favicon.save(_FAVICON_PATH, format="ICO", sizes=[(32, 32), (64, 64)])
|
||||
except OSError:
|
||||
favicon.save(_FAVICON_PATH, format="ICO")
|
||||
|
||||
|
||||
@router.get("/logo.png")
|
||||
async def branding_logo() -> FileResponse:
|
||||
if not os.path.exists(_LOGO_PATH):
|
||||
_ensure_default_branding()
|
||||
if not os.path.exists(_LOGO_PATH):
|
||||
raise HTTPException(status_code=404, detail="Logo not found")
|
||||
headers = {"Cache-Control": "public, max-age=300"}
|
||||
@@ -33,6 +77,8 @@ async def branding_logo() -> FileResponse:
|
||||
|
||||
@router.get("/favicon.ico")
|
||||
async def branding_favicon() -> FileResponse:
|
||||
if not os.path.exists(_FAVICON_PATH):
|
||||
_ensure_default_branding()
|
||||
if not os.path.exists(_FAVICON_PATH):
|
||||
raise HTTPException(status_code=404, detail="Favicon not found")
|
||||
headers = {"Cache-Control": "public, max-age=300"}
|
||||
|
||||
@@ -9,6 +9,7 @@ from datetime import datetime, timezone, timedelta
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
|
||||
from ..clients.jellyseerr import JellyseerrClient
|
||||
from ..clients.jellyfin import JellyfinClient
|
||||
from ..clients.qbittorrent import QBittorrentClient
|
||||
from ..clients.radarr import RadarrClient
|
||||
from ..clients.sonarr import SonarrClient
|
||||
@@ -1101,6 +1102,38 @@ async def recent_requests(
|
||||
allow_remote = mode == "always_js"
|
||||
allow_title_hydrate = mode == "prefer_cache"
|
||||
allow_artwork_hydrate = allow_remote or allow_title_hydrate
|
||||
jellyfin = JellyfinClient(runtime.jellyfin_base_url, runtime.jellyfin_api_key)
|
||||
jellyfin_cache: Dict[str, bool] = {}
|
||||
|
||||
async def _jellyfin_available(
|
||||
title_value: Optional[str], year_value: Optional[int], media_type_value: Optional[str]
|
||||
) -> bool:
|
||||
if not jellyfin.configured() or not title_value:
|
||||
return False
|
||||
cache_key = f"{media_type_value or ''}:{title_value.lower()}:{year_value or ''}"
|
||||
cached_value = jellyfin_cache.get(cache_key)
|
||||
if cached_value is not None:
|
||||
return cached_value
|
||||
types = ["Movie"] if media_type_value == "movie" else ["Series"]
|
||||
try:
|
||||
search = await jellyfin.search_items(title_value, types)
|
||||
except Exception:
|
||||
jellyfin_cache[cache_key] = False
|
||||
return False
|
||||
if isinstance(search, dict):
|
||||
items = search.get("Items") or search.get("items") or []
|
||||
for item in items:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
name = item.get("Name") or item.get("title")
|
||||
year = item.get("ProductionYear") or item.get("Year")
|
||||
if name and name.strip().lower() == title_value.strip().lower():
|
||||
if year_value and year and int(year) != int(year_value):
|
||||
continue
|
||||
jellyfin_cache[cache_key] = True
|
||||
return True
|
||||
jellyfin_cache[cache_key] = False
|
||||
return False
|
||||
results = []
|
||||
for row in rows:
|
||||
status = row.get("status")
|
||||
@@ -1192,6 +1225,11 @@ async def recent_requests(
|
||||
updated_at=payload.get("updated_at"),
|
||||
payload_json=json.dumps(details, ensure_ascii=True),
|
||||
)
|
||||
status_label = _status_label(status)
|
||||
if status_label == "Working on it":
|
||||
is_available = await _jellyfin_available(title, year, row.get("media_type"))
|
||||
if is_available:
|
||||
status_label = "Available"
|
||||
results.append(
|
||||
{
|
||||
"id": row.get("request_id"),
|
||||
@@ -1199,7 +1237,7 @@ async def recent_requests(
|
||||
"year": year,
|
||||
"type": row.get("media_type"),
|
||||
"status": status,
|
||||
"statusLabel": _status_label(status),
|
||||
"statusLabel": status_label,
|
||||
"mediaId": row.get("media_id"),
|
||||
"artwork": {
|
||||
"poster_url": _artwork_url(poster_path, "w185", cache_mode),
|
||||
|
||||
BIN
data/branding/favicon.ico
Normal file
BIN
data/branding/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
BIN
data/branding/logo.png
Normal file
BIN
data/branding/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
19
docker-compose.hub.yml
Normal file
19
docker-compose.hub.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
services:
|
||||
backend:
|
||||
image: rephl3xnz/magent-backend:latest
|
||||
env_file:
|
||||
- ./.env
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
|
||||
frontend:
|
||||
image: rephl3xnz/magent-frontend:latest
|
||||
environment:
|
||||
- NEXT_PUBLIC_API_BASE=/api
|
||||
- BACKEND_INTERNAL_URL=http://backend:8000
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- backend
|
||||
@@ -1,8 +1,8 @@
|
||||
services:
|
||||
backend:
|
||||
build:
|
||||
context: ./backend
|
||||
dockerfile: Dockerfile
|
||||
context: .
|
||||
dockerfile: backend/Dockerfile
|
||||
env_file:
|
||||
- ./.env
|
||||
ports:
|
||||
|
||||
@@ -8,6 +8,7 @@ COPY package.json ./
|
||||
RUN npm install
|
||||
|
||||
COPY app ./app
|
||||
COPY public ./public
|
||||
COPY next-env.d.ts ./next-env.d.ts
|
||||
COPY next.config.js ./next.config.js
|
||||
COPY tsconfig.json ./tsconfig.json
|
||||
@@ -22,6 +23,7 @@ ENV NEXT_TELEMETRY_DISABLED=1 \
|
||||
NODE_ENV=production
|
||||
|
||||
COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
COPY --from=builder /app/next.config.js ./next.config.js
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { getApiBase } from '../lib/auth'
|
||||
|
||||
const STORAGE_KEY = 'branding_version'
|
||||
|
||||
export default function BrandingFavicon() {
|
||||
useEffect(() => {
|
||||
const baseUrl = getApiBase()
|
||||
const version =
|
||||
(typeof window !== 'undefined' && window.localStorage.getItem(STORAGE_KEY)) || ''
|
||||
const versionSuffix = version ? `?v=${encodeURIComponent(version)}` : ''
|
||||
const href = `${baseUrl}/branding/favicon.ico${versionSuffix}`
|
||||
const href = '/api/branding/favicon.ico'
|
||||
let link = document.querySelector("link[rel='icon']") as HTMLLinkElement | null
|
||||
if (!link) {
|
||||
link = document.createElement('link')
|
||||
|
||||
@@ -1,36 +1,14 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { getApiBase } from '../lib/auth'
|
||||
|
||||
const STORAGE_KEY = 'branding_version'
|
||||
|
||||
type BrandingLogoProps = {
|
||||
className?: string
|
||||
alt?: string
|
||||
}
|
||||
|
||||
export default function BrandingLogo({ className, alt = 'Magent logo' }: BrandingLogoProps) {
|
||||
const [src, setSrc] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const baseUrl = getApiBase()
|
||||
const version =
|
||||
(typeof window !== 'undefined' && window.localStorage.getItem(STORAGE_KEY)) || ''
|
||||
const versionSuffix = version ? `?v=${encodeURIComponent(version)}` : ''
|
||||
setSrc(`${baseUrl}/branding/logo.png${versionSuffix}`)
|
||||
}, [])
|
||||
|
||||
if (!src) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<img
|
||||
className={className}
|
||||
src={src}
|
||||
src="/api/branding/logo.png"
|
||||
alt={alt}
|
||||
onError={() => setSrc(null)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ export default function UsersPage() {
|
||||
const [users, setUsers] = useState<AdminUser[]>([])
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [passwordInputs, setPasswordInputs] = useState<Record<string, string>>({})
|
||||
const [passwordStatus, setPasswordStatus] = useState<Record<string, string>>({})
|
||||
|
||||
const loadUsers = async () => {
|
||||
try {
|
||||
@@ -105,42 +103,6 @@ export default function UsersPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const updateUserPassword = async (username: string) => {
|
||||
const newPassword = passwordInputs[username] || ''
|
||||
if (!newPassword || newPassword.length < 8) {
|
||||
setPasswordStatus((current) => ({
|
||||
...current,
|
||||
[username]: 'Password must be at least 8 characters.',
|
||||
}))
|
||||
return
|
||||
}
|
||||
try {
|
||||
const baseUrl = getApiBase()
|
||||
const response = await authFetch(
|
||||
`${baseUrl}/admin/users/${encodeURIComponent(username)}/password`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password: newPassword }),
|
||||
}
|
||||
)
|
||||
if (!response.ok) {
|
||||
const text = await response.text()
|
||||
throw new Error(text || 'Update failed')
|
||||
}
|
||||
setPasswordInputs((current) => ({ ...current, [username]: '' }))
|
||||
setPasswordStatus((current) => ({
|
||||
...current,
|
||||
[username]: 'Password updated.',
|
||||
}))
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
setPasswordStatus((current) => ({
|
||||
...current,
|
||||
[username]: 'Could not update password.',
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!getToken()) {
|
||||
@@ -197,27 +159,6 @@ export default function UsersPage() {
|
||||
{user.isBlocked ? 'Allow access' : 'Block access'}
|
||||
</button>
|
||||
</div>
|
||||
{user.authProvider === 'local' && (
|
||||
<div className="user-actions">
|
||||
<input
|
||||
type="password"
|
||||
placeholder="New password (min 8 chars)"
|
||||
value={passwordInputs[user.username] || ''}
|
||||
onChange={(event) =>
|
||||
setPasswordInputs((current) => ({
|
||||
...current,
|
||||
[user.username]: event.target.value,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<button type="button" onClick={() => updateUserPassword(user.username)}>
|
||||
Set password
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{passwordStatus[user.username] && (
|
||||
<div className="meta">{passwordStatus[user.username]}</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
13
frontend/public/branding-icon.svg
Normal file
13
frontend/public/branding-icon.svg
Normal file
@@ -0,0 +1,13 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64">
|
||||
<defs>
|
||||
<linearGradient id="magentIconGlow" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0%" stop-color="#ff6b2b"/>
|
||||
<stop offset="100%" stop-color="#ffa84b"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="64" height="64" rx="14" fill="#0e1624"/>
|
||||
<path
|
||||
d="M18 50V14h8l6 11 6-11h8v36h-8V32l-6 10-6-10v18h-8z"
|
||||
fill="url(#magentIconGlow)"
|
||||
/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 457 B |
14
frontend/public/branding-logo.svg
Normal file
14
frontend/public/branding-logo.svg
Normal file
@@ -0,0 +1,14 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" viewBox="0 0 300 300">
|
||||
<defs>
|
||||
<linearGradient id="magentGlow" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0%" stop-color="#ff6b2b"/>
|
||||
<stop offset="100%" stop-color="#ffa84b"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="300" height="300" rx="56" fill="#0e1624"/>
|
||||
<rect x="24" y="24" width="252" height="252" rx="44" fill="#121d31"/>
|
||||
<path
|
||||
d="M80 220V80h28l42 70 42-70h28v140h-28v-88l-42 66-42-66v88H80z"
|
||||
fill="url(#magentGlow)"
|
||||
/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 537 B |
Reference in New Issue
Block a user