Compare commits
64 Commits
dev-monito
...
dev-stream
| Author | SHA1 | Date | |
|---|---|---|---|
| db19d28ae0 | |||
| a9c6abe06b | |||
| 764fef37e5 | |||
| 565481aa5a | |||
| 64b7d4c963 | |||
| 9eb7079ea6 | |||
| bd92480958 | |||
| 079a7e2cb5 | |||
| 295f68cb92 | |||
| a2a1154a22 | |||
| 3074b2d5f1 | |||
| 4638f3765a | |||
| 70189b95e1 | |||
| c47b1fc23f | |||
| f39e307bc4 | |||
| 3c965aa1ec | |||
| bd4ce76177 | |||
| fd0853d6f0 | |||
| 53ad80c90b | |||
| fb47cf9d6b | |||
| eac586d946 | |||
| ae0e416cdd | |||
| a64ac6b2cb | |||
| 1881247bf2 | |||
| 0337d7530a | |||
| 9b9240c35b | |||
| a568cb7c86 | |||
| daafeb79b7 | |||
| bc8c214c99 | |||
| d5f0098280 | |||
| 4cb9fd0810 | |||
| 7bc8720377 | |||
| cc4942a537 | |||
| c4f416af37 | |||
| 2c31485964 | |||
| 5d5d66bd79 | |||
| ce6fda257b | |||
| 7afc845343 | |||
| 546039aa43 | |||
| e6196ce078 | |||
| eecd5444a6 | |||
| 74506f6928 | |||
| 845a67bdd8 | |||
| 651697640c | |||
| dd48cc542f | |||
| 6c0e42d291 | |||
| e230913c89 | |||
| 8967d407cb | |||
| 217a667df2 | |||
| 4653feb123 | |||
| 6ad10a585d | |||
| eed2e70d21 | |||
| eded5a2fc8 | |||
| 8428fc6cf6 | |||
| 888a030680 | |||
| a628d85ef2 | |||
| afb62645f6 | |||
| 8aba35fee1 | |||
| 6817bd8c80 | |||
| 854177a121 | |||
| ddb71b3bb0 | |||
| 35a3e48ac9 | |||
| 6e55195e6f | |||
| e325687af5 |
12
.env
@@ -15,7 +15,7 @@
|
||||
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
|
||||
|
||||
###> symfony/framework-bundle ###
|
||||
APP_ENV=dev
|
||||
APP_ENV=prod
|
||||
APP_SECRET=
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
@@ -26,12 +26,18 @@ APP_SECRET=
|
||||
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
|
||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
|
||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
||||
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
||||
###< doctrine/doctrine-bundle ###
|
||||
# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
||||
|
||||
###< doctrine/doctrine-bundle ###
|
||||
MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!"
|
||||
###> symfony/messenger ###
|
||||
# Choose one of the transports below
|
||||
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
|
||||
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
|
||||
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
|
||||
###< symfony/messenger ###
|
||||
|
||||
REDIS_HOST=redis://redis
|
||||
|
||||
MOVIES_PATH=/var/download/movies
|
||||
TVSHOWS_PATH=/var/download/tvshows
|
||||
|
||||
8
.env.dev
@@ -1,8 +0,0 @@
|
||||
DATABASE_URL="mysql://root:password@database:3306/app?serverVersion=10.6.19.2-MariaDB&charset=utf8mb4"
|
||||
APP_SECRET=70169beadfbc8101c393cbfbba27a313
|
||||
|
||||
DOWNLOAD_DIR=./movies
|
||||
MERCURE_URL=http://mercure/.well-known/mercure
|
||||
MERCURE_PUBLIC_URL=https://dev.caldwell.digital/hub/.well-known/mercure
|
||||
MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!"
|
||||
MONITOR_FREQUENCY="* * * * *"
|
||||
12
.env.dist
@@ -1,12 +0,0 @@
|
||||
APP_ENV=%%app_env%%
|
||||
APP_SECRET="%%app_secret%%"
|
||||
DATABASE_URL="%%db_url%%"
|
||||
DOWNLOAD_DIR=%%download_dir%%
|
||||
REAL_DEBRID_KEY="%%rd_key%%"
|
||||
TMDB_API=%%tmdb_api%%
|
||||
MERCURE_URL=%%mercure_url%%
|
||||
MERCURE_PUBLIC_URL=%%mercure_public_url%%
|
||||
MERCURE_JWT_SECRET="%%mercure_jwt_secret%%"
|
||||
JELLYFIN_URL=%%jellyfin_url%%
|
||||
JELLYFIN_TOKEN=%%jellyfin_token%%
|
||||
REDIS_HOST="%%redis_host%%"
|
||||
21
Dockerfile
@@ -1,4 +1,19 @@
|
||||
FROM registry.caldwell.digital/library/php:8.4-apache
|
||||
FROM php:8.4-fpm-alpine3.21
|
||||
|
||||
COPY ./bash/vhost.conf /etc/apache2/sites-enabled/vhost.conf
|
||||
RUN rm /etc/apache2/sites-enabled/000-default.conf
|
||||
RUN docker-php-ext-install pdo_mysql
|
||||
|
||||
# SETUP PHP-FPM CONFIG SETTINGS (max_children / max_requests)
|
||||
RUN echo 'pm = dynamic' >> /usr/local/etc/php-fpm.d/zz-docker.conf && \
|
||||
echo 'pm.max_children = 75' >> /usr/local/etc/php-fpm.d/zz-docker.conf && \
|
||||
echo 'pm.start_servers = 30' >> /usr/local/etc/php-fpm.d/zz-docker.conf && \
|
||||
echo 'pm.min_spare_servers = 5' >> /usr/local/etc/php-fpm.d/zz-docker.conf && \
|
||||
echo 'pm.max_spare_servers = 30' >> /usr/local/etc/php-fpm.d/zz-docker.conf && \
|
||||
echo 'pm.process_idle_timeout = 10s' >> /usr/local/etc/php-fpm.d/zz-docker.conf
|
||||
|
||||
COPY --chmod=0775 ./bash/entrypoint.sh /usr/local/bin/
|
||||
|
||||
HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD [ "php", "/var/www/bin/console", "startup:status" ]
|
||||
|
||||
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
|
||||
|
||||
WORKDIR /var/www
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
FROM registry.caldwell.digital/library/php:8.4-apache
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install libldap2-dev -y && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
|
||||
docker-php-ext-install ldap
|
||||
|
||||
COPY --chown=www-data:www-data . /var/www
|
||||
COPY ./bash/vhost.conf /etc/apache2/sites-enabled/vhost.conf
|
||||
COPY bash/nginx.conf /etc/apache2/sites-enabled/vhost.conf
|
||||
RUN rm /etc/apache2/sites-enabled/000-default.conf
|
||||
|
||||
57
README.md
@@ -1,13 +1,50 @@
|
||||
# Caldwell Digital - Symfony Template
|
||||
Get up and running quickly with this Symfony framework template!
|
||||
# Torsearch
|
||||
Torsearch is a "media acquisition tool" that works strictly with Real Debrid. Torsearch makes it easy to search for
|
||||
and download your favorite movies and tv shows. You can think of it like Stremio, but without the streaming. Why the
|
||||
comparison to Stremio? That's because Torsearch uses the same source for media files that Stremio uses: Torrentio
|
||||
(hence the name: Torsearch).
|
||||
|
||||
After two failed attempts at running a media server, I decided to hang up my hat and give up my dream of a self-hosted
|
||||
media server. I figured the days of torrenting were mostly over and everybody ranting & raving about their media collections
|
||||
must be going to Walmart and buying up the bucket of old movies they have. That's until I stumbled across Stremio.
|
||||
|
||||
At first, it seemed too good to be true, but I was yearning for something just sketchy enough to try out. What could
|
||||
go wrong with handing over my card information to an unknown organization across the pond? At the end of the day,
|
||||
the cost benefit analysis landed in my favor, and about 30 minutes after purchasing my Real Debrid subscription and
|
||||
setting up Stremio, I was in business.
|
||||
|
||||
My mind was blown. I might not have the most "cultured" taste in media, but it had everything I searched for and more! After
|
||||
watching a few movies, I noticed the "Copy Download Link" button. "What's this lil guy do?" I asked myself. Duh, it
|
||||
downloads the f*****g movie. And there's the 💡flashing over my head. There's gotta be a way to automate this, I told myself.
|
||||
|
||||
After a month of studying Stremio's code and lots of tinkering, I finally figured it out. Torrentio is the magic behind
|
||||
the scenes. You feed it a Real Debrid API key and an IMDB ID, and it gives you a list of results to download that media.
|
||||
Easy peasy.
|
||||
|
||||
In about an hour I had a proof of concept working. It wasn't pretty, but it wasn't supposed to be. That proof-of-concept
|
||||
has blossomed into the beautiful Torsearch that I've been using nearly every day since then. The code in this repo
|
||||
is a complete re-write of the proof-of-concept that started out ugly and ended up even uglier. Knowing the core functionality
|
||||
required to make it work, I was able to re-write the app with some design patterns in place.
|
||||
|
||||
## Pics or didn't happen
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Features
|
||||
- Search for Movies & TV Shows by their name
|
||||
- Download directly to your NAS
|
||||
- Monitor TV Shows for new episodes and automatically download them
|
||||
- Browse popular media and view its download options
|
||||
- LDAP or local auth (OIDC coming soon)
|
||||
|
||||
## Features on the roadmap
|
||||
- Requests - allow users to request new media
|
||||
- OIDC auth
|
||||
- Prometheus logging
|
||||
|
||||
## Getting Started
|
||||
1. Run `source bash/get_certs.sh` to grab the wildcard certs
|
||||
2. Set the docker image tag in the `bash/build.sh` file
|
||||
3. Set the docker image tag in the `deploy.compose.yml` file
|
||||
4. run `composer install`
|
||||
1. Clone the repo
|
||||
|
||||
## Optional steps
|
||||
1. Set phing vars
|
||||
2. Update the project name in `build.xml`
|
||||
3. Set a custom development hostname in `bash/vhost.conf`
|
||||
|
||||
@@ -15,7 +15,7 @@ export default class extends Controller {
|
||||
}
|
||||
|
||||
download() {
|
||||
fetch('/download', {
|
||||
fetch('/api/download', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -26,7 +26,7 @@ export default class extends Controller {
|
||||
title: this.element.dataset['title'],
|
||||
filename: this.filenameValue,
|
||||
mediaType: this.mediaTypeValue,
|
||||
imdbId: this.imdbIdValue
|
||||
imdbId: this.imdbIdValue,
|
||||
})
|
||||
})
|
||||
.then(res => res.json())
|
||||
|
||||
42
assets/controllers/download_list_controller.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
import { getComponent } from '@symfony/ux-live-component';
|
||||
/*
|
||||
* The following line makes this controller "lazy": it won't be downloaded until needed
|
||||
* See https://symfony.com/bundles/StimulusBundle/current/index.html#lazy-stimulus-controllers
|
||||
*/
|
||||
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
static targets = ['download']
|
||||
|
||||
async initialize() {
|
||||
this.component = await getComponent(this.element);
|
||||
}
|
||||
|
||||
connect() {
|
||||
// Called every time the controller is connected to the DOM
|
||||
// (on page load, when it's added to the DOM, moved in the DOM, etc.)
|
||||
|
||||
// Here you can add event listeners on the element or target elements,
|
||||
// add or remove classes, attributes, dispatch custom events, etc.
|
||||
// this.fooTarget.addEventListener('click', this._fooBar)
|
||||
}
|
||||
|
||||
downloadTargetConnected(target) {
|
||||
let downloads = this.element.querySelectorAll('tbody tr');
|
||||
if (downloads.length > 5) {
|
||||
target.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// Add custom controller actions here
|
||||
// fooBar() { this.fooTarget.classList.toggle(this.bazClass) }
|
||||
|
||||
disconnect() {
|
||||
// Called anytime its element is disconnected from the DOM
|
||||
// (on page change, when it's removed from or moved in the DOM, etc.)
|
||||
|
||||
// Here you should remove all event listeners added in "connect()"
|
||||
// this.fooTarget.removeEventListener('click', this._fooBar)
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
echo "> Building ${IMG} for linux/amd64"
|
||||
docker buildx build --platform linux/amd64 -f Dockerfile.prod -t ${IMG} .
|
||||
docker buildx build --platform linux/amd64 -f Dockerfile.app -t "${IMG}-app" .
|
||||
docker buildx build --platform linux/amd64 -f Dockerfile.worker -t "${IMG}-worker" .
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
echo "> Building ${IMG} for linux/arm/v8"
|
||||
docker buildx build --platform linux/arm/v8 -f Dockerfile.prod -t ${IMG} .
|
||||
docker buildx build --platform linux/arm/v8 -f Dockerfile.app -t "${IMG}-app" .
|
||||
docker buildx build --platform linux/arm/v8 -f Dockerfile.app -t "${IMG}-worker" .
|
||||
@@ -1,2 +1,3 @@
|
||||
echo "> Pushing ${IMG}"
|
||||
docker push ${IMG}
|
||||
docker push "${IMG}-app"
|
||||
docker push "${IMG}-worker"
|
||||
@@ -2,5 +2,5 @@ dev.caldwell.digital:443
|
||||
|
||||
tls /etc/ssl/wildcard.crt /etc/ssl/wildcard.pem
|
||||
|
||||
reverse_proxy php:80
|
||||
reverse_proxy app:80
|
||||
|
||||
|
||||
13
bash/entrypoint.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Sleep for a second to ensure DB is awake and ready
|
||||
SLEEP_TIME=$(shuf -i 2-5 -n 1)
|
||||
echo "> Sleeping for ${SLEEP_TIME} seconds to wait for the database"
|
||||
echo "> If there are errors after the migration runs, it's possible another container (scheduler, worker, etc.) already ran the migrations"
|
||||
sleep $SLEEP_TIME
|
||||
|
||||
# Provision database
|
||||
php /var/www/bin/console doctrine:migrations:migrate --no-interaction
|
||||
php /var/www/bin/console db:seed
|
||||
|
||||
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
||||
32
bash/nginx.conf
Executable file
@@ -0,0 +1,32 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name localhost;
|
||||
|
||||
root /var/www/public;
|
||||
|
||||
location /hub/ {
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header Host $host;
|
||||
proxy_redirect off;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_pass http://mercure/;
|
||||
}
|
||||
|
||||
|
||||
location / {
|
||||
# try to serve file directly, fallback to index.php
|
||||
try_files $uri /index.php$is_args$args;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
fastcgi_pass unix:/run/php-fpm.sock;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.*)$;
|
||||
fastcgi_buffers 16 16k;
|
||||
fastcgi_buffer_size 32k;
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
||||
fastcgi_param DOCUMENT_ROOT $realpath_root;
|
||||
internal;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<VirtualHost *:80>
|
||||
ServerName localhost
|
||||
|
||||
DocumentRoot /var/www/public
|
||||
DirectoryIndex /index.php
|
||||
|
||||
<LocationMatch "/hub/">
|
||||
ProxyPass http://mercure:80/
|
||||
ProxyPassReverse http://mercure:80/
|
||||
</LocationMatch>
|
||||
|
||||
<Directory /var/www/public>
|
||||
AllowOverride None
|
||||
Order Allow,Deny
|
||||
Allow from All
|
||||
|
||||
FallbackResource /index.php
|
||||
</Directory>
|
||||
|
||||
<Directory /var/www/public/bundles>
|
||||
FallbackResource disabled
|
||||
</Directory>
|
||||
</VirtualHost>
|
||||
@@ -1,11 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="Caldwell Digital Symfony Template" default="build">
|
||||
<project name="Torsearch" default="build">
|
||||
<!-- build dev for dev envs -->
|
||||
<target name="build" depends="setEnv,composer,compileAssets,migrateDb,clearCache" />
|
||||
|
||||
<target name="composer" description="Run composer">
|
||||
<exec executable="composer">
|
||||
<arg value="install" />
|
||||
<arg value="--ignore-platform-reqs" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
|
||||
40
compose.yml
@@ -19,24 +19,44 @@ services:
|
||||
command: redis-server --maxmemory 512MB
|
||||
restart: unless-stopped
|
||||
|
||||
php:
|
||||
build: .
|
||||
app:
|
||||
build:
|
||||
dockerfile: docker/Dockerfile.app
|
||||
context: .
|
||||
ports:
|
||||
- "8001:80"
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
depends_on:
|
||||
database:
|
||||
condition: service_healthy
|
||||
|
||||
worker:
|
||||
build: .
|
||||
build:
|
||||
dockerfile: docker/Dockerfile.worker
|
||||
context: .
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
- ./var/download:/var/download
|
||||
command: php ./bin/console messenger:consume async -vv --time-limit=3600
|
||||
- ./:/app
|
||||
- ./var/downloads/movies:/var/download/movies
|
||||
- ./var/downloads/tvshows:/var/download/tvshows
|
||||
command: -vvv --time-limit=3600
|
||||
env_file:
|
||||
- .env
|
||||
depends_on:
|
||||
app:
|
||||
condition: service_healthy
|
||||
|
||||
scheduler:
|
||||
build: .
|
||||
build:
|
||||
dockerfile: docker/Dockerfile.scheduler
|
||||
context: .
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
- ./var/download:/var/download
|
||||
command: php ./bin/console messenger:consume scheduler_monitor -vv --time-limit=3600
|
||||
command: -vv --time-limit=3600
|
||||
depends_on:
|
||||
app:
|
||||
condition: service_healthy
|
||||
|
||||
mercure:
|
||||
image: dunglas/mercure
|
||||
@@ -67,6 +87,10 @@ services:
|
||||
MYSQL_USERNAME: app
|
||||
MYSQL_PASSWORD: password
|
||||
MYSQL_ROOT_PASSWORD: password
|
||||
healthcheck:
|
||||
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
|
||||
timeout: 10s
|
||||
retries: 10
|
||||
|
||||
adminer:
|
||||
image: adminer
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
"aimeos/map": "^3.12",
|
||||
"doctrine/dbal": "^3",
|
||||
"doctrine/doctrine-bundle": "^2.14",
|
||||
"doctrine/doctrine-fixtures-bundle": "^4.1",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.4",
|
||||
"doctrine/orm": "^3.3",
|
||||
"dragonmantank/cron-expression": "^3.4",
|
||||
"league/pipeline": "^1.1",
|
||||
"nesbot/carbon": "^3.9",
|
||||
"nihilarr/parse-torrent-name": "^0.0.1",
|
||||
"nyholm/psr7": "*",
|
||||
@@ -29,6 +31,7 @@
|
||||
"symfony/flex": "^2",
|
||||
"symfony/form": "7.2.*",
|
||||
"symfony/framework-bundle": "7.2.*",
|
||||
"symfony/ldap": "7.2.*",
|
||||
"symfony/mercure-bundle": "^0.3.9",
|
||||
"symfony/messenger": "7.2.*",
|
||||
"symfony/runtime": "7.2.*",
|
||||
@@ -86,7 +89,7 @@
|
||||
"post-update-cmd": [
|
||||
"@auto-scripts"
|
||||
],
|
||||
"sym": "docker compose exec php ./bin/console"
|
||||
"sym": "docker compose exec app ./bin/console"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/symfony": "*"
|
||||
|
||||
302
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "7e29123297e1ac72cd417967d2a761b4",
|
||||
"content-hash": "33f1579a34e7ada02bb4738a9b39f493",
|
||||
"packages": [
|
||||
{
|
||||
"name": "1tomany/rich-bundle",
|
||||
@@ -446,6 +446,89 @@
|
||||
],
|
||||
"time": "2025-03-22T10:17:19+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/data-fixtures",
|
||||
"version": "2.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/data-fixtures.git",
|
||||
"reference": "f7f1e12d6bceb58c204b3e77210a103c1c57601e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/f7f1e12d6bceb58c204b3e77210a103c1c57601e",
|
||||
"reference": "f7f1e12d6bceb58c204b3e77210a103c1c57601e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"doctrine/persistence": "^3.1 || ^4.0",
|
||||
"php": "^8.1",
|
||||
"psr/log": "^1.1 || ^2 || ^3"
|
||||
},
|
||||
"conflict": {
|
||||
"doctrine/dbal": "<3.5 || >=5",
|
||||
"doctrine/orm": "<2.14 || >=4",
|
||||
"doctrine/phpcr-odm": "<1.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/coding-standard": "^12",
|
||||
"doctrine/dbal": "^3.5 || ^4",
|
||||
"doctrine/mongodb-odm": "^1.3.0 || ^2.0.0",
|
||||
"doctrine/orm": "^2.14 || ^3",
|
||||
"ext-sqlite3": "*",
|
||||
"fig/log-test": "^1",
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phpunit/phpunit": "^10.5.3",
|
||||
"symfony/cache": "^6.4 || ^7",
|
||||
"symfony/var-exporter": "^6.4 || ^7"
|
||||
},
|
||||
"suggest": {
|
||||
"alcaeus/mongo-php-adapter": "For using MongoDB ODM 1.3 with PHP 7 (deprecated)",
|
||||
"doctrine/mongodb-odm": "For loading MongoDB ODM fixtures",
|
||||
"doctrine/orm": "For loading ORM fixtures",
|
||||
"doctrine/phpcr-odm": "For loading PHPCR ODM fixtures"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Common\\DataFixtures\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jonathan Wage",
|
||||
"email": "jonwage@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Data Fixtures for all Doctrine Object Managers",
|
||||
"homepage": "https://www.doctrine-project.org",
|
||||
"keywords": [
|
||||
"database"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/doctrine/data-fixtures/issues",
|
||||
"source": "https://github.com/doctrine/data-fixtures/tree/2.0.2"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://www.doctrine-project.org/sponsorship.html",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://www.patreon.com/phpdoctrine",
|
||||
"type": "patreon"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdata-fixtures",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-01-21T13:21:31+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/dbal",
|
||||
"version": "3.9.4",
|
||||
@@ -727,6 +810,92 @@
|
||||
],
|
||||
"time": "2025-03-22T17:28:21+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/doctrine-fixtures-bundle",
|
||||
"version": "4.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/DoctrineFixturesBundle.git",
|
||||
"reference": "a06db6b81ff20a2980bf92063d80c013bb8b4b7c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/a06db6b81ff20a2980bf92063d80c013bb8b4b7c",
|
||||
"reference": "a06db6b81ff20a2980bf92063d80c013bb8b4b7c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"doctrine/data-fixtures": "^2.0",
|
||||
"doctrine/doctrine-bundle": "^2.2",
|
||||
"doctrine/orm": "^2.14.0 || ^3.0",
|
||||
"doctrine/persistence": "^2.4 || ^3.0 || ^4.0",
|
||||
"php": "^8.1",
|
||||
"psr/log": "^2 || ^3",
|
||||
"symfony/config": "^6.4 || ^7.0",
|
||||
"symfony/console": "^6.4 || ^7.0",
|
||||
"symfony/dependency-injection": "^6.4 || ^7.0",
|
||||
"symfony/deprecation-contracts": "^2.1 || ^3",
|
||||
"symfony/doctrine-bridge": "^6.4.16 || ^7.1.9",
|
||||
"symfony/http-kernel": "^6.4 || ^7.0"
|
||||
},
|
||||
"conflict": {
|
||||
"doctrine/dbal": "< 3"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/coding-standard": "13.0.0",
|
||||
"phpstan/phpstan": "2.1.11",
|
||||
"phpunit/phpunit": "^10.5.38 || 11.4.14"
|
||||
},
|
||||
"type": "symfony-bundle",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Bundle\\FixturesBundle\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Doctrine Project",
|
||||
"homepage": "https://www.doctrine-project.org"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony DoctrineFixturesBundle",
|
||||
"homepage": "https://www.doctrine-project.org",
|
||||
"keywords": [
|
||||
"Fixture",
|
||||
"persistence"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/doctrine/DoctrineFixturesBundle/issues",
|
||||
"source": "https://github.com/doctrine/DoctrineFixturesBundle/tree/4.1.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://www.doctrine-project.org/sponsorship.html",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://www.patreon.com/phpdoctrine",
|
||||
"type": "patreon"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdoctrine-fixtures-bundle",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-03-26T10:56:26+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/doctrine-migrations-bundle",
|
||||
"version": "3.4.1",
|
||||
@@ -1623,6 +1792,62 @@
|
||||
],
|
||||
"time": "2025-01-26T21:29:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/pipeline",
|
||||
"version": "1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/pipeline.git",
|
||||
"reference": "9069ddfdbd5582f8a563e00cffdbeffb9a0acd01"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/pipeline/zipball/9069ddfdbd5582f8a563e00cffdbeffb9a0acd01",
|
||||
"reference": "9069ddfdbd5582f8a563e00cffdbeffb9a0acd01",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.0 || ^10.0 || ^11.5"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"League\\Pipeline\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Frank de Jonge",
|
||||
"email": "info@frenky.net",
|
||||
"role": "Author"
|
||||
},
|
||||
{
|
||||
"name": "Woody Gilk",
|
||||
"email": "woody.gilk@gmail.com",
|
||||
"role": "Maintainer"
|
||||
}
|
||||
],
|
||||
"description": "A plug and play pipeline implementation.",
|
||||
"keywords": [
|
||||
"composition",
|
||||
"design pattern",
|
||||
"pattern",
|
||||
"pipeline",
|
||||
"sequential"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/thephpleague/pipeline/issues",
|
||||
"source": "https://github.com/thephpleague/pipeline/tree/1.1.0"
|
||||
},
|
||||
"time": "2025-02-06T08:48:15+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
"version": "3.9.1",
|
||||
@@ -5082,6 +5307,81 @@
|
||||
],
|
||||
"time": "2025-05-02T09:04:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/ldap",
|
||||
"version": "v7.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/ldap.git",
|
||||
"reference": "48013cfa9d394343162dae7da914112a6206b575"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/ldap/zipball/48013cfa9d394343162dae7da914112a6206b575",
|
||||
"reference": "48013cfa9d394343162dae7da914112a6206b575",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-ldap": "*",
|
||||
"php": ">=8.2",
|
||||
"symfony/options-resolver": "^6.4|^7.0"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/options-resolver": "<6.4",
|
||||
"symfony/security-core": "<6.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/security-core": "^6.4|^7.0",
|
||||
"symfony/security-http": "^6.4|^7.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Ldap\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Charles Sarrazin",
|
||||
"email": "charles@sarraz.in"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Provides a LDAP client for PHP on top of PHP's ldap extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"active-directory",
|
||||
"ldap"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/ldap/tree/v7.2.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-11-25T15:21:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/mercure",
|
||||
"version": "v0.6.5",
|
||||
|
||||
@@ -17,4 +17,5 @@ return [
|
||||
Symfony\Bundle\MercureBundle\MercureBundle::class => ['all' => true],
|
||||
Symfony\UX\Turbo\TurboBundle::class => ['all' => true],
|
||||
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
|
||||
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
|
||||
];
|
||||
|
||||
57
config/dist/ldap.security.yaml
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
security:
|
||||
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
|
||||
password_hashers:
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
|
||||
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
|
||||
providers:
|
||||
users_in_memory: { memory: null }
|
||||
app_local:
|
||||
entity:
|
||||
class: App\User\Framework\Entity\User
|
||||
property: email
|
||||
|
||||
app_ldap:
|
||||
id: App\User\Framework\Security\LdapUserProvider
|
||||
|
||||
firewalls:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
main:
|
||||
lazy: true
|
||||
provider: app_ldap
|
||||
form_login_ldap:
|
||||
login_path: app_login
|
||||
check_path: app_login
|
||||
enable_csrf: true
|
||||
service: Symfony\Component\Ldap\Ldap
|
||||
dn_string: '%env(LDAP_DN_STRING)%'
|
||||
logout:
|
||||
path: app_logout
|
||||
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
|
||||
# https://symfony.com/doc/current/security/impersonating_user.html
|
||||
# switch_user: true
|
||||
|
||||
# Easy way to control access for large sections of your site
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
- { path: ^/getting-started, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/register, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/login, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/, roles: ROLE_USER } # Or ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
||||
|
||||
when@test:
|
||||
security:
|
||||
password_hashers:
|
||||
# By default, password hashers are resource intensive and take time. This is
|
||||
# important to generate secure password hashes. In tests however, secure hashes
|
||||
# are not important, waste resources and increase test times. The following
|
||||
# reduces the work factor to the lowest possible values.
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
|
||||
algorithm: auto
|
||||
cost: 4 # Lowest possible value for bcrypt
|
||||
time_cost: 3 # Lowest possible value for argon
|
||||
memory_cost: 10 # Lowest possible value for argon
|
||||
55
config/dist/local.security.yaml
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
security:
|
||||
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
|
||||
password_hashers:
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
|
||||
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
|
||||
providers:
|
||||
users_in_memory: { memory: null }
|
||||
app_local:
|
||||
entity:
|
||||
class: App\User\Framework\Entity\User
|
||||
property: email
|
||||
|
||||
app_ldap:
|
||||
id: App\User\Framework\Security\LdapUserProvider
|
||||
|
||||
firewalls:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
main:
|
||||
lazy: true
|
||||
provider: app_local
|
||||
form_login:
|
||||
login_path: app_login
|
||||
check_path: app_login
|
||||
enable_csrf: true
|
||||
logout:
|
||||
path: app_logout
|
||||
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
|
||||
# https://symfony.com/doc/current/security/impersonating_user.html
|
||||
# switch_user: true
|
||||
|
||||
# Easy way to control access for large sections of your site
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
- { path: ^/getting-started, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/register, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/login, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/, roles: ROLE_USER } # Or ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
||||
|
||||
when@test:
|
||||
security:
|
||||
password_hashers:
|
||||
# By default, password hashers are resource intensive and take time. This is
|
||||
# important to generate secure password hashes. In tests however, secure hashes
|
||||
# are not important, waste resources and increase test times. The following
|
||||
# reduces the work factor to the lowest possible values.
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
|
||||
algorithm: auto
|
||||
cost: 4 # Lowest possible value for bcrypt
|
||||
time_cost: 3 # Lowest possible value for argon
|
||||
memory_cost: 10 # Lowest possible value for argon
|
||||
@@ -9,7 +9,7 @@ framework:
|
||||
|
||||
# Redis
|
||||
app: cache.adapter.redis
|
||||
default_redis_provider: '%env(REDIS_HOST)%'
|
||||
default_redis_provider: '%app.cache.redis.host%'
|
||||
|
||||
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
|
||||
#app: cache.adapter.apcu
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
mercure:
|
||||
hubs:
|
||||
default:
|
||||
url: '%env(MERCURE_URL)%'
|
||||
public_url: '%env(MERCURE_PUBLIC_URL)%'
|
||||
url: '%app.mercure.url%'
|
||||
public_url: '%app.mercure.public_url%'
|
||||
jwt:
|
||||
secret: '%env(MERCURE_JWT_SECRET)%'
|
||||
publish: '*'
|
||||
|
||||
@@ -29,6 +29,7 @@ framework:
|
||||
'App\Monitor\Action\Command\MonitorTvSeasonCommand': async
|
||||
'App\Monitor\Action\Command\MonitorTvShowCommand': async
|
||||
'App\Monitor\Action\Command\MonitorMovieCommand': async
|
||||
'App\Torrentio\Action\Command\GetTvShowOptionsCommand': async
|
||||
|
||||
# when@test:
|
||||
# framework:
|
||||
|
||||
@@ -5,26 +5,27 @@ security:
|
||||
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
|
||||
providers:
|
||||
users_in_memory: { memory: null }
|
||||
app_user_provider:
|
||||
app_local:
|
||||
entity:
|
||||
class: App\User\Framework\Entity\User
|
||||
property: email
|
||||
|
||||
app_ldap:
|
||||
id: App\User\Framework\Security\LdapUserProvider
|
||||
|
||||
firewalls:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
main:
|
||||
lazy: true
|
||||
provider: app_user_provider
|
||||
provider: app_local
|
||||
form_login:
|
||||
login_path: app_login
|
||||
check_path: app_login
|
||||
enable_csrf: true
|
||||
logout:
|
||||
path: app_logout
|
||||
# where to redirect after logout
|
||||
# target: app_any_route
|
||||
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
@@ -35,6 +36,7 @@ security:
|
||||
# Easy way to control access for large sections of your site
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
- { path: ^/getting-started, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/register, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/login, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/, roles: ROLE_USER } # Or ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
||||
|
||||
@@ -14,6 +14,14 @@ controllersUser:
|
||||
defaults:
|
||||
schemes: ['https']
|
||||
|
||||
controllersDownload:
|
||||
resource:
|
||||
path: ../src/Download/Framework/Controller
|
||||
namespace: App\Download\Framework\Controller
|
||||
type: attribute
|
||||
defaults:
|
||||
schemes: [ 'https' ]
|
||||
|
||||
controllersMonitor:
|
||||
resource:
|
||||
path: ../src/Monitor/Framework/Controller
|
||||
|
||||
61
config/security.yaml
Normal file
@@ -0,0 +1,61 @@
|
||||
security:
|
||||
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
|
||||
password_hashers:
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
|
||||
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
|
||||
providers:
|
||||
users_in_memory: { memory: null }
|
||||
app_local:
|
||||
entity:
|
||||
class: App\User\Framework\Entity\User
|
||||
property: email
|
||||
|
||||
app_ldap:
|
||||
id: App\User\Framework\Security\LdapUserProvider
|
||||
|
||||
firewalls:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
main:
|
||||
lazy: true
|
||||
provider: app_ldap
|
||||
entry_point: form_login_ldap
|
||||
form_login_ldap:
|
||||
login_path: app_login
|
||||
check_path: app_login
|
||||
enable_csrf: true
|
||||
service: Symfony\Component\Ldap\Ldap
|
||||
dn_string: '%env(LDAP_DN_STRING)%'
|
||||
form_login:
|
||||
login_path: app_login
|
||||
check_path: app_login
|
||||
enable_csrf: true
|
||||
logout:
|
||||
path: app_logout
|
||||
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
|
||||
# https://symfony.com/doc/current/security/impersonating_user.html
|
||||
# switch_user: true
|
||||
|
||||
# Easy way to control access for large sections of your site
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
- { path: ^/register, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/login, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/, roles: ROLE_USER } # Or ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
||||
|
||||
when@test:
|
||||
security:
|
||||
password_hashers:
|
||||
# By default, password hashers are resource intensive and take time. This is
|
||||
# important to generate secure password hashes. In tests however, secure hashes
|
||||
# are not important, waste resources and increase test times. The following
|
||||
# reduces the work factor to the lowest possible values.
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
|
||||
algorithm: auto
|
||||
cost: 4 # Lowest possible value for bcrypt
|
||||
time_cost: 3 # Lowest possible value for argon
|
||||
memory_cost: 10 # Lowest possible value for argon
|
||||
@@ -4,11 +4,22 @@
|
||||
# Put parameters here that don't need to change on each machine where the app is deployed
|
||||
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
||||
parameters:
|
||||
# Media
|
||||
media.default_movies_dir: movies
|
||||
media.default_tvshows_dir: tvshows
|
||||
media.movies_path: '/var/download/%env(default:media.default_movies_dir:MOVIES_PATH)%'
|
||||
media.movies_path: '%env(default:media.default_movies_dir:MOVIES_PATH)%'
|
||||
media.tvshows_path: '/var/download/%env(default:media.default_tvshows_dir:TVSHOWS_PATH)%'
|
||||
|
||||
# Mercure
|
||||
app.mercure.url: 'http://mercure/.well-known/mercure'
|
||||
app.mercure.public_url: '%env(APP_URL)%/hub/.well-known/mercure'
|
||||
|
||||
# Cache
|
||||
app.cache.adapter: '%env(default:app.cache.adapter.default:CACHE_ADAPTER)%'
|
||||
app.cache.redis.host: '%env(default:app.cache.redis.host.default:REDIS_HOST)%'
|
||||
app.cache.adapter.default: 'filesystem'
|
||||
app.cache.redis.host.default: 'redis://redis'
|
||||
|
||||
services:
|
||||
# default configuration for services in *this* file
|
||||
_defaults:
|
||||
@@ -28,6 +39,38 @@ services:
|
||||
# please note that last definitions always *replace* previous ones
|
||||
App\Download\Downloader\DownloaderInterface: "@App\\Download\\Downloader\\ProcessDownloader"
|
||||
|
||||
# Session
|
||||
Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
|
||||
arguments:
|
||||
- '%env(DATABASE_URL)%'
|
||||
|
||||
# LDAP
|
||||
App\User\Framework\Security\LdapUserProvider:
|
||||
arguments:
|
||||
$registerLdapUserHandler: '@App\User\Action\Handler\RegisterLdapUserHandler'
|
||||
$userRepository: '@App\User\Framework\Repository\UserRepository'
|
||||
$ldap: '@Symfony\Component\Ldap\LdapInterface'
|
||||
$baseDn: '%env(LDAP_BASE_DN)%'
|
||||
$searchDn: '%env(LDAP_BIND_USER)%'
|
||||
$searchPassword: '%env(LDAP_BIND_PASS)%'
|
||||
$defaultRoles: ['ROLE_USER']
|
||||
$uidKey: '%env(LDAP_UID_KEY)%'
|
||||
# $passwordAttribute: '%env(LDAP_PASSWORD_ATTRIBUTE)%'
|
||||
|
||||
|
||||
Symfony\Component\Ldap\LdapInterface: '@Symfony\Component\Ldap\Ldap'
|
||||
|
||||
Symfony\Component\Ldap\Ldap:
|
||||
arguments: [ '@Symfony\Component\Ldap\Adapter\ExtLdap\Adapter' ]
|
||||
tags:
|
||||
- ldap
|
||||
|
||||
Symfony\Component\Ldap\Adapter\ExtLdap\Adapter:
|
||||
arguments:
|
||||
- host: '%env(LDAP_HOST)%'
|
||||
port: '%env(LDAP_PORT)%'
|
||||
encryption: '%env(LDAP_ENCRYPTION)%'
|
||||
options:
|
||||
protocol_version: 3
|
||||
referrals: false
|
||||
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
services:
|
||||
php:
|
||||
image: registry.caldwell.digital/home/torsearch/app:${TAG}
|
||||
web:
|
||||
image: code.caldwell.digital/home/torsearch/web:latest
|
||||
ports:
|
||||
- "8001:80"
|
||||
- '8001:80'
|
||||
volumes:
|
||||
- $PWD/bash/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
depends_on:
|
||||
app:
|
||||
condition: service_healthy
|
||||
|
||||
app:
|
||||
image: code.caldwell.digital/home/torsearch/app:${TAG}
|
||||
deploy:
|
||||
replicas: 2
|
||||
|
||||
worker:
|
||||
image: registry.caldwell.digital/home/torsearch/app:${TAG}
|
||||
image: code.caldwell.digital/home/torsearch/app:${TAG}
|
||||
volumes:
|
||||
- /mnt/media/downloads:/var/download
|
||||
command: php ./bin/console messenger:consume async -v --time-limit=3600 --limit=10
|
||||
@@ -15,7 +23,7 @@ services:
|
||||
replicas: 2
|
||||
|
||||
scheduler:
|
||||
image: registry.caldwell.digital/home/torsearch/app:${TAG}
|
||||
image: code.caldwell.digital/home/torsearch/app:${TAG}
|
||||
volumes:
|
||||
- /mnt/media/downloads:/var/download
|
||||
command: php ./bin/console messenger:consume scheduler_monitor -vv --time-limit=3600
|
||||
|
||||
@@ -2,6 +2,7 @@ assets
|
||||
bash
|
||||
bin
|
||||
config
|
||||
docker
|
||||
migrations
|
||||
public
|
||||
src
|
||||
|
||||
19
docker/Dockerfile.app
Normal file
@@ -0,0 +1,19 @@
|
||||
FROM trafex/php-nginx:3.9.0
|
||||
|
||||
USER root
|
||||
|
||||
RUN apk add --no-cache \
|
||||
php84-pdo_mysql \
|
||||
php84-simplexml
|
||||
|
||||
USER nobody
|
||||
|
||||
COPY --chown=nobody:nobody . /var/www
|
||||
COPY --chmod=0775 ./bash/entrypoint.sh /usr/local/bin/
|
||||
COPY --chmod=0755 ./bash/nginx.conf /etc/nginx/conf.d/site.conf
|
||||
|
||||
HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD [ "php", "/var/www/bin/console", "startup:status" ]
|
||||
|
||||
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
|
||||
|
||||
WORKDIR /var/www
|
||||
7
docker/Dockerfile.scheduler
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM php:8.4-cli-alpine3.21
|
||||
|
||||
RUN docker-php-ext-install pdo_mysql
|
||||
|
||||
COPY --chown=www-data:www-data . /app
|
||||
|
||||
ENTRYPOINT [ "php", "/app/bin/console", "messenger:consume", "scheduler_monitor" ]
|
||||
3
docker/Dockerfile.web
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM nginx:1.28-alpine
|
||||
|
||||
COPY bash/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
7
docker/Dockerfile.worker
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM php:8.4-cli-alpine3.21
|
||||
|
||||
RUN docker-php-ext-install pdo_mysql
|
||||
|
||||
COPY --chown=www-data:www-data . /app
|
||||
|
||||
ENTRYPOINT [ "php", "/app/bin/console", "messenger:consume", "async" ]
|
||||
53
docs/examples/.env
Normal file
@@ -0,0 +1,53 @@
|
||||
# App must be served over HTTPS (requirement of Mercure)
|
||||
# Either serve behind an SSL terminating reverse proxy
|
||||
# or pass your certificates into the 'app' container.
|
||||
# Please omit any trailing slashes. The APP_URL is
|
||||
# used to generate the Mercure URL behind the scenes.
|
||||
APP_URL="https://torsearch.idocode.io"
|
||||
APP_SECRET="70169beadfbc8101c393cbfbba27a313"
|
||||
APP_ENV=prod
|
||||
|
||||
# Use the DATABASE_URL below to use the MariaDB container
|
||||
# provided in the example.compose.yml file, or remove this
|
||||
# line and fill in the details of your own MySQL/MariaDB server
|
||||
DATABASE_URL="mysql://root:password@database:3306/app?serverVersion=10.6.19.2-MariaDB&charset=utf8mb4"
|
||||
|
||||
# Fill in your MySQL/MariaDB connection details
|
||||
#DATABASE_URL="mysql://<mysql user>:<mysql pass>@<mysql host>:3306/<mysql db name>?serverVersion=10.6.19.2-MariaDB&charset=utf8mb4"
|
||||
|
||||
# Enter your Real Debrid API key
|
||||
# This key is never saved anywhere
|
||||
# else and is passed to Torrentio
|
||||
# to retrieve download options
|
||||
REAL_DEBRID_KEY=""
|
||||
|
||||
# Enter you TMDB API key
|
||||
# This is used to provide rich search results
|
||||
# when searching for media and rendering the
|
||||
# Popular Movies and TV Shows section.
|
||||
TMDB_API=
|
||||
|
||||
MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!"
|
||||
|
||||
# Use your own Redis instance or use the
|
||||
# below value to use the container included
|
||||
# in the example compose.yml file.
|
||||
REDIS_HOST="redis://redis"
|
||||
|
||||
# LDAP Config: To use LDAP, enter the below fields
|
||||
# and run 'php bin/console config:set auth.method ldap'
|
||||
LDAP_HOST=
|
||||
LDAP_PORT=
|
||||
LDAP_ENCRYPTION=
|
||||
LDAP_BASE_DN=
|
||||
LDAP_BIND_USER=
|
||||
LDAP_BIND_PASS=
|
||||
LDAP_DN_STRING=
|
||||
LDAP_UID_KEY="uid"
|
||||
# LDAP group that identifies an Admin
|
||||
# Users with this LDAP group will automatically
|
||||
# get the admin role in this system.
|
||||
LDAP_ADMIN_ROLE_DN=""
|
||||
LDAP_EMAIL_ATTRIBUTE=mail
|
||||
LDAP_USERNAME_ATTRIBUTE=uid
|
||||
LDAP_NAME_ATTRIBUTE=displayname
|
||||
108
docs/examples/compose.yml
Normal file
@@ -0,0 +1,108 @@
|
||||
services:
|
||||
# The "entrypoint" into the application. This reverse proxy
|
||||
# proxies traffic back to their respective services. If not
|
||||
# running behind a reverse proxy inject your SSL certificates
|
||||
# into this container.
|
||||
# This container runs the actual web app in a php:8.4-fpm
|
||||
# base container.
|
||||
app:
|
||||
image: code.caldwell.digital/home/torsearch-app:latest
|
||||
ports:
|
||||
- '8006:80'
|
||||
env_file:
|
||||
- .env
|
||||
depends_on:
|
||||
database:
|
||||
condition: service_healthy
|
||||
|
||||
# Downloads happen in this container. Replicate this
|
||||
# container to run multiple downloads simultaneously.
|
||||
# Map your "movies" folder to /var/download/movies
|
||||
# Map your "TV shows" folder to /var/download/tvshows
|
||||
# If your folders are on another machine, use an NFS volume.
|
||||
# This container runs a Symfony worker process.
|
||||
# See: https://symfony.com/doc/current/messenger.html
|
||||
worker:
|
||||
image: code.caldwell.digital/home/torsearch-worker:latest
|
||||
volumes:
|
||||
- /mnt/media/downloads/movies:/var/download/movies
|
||||
- /mnt/media/downloads/tvshows:/var/download/tvshows
|
||||
command: -v --time-limit=3600 --limit=10
|
||||
env_file:
|
||||
- .env
|
||||
restart: always
|
||||
depends_on:
|
||||
app:
|
||||
condition: service_healthy
|
||||
|
||||
# This container handles the monitoring for new media. When new
|
||||
# monitors are added, jobs are periodically dispatched to this
|
||||
# container, and the desired media is searched for and downloaded.
|
||||
# This container runs a Symfony worker process.
|
||||
# See: https://symfony.com/doc/current/messenger.html
|
||||
scheduler:
|
||||
image: code.caldwell.digital/home/torsearch-scheduler:latest
|
||||
volumes:
|
||||
- ./downloads:/var/download
|
||||
command: -vv --time-limit=3600
|
||||
env_file:
|
||||
- .env
|
||||
restart: always
|
||||
depends_on:
|
||||
app:
|
||||
condition: service_healthy
|
||||
|
||||
# This container facilitates viewing the progress of downloads
|
||||
# in realtime. It also handles sending alerts and notifications.
|
||||
# The MERCURE_PUBLISHER_JWT key & MERCURE_SUBSCRIBER_JWT_KEY should
|
||||
# match the MERCURE_JWT_SECRET environment variable.
|
||||
mercure:
|
||||
image: dunglas/mercure
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3001:80"
|
||||
environment:
|
||||
SERVER_NAME: ':80'
|
||||
MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
|
||||
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
|
||||
MERCURE_EXTRA_DIRECTIVES: |
|
||||
cors_origins *
|
||||
anonymous
|
||||
command: /usr/bin/caddy run --config /etc/caddy/dev.Caddyfile
|
||||
volumes:
|
||||
- mercure_data:/data
|
||||
- mercure_config:/config
|
||||
|
||||
database:
|
||||
image: mariadb:10.11.2
|
||||
volumes:
|
||||
- mysql:/var/lib/mysql
|
||||
environment:
|
||||
MYSQL_DATABASE: app
|
||||
MYSQL_USERNAME: app
|
||||
MYSQL_PASSWORD: password
|
||||
MYSQL_ROOT_PASSWORD: password
|
||||
healthcheck:
|
||||
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
|
||||
timeout: 10s
|
||||
retries: 10
|
||||
|
||||
redis:
|
||||
image: redis:latest
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
command: redis-server --maxmemory 512MB
|
||||
restart: unless-stopped
|
||||
|
||||
# **Optional**
|
||||
# Provides a simple method of viewing the database
|
||||
adminer:
|
||||
image: adminer
|
||||
ports:
|
||||
- "8081:8080"
|
||||
|
||||
volumes:
|
||||
mysql:
|
||||
mercure_config:
|
||||
mercure_data:
|
||||
redis_data:
|
||||
BIN
docs/img/torsearch_filter_download.png
Normal file
|
After Width: | Height: | Size: 200 KiB |
BIN
docs/img/torsearch_homepage.png
Normal file
|
After Width: | Height: | Size: 421 KiB |
BIN
docs/img/torsearch_inception_results.png
Normal file
|
After Width: | Height: | Size: 654 KiB |
BIN
docs/img/torsearch_monitor.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
docs/img/torsearch_severance.png
Normal file
|
After Width: | Height: | Size: 568 KiB |
BIN
docs/img/torsearch_severance_episodes.png
Normal file
|
After Width: | Height: | Size: 889 KiB |
BIN
docs/img/torsearch_severance_media.png
Normal file
|
After Width: | Height: | Size: 643 KiB |
BIN
docs/img/torsearch_severance_results.png
Normal file
|
After Width: | Height: | Size: 438 KiB |
35
migrations/Version20250510185814.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20250510185814 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE user ADD username VARCHAR(255) DEFAULT NULL
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE user DROP username
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
47
migrations/Version20250511050008.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20250511050008 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE download ADD user_id INT DEFAULT NULL
|
||||
SQL);
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE download ADD CONSTRAINT FK_781A8270A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)
|
||||
SQL);
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX IDX_781A8270A76ED395 ON download (user_id)
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE download DROP FOREIGN KEY FK_781A8270A76ED395
|
||||
SQL);
|
||||
$this->addSql(<<<'SQL'
|
||||
DROP INDEX IDX_781A8270A76ED395 ON download
|
||||
SQL);
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE download DROP user_id
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
35
migrations/Version20250519193350.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20250519193350 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE preference ADD type VARCHAR(255) DEFAULT NULL
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE preference DROP type
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
58
src/Command/ConfigSetCommand.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'config:set',
|
||||
description: 'Add a short description for your command',
|
||||
)]
|
||||
class ConfigSetCommand extends Command
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addArgument('key', InputArgument::REQUIRED, 'Config key')
|
||||
->addArgument('value', InputArgument::REQUIRED, 'Config value')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$key = $input->getArgument('key');
|
||||
$handlers = [
|
||||
'auth.method' => 'setAuthMethod',
|
||||
];
|
||||
|
||||
$handler = $handlers[$key];
|
||||
$this->$handler($input, $io);
|
||||
|
||||
$io->success('Success: "' . $input->getArgument('key') . '" set to "' . $input->getArgument('value') . '"');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function setAuthMethod(InputInterface $input, SymfonyStyle $io)
|
||||
{
|
||||
$config = [
|
||||
'local' => 'config/dist/local.security.yaml',
|
||||
'ldap' => 'config/dist/ldap.security.yaml',
|
||||
];
|
||||
$authMethod = $input->getArgument('value');
|
||||
$io->text('> Setting auth method to: ' . $authMethod);
|
||||
copy($config[$authMethod], 'config/packages/security.yaml');
|
||||
}
|
||||
}
|
||||
171
src/Command/SeedDatabaseCommand.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\User\Framework\Repository\PreferenceOptionRepository;
|
||||
use App\User\Framework\Repository\PreferencesRepository;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'db:seed',
|
||||
description: 'Seed the database with required data.',
|
||||
)]
|
||||
class SeedDatabaseCommand extends Command
|
||||
{
|
||||
private PreferencesRepository $preferenceRepository;
|
||||
private PreferenceOptionRepository $preferenceOptionRepository;
|
||||
|
||||
public function __construct(
|
||||
PreferencesRepository $preferenceRepository,
|
||||
PreferenceOptionRepository $preferenceOptionRepository,
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->preferenceRepository = $preferenceRepository;
|
||||
$this->preferenceOptionRepository = $preferenceOptionRepository;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$this->seedPreferences($io);
|
||||
$this->seedPreferenceOptions($io);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function seedPreferences(SymfonyStyle $io)
|
||||
{
|
||||
$io->info('[SeedDatabaseCommand] > Seeding preferences...');
|
||||
$preferences = $this->getPreferences();
|
||||
|
||||
foreach ($preferences as $preference) {
|
||||
if ($this->preferenceRepository->find($preference['id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->preferenceRepository->getEntityManager()->persist((new \App\User\Framework\Entity\Preference())
|
||||
->setId($preference['id'])
|
||||
->setName($preference['name'])
|
||||
->setDescription($preference['description'])
|
||||
->setEnabled($preference['enabled'])
|
||||
->setType($preference['type'])
|
||||
);
|
||||
}
|
||||
|
||||
$this->preferenceRepository->getEntityManager()->flush();
|
||||
}
|
||||
|
||||
private function getPreferences(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'id' => 'codec',
|
||||
'name' => 'Codec',
|
||||
'description' => null,
|
||||
'enabled' => true,
|
||||
'type' => 'media',
|
||||
],
|
||||
[
|
||||
'id' => 'resolution',
|
||||
'name' => 'Resolution',
|
||||
'description' => null,
|
||||
'enabled' => true,
|
||||
'type' => 'media',
|
||||
],
|
||||
[
|
||||
'id' => 'language',
|
||||
'name' => 'Language',
|
||||
'description' => null,
|
||||
'enabled' => true,
|
||||
'type' => 'media',
|
||||
],
|
||||
[
|
||||
'id' => 'provider',
|
||||
'name' => 'Provider',
|
||||
'description' => null,
|
||||
'enabled' => true,
|
||||
'type' => 'media',
|
||||
],
|
||||
[
|
||||
'id' => 'movie_folder',
|
||||
'name' => 'Create new folder for Movies',
|
||||
'description' => 'When downloading a movie, store it in a new folder in your base \'movies\' folder. (e.g.: .../movies/Inception/Inception.2160p.h265.mkv)',
|
||||
'enabled' => true,
|
||||
'type' => 'download'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function seedPreferenceOptions(SymfonyStyle $io)
|
||||
{
|
||||
$io->info('[SeedDatabaseCommand] > Seeding preference options...');
|
||||
$options = $this->getPreferenceOptions();
|
||||
|
||||
foreach ($options as $option) {
|
||||
if ($this->preferenceOptionRepository->findBy([
|
||||
'preference' => $option['preference_id'],
|
||||
'name' => $option['name'],
|
||||
'value' => $option['value'],
|
||||
'enabled' => $option['enabled'],
|
||||
])) {
|
||||
continue;
|
||||
}
|
||||
$this->preferenceOptionRepository->getEntityManager()->persist(
|
||||
(new \App\User\Framework\Entity\PreferenceOption())
|
||||
->setPreference($this->preferenceRepository->find($option['preference_id']))
|
||||
->setName($option['name'])
|
||||
->setValue($option['value'])
|
||||
->setEnabled($option['enabled'])
|
||||
);
|
||||
}
|
||||
|
||||
$this->preferenceOptionRepository->getEntityManager()->flush();
|
||||
}
|
||||
|
||||
private function getPreferenceOptions(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'preference_id' => 'resolution',
|
||||
'name' => '720p',
|
||||
'value' => '720p',
|
||||
'enabled' => true
|
||||
],
|
||||
[
|
||||
'preference_id' => 'resolution',
|
||||
'name' => '1080p',
|
||||
'value' => '1080p',
|
||||
'enabled' => true
|
||||
],
|
||||
[
|
||||
'preference_id' => 'resolution',
|
||||
'name' => '2160p',
|
||||
'value' => '2160p',
|
||||
'enabled' => true
|
||||
],
|
||||
[
|
||||
'preference_id' => 'codec',
|
||||
'name' => '-',
|
||||
'value' => '-',
|
||||
'enabled' => true
|
||||
],
|
||||
[
|
||||
'preference_id' => 'codec',
|
||||
'name' => 'h264',
|
||||
'value' => 'h264',
|
||||
'enabled' => true
|
||||
],
|
||||
[
|
||||
'preference_id' => 'codec',
|
||||
'name' => 'h265/HEVC',
|
||||
'value' => 'h265',
|
||||
'enabled' => true
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
48
src/Command/StartupStatusCommand.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'startup:status',
|
||||
description: 'Add a short description for your command',
|
||||
)]
|
||||
class StartupStatusCommand extends Command
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$ready = true;
|
||||
$messengerTableExists = $this->doesMessengerTableExist();
|
||||
|
||||
if (false === $messengerTableExists) {
|
||||
$ready = false;
|
||||
}
|
||||
|
||||
return (true === $ready) ? Command::SUCCESS : Command::FAILURE;
|
||||
}
|
||||
|
||||
private function doesMessengerTableExist()
|
||||
{
|
||||
return $this->entityManager->getConnection()
|
||||
->createSchemaManager()
|
||||
->tablesExist('messenger_messages');
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ final class AlertController extends AbstractController
|
||||
{
|
||||
$update = new Update(
|
||||
'alerts',
|
||||
$this->renderer->render('broadcast/Alert.html.twig', [
|
||||
$this->renderer->render('Alert.stream.html.twig', [
|
||||
'alert_id' => 1,
|
||||
'title' => 'Added to queue',
|
||||
'message' => 'This is a testy test!',
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Download\Action\Input\DownloadMediaInput;
|
||||
use App\Download\Framework\Repository\DownloadRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class DownloadController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private DownloadRepository $downloadRepository,
|
||||
private MessageBusInterface $bus,
|
||||
) {}
|
||||
|
||||
#[Route('/download', name: 'app_download', methods: ['POST'])]
|
||||
public function download(
|
||||
DownloadMediaInput $input,
|
||||
): Response {
|
||||
$download = $this->downloadRepository->insert(
|
||||
$input->url,
|
||||
$input->title,
|
||||
$input->filename,
|
||||
$input->imdbId,
|
||||
$input->mediaType,
|
||||
"",
|
||||
);
|
||||
$input->downloadId = $download->getId();
|
||||
try {
|
||||
$this->bus->dispatch($input->toCommand());
|
||||
} catch (\Throwable $exception) {
|
||||
return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
return $this->json(['status' => 200, 'message' => 'Added to Queue']);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Controller;
|
||||
use App\Download\Framework\Repository\DownloadRepository;
|
||||
use App\Tmdb\Tmdb;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
@@ -16,11 +17,13 @@ final class IndexController extends AbstractController
|
||||
) {}
|
||||
|
||||
#[Route('/', name: 'app_index')]
|
||||
public function index(): Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$request->getSession()->set('mercure_alert_topic', 'alerts_' . uniqid());
|
||||
|
||||
return $this->render('index/index.html.twig', [
|
||||
'active_downloads' => $this->downloadRepository->getActivePaginated(),
|
||||
'recent_downloads' => $this->downloadRepository->latest(5),
|
||||
'active_downloads' => $this->getUser()->getActiveDownloads(),
|
||||
'recent_downloads' => $this->getUser()->getDownloads(),
|
||||
'popular_movies' => $this->tmdb->popularMovies(1, 6),
|
||||
'popular_tvshows' => $this->tmdb->popularTvShows(1, 6),
|
||||
]);
|
||||
|
||||
@@ -6,18 +6,20 @@ use App\Search\Action\Handler\GetMediaInfoHandler;
|
||||
use App\Search\Action\Handler\SearchHandler;
|
||||
use App\Search\Action\Input\GetMediaInfoInput;
|
||||
use App\Search\Action\Input\SearchInput;
|
||||
use Carbon\Carbon;
|
||||
use App\Tmdb\TmdbResult;
|
||||
use App\Torrentio\Action\Command\GetMovieOptionsCommand;
|
||||
use App\Torrentio\Action\Command\GetTvShowOptionsCommand;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
||||
final class SearchController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private SearchHandler $searchHandler,
|
||||
private GetMediaInfoHandler $getMediaInfoHandler,
|
||||
private MessageBusInterface $bus,
|
||||
) {}
|
||||
|
||||
#[Route('/search', name: 'app_search', methods: ['GET'])]
|
||||
@@ -34,24 +36,48 @@ final class SearchController extends AbstractController
|
||||
#[Route('/result/{mediaType}/{tmdbId}', name: 'app_search_result')]
|
||||
public function result(
|
||||
GetMediaInfoInput $input,
|
||||
CacheInterface $cache
|
||||
): Response {
|
||||
$cacheId = sprintf("page.%s.%s", $input->mediaType, $input->tmdbId);
|
||||
$result = $this->getMediaInfoHandler->handle($input->toCommand());
|
||||
$this->warmDownloadOptionCache($result->media);
|
||||
|
||||
// return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
||||
// $item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
||||
$result = $this->getMediaInfoHandler->handle($input->toCommand());
|
||||
return $this->render('search/result.html.twig', [
|
||||
'results' => $result,
|
||||
'filter' => [
|
||||
'resolution' => '',
|
||||
'codec' => '',
|
||||
'provider' => '',
|
||||
'language' => '',
|
||||
'season' => 1,
|
||||
'episode' => ''
|
||||
]
|
||||
]);
|
||||
// });
|
||||
return $this->render('search/result.html.twig', [
|
||||
'results' => $result,
|
||||
'filter' => [
|
||||
'resolution' => '',
|
||||
'codec' => '',
|
||||
'provider' => '',
|
||||
'language' => '',
|
||||
'season' => 1,
|
||||
'episode' => ''
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
private function warmDownloadOptionCache(TmdbResult $result)
|
||||
{
|
||||
if ($result->mediaType === 'tvshows') {
|
||||
// dispatches a job to get the download options
|
||||
// for each episode and load them in cache
|
||||
foreach ($result->episodes as $season => $episodes) {
|
||||
// Only do the first 2 seasons, so we reduce
|
||||
// getting rate-limited by Torrentio
|
||||
if ($season > 2) {
|
||||
return;
|
||||
}
|
||||
foreach ($episodes as $episode) {
|
||||
$this->bus->dispatch(new GetTvShowOptionsCommand(
|
||||
tmdbId: $result->tmdbId,
|
||||
imdbId: $result->imdbId,
|
||||
season: $season,
|
||||
episode: $episode['episode_number'],
|
||||
));
|
||||
}
|
||||
}
|
||||
} elseif ($result->mediaType === 'movies') {
|
||||
$this->bus->dispatch(new GetMovieOptionsCommand(
|
||||
$result->tmdbId,
|
||||
$result->imdbId,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Torrentio\Action\Input\GetMovieOptionsInput;
|
||||
use App\Torrentio\Action\Input\GetTvShowOptionsInput;
|
||||
use Carbon\Carbon;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Mercure\HubInterface;
|
||||
use Symfony\Component\Mercure\Update;
|
||||
@@ -63,7 +64,7 @@ final class TorrentioController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/torrentio/tvshows/clear/{tmdbId}/{imdbId}/{season?}/{episode?}', name: 'app_clear_torrentio_tvshows')]
|
||||
public function clearTvShowOptions(GetTvShowOptionsInput $input, CacheInterface $cache): Response
|
||||
public function clearTvShowOptions(GetTvShowOptionsInput $input, CacheInterface $cache, Request $request): Response
|
||||
{
|
||||
$cacheId = sprintf(
|
||||
"page.torrentio.tvshows.%s.%s.%s.%s",
|
||||
@@ -75,8 +76,8 @@ final class TorrentioController extends AbstractController
|
||||
$cache->delete($cacheId);
|
||||
|
||||
$this->hub->publish(new Update(
|
||||
'alerts',
|
||||
$this->renderer->render('broadcast/Alert.html.twig', [
|
||||
$request->getSession()->get('mercure_alert_topic'),
|
||||
$this->renderer->render('Alert.stream.html.twig', [
|
||||
'alert_id' => uniqid(),
|
||||
'title' => 'Success',
|
||||
'message' => 'Torrentio cache Cleared.',
|
||||
|
||||
@@ -15,6 +15,7 @@ class DownloadMediaCommand implements CommandInterface
|
||||
public string $filename,
|
||||
public string $mediaType,
|
||||
public string $imdbId,
|
||||
public int $userId,
|
||||
public ?int $downloadId = null,
|
||||
) {}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use App\Download\Action\Command\DownloadMediaCommand;
|
||||
use App\Download\Action\Result\DownloadMediaResult;
|
||||
use App\Download\Framework\Repository\DownloadRepository;
|
||||
use App\Download\Downloader\DownloaderInterface;
|
||||
use App\User\Framework\Repository\UserRepository;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
use OneToMany\RichBundle\Contract\HandlerInterface;
|
||||
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||
@@ -17,12 +18,14 @@ readonly class DownloadMediaHandler implements HandlerInterface
|
||||
public function __construct(
|
||||
private DownloaderInterface $downloader,
|
||||
private DownloadRepository $downloadRepository,
|
||||
private UserRepository $userRepository,
|
||||
) {}
|
||||
|
||||
public function handle(CommandInterface $command): ResultInterface
|
||||
{
|
||||
if (null === $command->downloadId) {
|
||||
$download = $this->downloadRepository->insert(
|
||||
$this->userRepository->find($command->userId),
|
||||
$command->url,
|
||||
$command->title,
|
||||
$command->filename,
|
||||
@@ -34,7 +37,6 @@ readonly class DownloadMediaHandler implements HandlerInterface
|
||||
$download = $this->downloadRepository->find($command->downloadId);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$this->downloadRepository->updateStatus($download->getId(), 'In Progress');
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ class DownloadMediaInput implements InputInterface
|
||||
#[SourceRequest('imdbId')]
|
||||
public string $imdbId,
|
||||
|
||||
public ?int $userId = null,
|
||||
|
||||
public ?int $downloadId = null,
|
||||
) {}
|
||||
|
||||
@@ -37,6 +39,7 @@ class DownloadMediaInput implements InputInterface
|
||||
$this->filename,
|
||||
$this->mediaType,
|
||||
$this->imdbId,
|
||||
$this->userId,
|
||||
$this->downloadId,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ use App\Message\DownloadTvShowMessage;
|
||||
interface DownloaderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $baseDir
|
||||
* @param string $mediaType
|
||||
* @param string $title
|
||||
* @param string $url
|
||||
* @return void
|
||||
* Downloads the requested file.
|
||||
*/
|
||||
public function download(string $baseDir, string $title, string $url, ?int $downloadId): void;
|
||||
public function download(string $mediaType, string $title, string $url, ?int $downloadId): void;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Download\Downloader;
|
||||
|
||||
use App\Download\Framework\Entity\Download;
|
||||
use App\Monitor\Service\MediaFiles;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
use Symfony\Component\Process\Process;
|
||||
@@ -11,25 +12,26 @@ class ProcessDownloader implements DownloaderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
private MediaFiles $mediaFiles,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function download(string $baseDir, string $title, string $url, ?int $downloadId): void
|
||||
public function download(string $mediaType, string $title, string $url, ?int $downloadId): void
|
||||
{
|
||||
/** @var Download $downloadEntity */
|
||||
$downloadEntity = $this->entityManager->getRepository(Download::class)->find($downloadId);
|
||||
$downloadEntity->setProgress(0);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$process = new Process([
|
||||
'/bin/sh',
|
||||
'/var/www/bash/app/wget_download.sh',
|
||||
$baseDir,
|
||||
$title,
|
||||
$downloadPreferences = $downloadEntity->getUser()->getDownloadPreferences();
|
||||
$path = $this->getDownloadPath($mediaType, $title, $downloadPreferences);
|
||||
|
||||
$process = (new Process([
|
||||
'wget',
|
||||
$url
|
||||
]);
|
||||
]))->setWorkingDirectory($path);
|
||||
|
||||
$process->setTimeout(1800); // 30 min
|
||||
$process->setIdleTimeout(600); // 10 min
|
||||
@@ -61,4 +63,20 @@ class ProcessDownloader implements DownloaderInterface
|
||||
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
public function getDownloadPath(string $mediaType, string $title, array $downloadPreferences): string
|
||||
{
|
||||
if ($mediaType === 'movies') {
|
||||
if ((bool) $downloadPreferences['movie_folder']->getPreferenceValue() === true) {
|
||||
return $this->mediaFiles->createMovieDirectory($title);
|
||||
}
|
||||
return $this->mediaFiles->getMoviesPath();
|
||||
}
|
||||
|
||||
if ($mediaType === 'tvshows') {
|
||||
return $this->mediaFiles->createTvShowDirectory($title);
|
||||
}
|
||||
|
||||
throw new \Exception("There is no download path for media type: $mediaType");
|
||||
}
|
||||
}
|
||||
73
src/Download/Framework/Controller/ApiController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Download\Framework\Controller;
|
||||
|
||||
use App\Download\Action\Input\DownloadMediaInput;
|
||||
use App\Download\Framework\Repository\DownloadRepository;
|
||||
use App\Download\Stream;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Mercure\HubInterface;
|
||||
use Symfony\Component\Mercure\Update;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class ApiController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private DownloadRepository $downloadRepository,
|
||||
private MessageBusInterface $bus,
|
||||
private readonly HubInterface $hub,
|
||||
) {}
|
||||
|
||||
#[Route('/api/download', name: 'api_download', methods: ['POST'])]
|
||||
public function download(
|
||||
Request $request,
|
||||
DownloadMediaInput $input,
|
||||
): Response {
|
||||
$download = $this->downloadRepository->insert(
|
||||
$this->getUser(),
|
||||
$input->url,
|
||||
$input->title,
|
||||
$input->filename,
|
||||
$input->imdbId,
|
||||
$input->mediaType,
|
||||
"",
|
||||
);
|
||||
$this->downloadRepository->getEntityManager()->persist($download);
|
||||
$this->downloadRepository->getEntityManager()->flush();
|
||||
$input->downloadId = $download->getId();
|
||||
$input->userId = $this->getUser()->getId();
|
||||
|
||||
try {
|
||||
$this->bus->dispatch($input->toCommand());
|
||||
} catch (\Throwable $exception) {
|
||||
return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
$this->hub->publish(new Update(
|
||||
$request->getSession()->get('mercure_alert_topic'),
|
||||
$this->renderView('broadcast/Alert.stream.html.twig', [
|
||||
'alert_id' => uniqid(),
|
||||
'title' => 'Success',
|
||||
'message' => '"' . $input->title . '" added to Queue',
|
||||
])
|
||||
));
|
||||
|
||||
return $this->json(['status' => 200, 'message' => 'Added to Queue']);
|
||||
}
|
||||
|
||||
#[Route('/stream', 'app_stream', methods: ['GET'])]
|
||||
public function streamVideo()
|
||||
{
|
||||
$stream = new Stream(
|
||||
'https://torrentio.strem.fun/realdebrid/QYYBR7OSQ4VEFKWASDEZ2B4VO67KHUJY6IWOT7HHA7ATXO7QCYDQ/e8b22517328a9704bf8400b8b98cfc22836ad1e4/null/3/Ted.2012.UNRATED.1080p.BluRay.x265-RARBG.mp4',
|
||||
[
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
return $stream->start();
|
||||
}
|
||||
}
|
||||
27
src/Download/Framework/Controller/WebController.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Download\Framework\Controller;
|
||||
|
||||
use App\Download\Action\Input\DownloadMediaInput;
|
||||
use App\Download\Framework\Repository\DownloadRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Mercure\HubInterface;
|
||||
use Symfony\Component\Mercure\Update;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class WebController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private DownloadRepository $downloadRepository,
|
||||
private MessageBusInterface $bus,
|
||||
private readonly HubInterface $hub,
|
||||
) {}
|
||||
|
||||
#[Route('/downloads', name: 'app_downloads', methods: ['GET'])]
|
||||
public function download(): Response {
|
||||
return $this->render('downloads/index.html.twig');
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Download\Framework\Entity;
|
||||
|
||||
use App\Download\Framework\Repository\DownloadRepository;
|
||||
use App\User\Framework\Entity\User;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\UX\Turbo\Attribute\Broadcast;
|
||||
|
||||
@@ -39,6 +40,9 @@ class Download
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $batchId = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'downloads')]
|
||||
private ?User $user = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -146,4 +150,16 @@ class Download
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(?User $user): static
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
namespace App\Download\Framework\Repository;
|
||||
|
||||
use App\Download\Framework\Entity\Download;
|
||||
use App\ValueObject\DownloadRequest;
|
||||
use App\User\Framework\Entity\User;
|
||||
use App\Util\Paginator;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Knp\Component\Pager\Paginator;
|
||||
use Knp\Component\Pager\PaginatorInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Download>
|
||||
@@ -16,41 +16,43 @@ class DownloadRepository extends ServiceEntityRepository
|
||||
{
|
||||
private ManagerRegistry $managerRegistry;
|
||||
|
||||
public function __construct(ManagerRegistry $registry, ManagerRegistry $managerRegistry)
|
||||
private Paginator $paginator;
|
||||
|
||||
public function __construct(ManagerRegistry $registry, ManagerRegistry $managerRegistry, Paginator $paginator)
|
||||
{
|
||||
parent::__construct($registry, Download::class);
|
||||
$this->managerRegistry = $managerRegistry;
|
||||
$this->paginator = $paginator;
|
||||
}
|
||||
|
||||
public function getCompletePaginated(int $pageNumber = 1, int $perPage = 10)
|
||||
public function getCompletePaginated(UserInterface $user, int $pageNumber = 1, int $perPage = 10)
|
||||
{
|
||||
$firstResult = ($pageNumber - 1) * $perPage;
|
||||
$query = $this->createQueryBuilder('d')
|
||||
->andWhere('d.status IN (:statuses)')
|
||||
->andWhere('d.user = :user')
|
||||
->orderBy('d.id', 'DESC')
|
||||
->setParameter('statuses', ['Complete'])
|
||||
->setFirstResult($firstResult)
|
||||
->setMaxResults($perPage)
|
||||
->setParameter('user', $user)
|
||||
->getQuery();
|
||||
|
||||
return new \Doctrine\ORM\Tools\Pagination\Paginator($query);
|
||||
return $this->paginator->paginate($query, $pageNumber, $perPage);
|
||||
}
|
||||
|
||||
public function getActivePaginated(int $pageNumber = 1, int $perPage = 5)
|
||||
public function getActivePaginated(UserInterface $user, int $pageNumber = 1, int $perPage = 5)
|
||||
{
|
||||
$firstResult = ($pageNumber - 1) * $perPage;
|
||||
$query = $this->createQueryBuilder('d')
|
||||
->andWhere('d.status IN (:statuses)')
|
||||
->andWhere('d.user = :user')
|
||||
->orderBy('d.id', 'ASC')
|
||||
->setParameter('statuses', ['New', 'In Progress'])
|
||||
->setFirstResult($firstResult)
|
||||
->setMaxResults($perPage)
|
||||
->setParameter('user', $user)
|
||||
->getQuery();
|
||||
|
||||
return new \Doctrine\ORM\Tools\Pagination\Paginator($query);
|
||||
return $this->paginator->paginate($query, $pageNumber, $perPage);
|
||||
}
|
||||
|
||||
public function insert(
|
||||
UserInterface $user,
|
||||
string $url,
|
||||
string $title,
|
||||
string $filename,
|
||||
@@ -59,7 +61,9 @@ class DownloadRepository extends ServiceEntityRepository
|
||||
string $batchId,
|
||||
string $status = 'New'
|
||||
): Download {
|
||||
/** @var User $user */
|
||||
$download = (new Download())
|
||||
->setUser($user)
|
||||
->setUrl($url)
|
||||
->setTitle($title)
|
||||
->setFilename($filename)
|
||||
@@ -75,22 +79,6 @@ class DownloadRepository extends ServiceEntityRepository
|
||||
return $download;
|
||||
}
|
||||
|
||||
public function insertFromDownloadRequest(DownloadRequest $request): Download
|
||||
{
|
||||
$download = (new Download())
|
||||
->setUrl($request->downloadUrl)
|
||||
->setTitle($request->seriesName)
|
||||
->setFilename($request->filename)
|
||||
->setImdbId($request->imdbCode)
|
||||
->setMediaType($request->mediaType)
|
||||
->setStatus('New');
|
||||
|
||||
$this->getEntityManager()->persist($download);
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
return $download;
|
||||
}
|
||||
|
||||
public function updateStatus(int $id, string $status): Download
|
||||
{
|
||||
$download = $this->find($id);
|
||||
@@ -106,18 +94,6 @@ class DownloadRepository extends ServiceEntityRepository
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
|
||||
public function getPendingByBatchId(string $batchId): ?array
|
||||
{
|
||||
$query = $this->createQueryBuilder('d')
|
||||
->andWhere('d.status IN (:statuses)')
|
||||
->andWhere('d.batchId = :batchId')
|
||||
->setParameter('statuses', ['New', 'In Progress'])
|
||||
->setParameter('batchId', $batchId)
|
||||
->getQuery();
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
|
||||
public function latest(int $limit = 1)
|
||||
{
|
||||
return $this->createQueryBuilder('d')
|
||||
|
||||
137
src/Download/Stream.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Download;
|
||||
|
||||
class Stream
|
||||
{
|
||||
|
||||
private $path = "";
|
||||
private $stream = "";
|
||||
private $buffer = 512;
|
||||
private $start = -1;
|
||||
private $end = -1;
|
||||
private $size = null;
|
||||
private $httpString = "";
|
||||
private $contentType = "video/mp4";
|
||||
private $cacheControl = "max-age=2592000, public";
|
||||
private $expires = null;
|
||||
private $lastModified = null;
|
||||
|
||||
function __construct($filePath, $options){
|
||||
$this->path = $filePath;
|
||||
$this->httpString = isset($options['is_https']) ? (($options['is_https'] == true) ? "HTTPS/1.1" : "HTTP/1.1") : "HTTP/1.1";
|
||||
$this->size = isset($options['video_size']) ? $options['video_size'] : $this->size;
|
||||
$this->buffer = isset($options['video_buffer']) ? $options['video_buffer'] : $this->buffer;
|
||||
$this->contentType = isset($options['content_type']) ? $options['content_type'] : $this->contentType;
|
||||
$this->cacheControl = isset($options['cache_control']) ? $options['cache_control'] : $this->cacheControl;
|
||||
$this->expires = isset($options['expires']) ? $options['expires'] : gmdate('D, d M Y H:i:s', time()+2592000).' GMT';
|
||||
$this->lastModified = isset($options['last_modified']) ? $options['last_modified'] : gmdate('D, d M Y H:i:s', @filemtime($this->path)).' GMT';
|
||||
}
|
||||
|
||||
private function open(){
|
||||
if (!($this->stream = fopen($this->path, 'rb'))) {
|
||||
die('Could not open stream for reading');
|
||||
}
|
||||
}
|
||||
|
||||
private function setHeader(){
|
||||
// if (isset($_SERVER['RANGE'])) {
|
||||
// print_r($_SERVER);
|
||||
// die();
|
||||
// }
|
||||
|
||||
ob_get_clean();
|
||||
header("Content-Type: ".$this->contentType);
|
||||
header("Cache-Control: ".$this->cacheControl);
|
||||
header("Expires: ".$this->expires);
|
||||
header("Last-Modified: ".$this->lastModified);
|
||||
$this->start = 0;
|
||||
$this->size = ($this->size == null || $this->size <= 0) ? $this->getContentLengthFromURL($this->path) : $this->size;
|
||||
$this->end = $this->size - 1;
|
||||
|
||||
header("Accept-Ranges: bytes");
|
||||
|
||||
|
||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||
// header("Accept-Ranges: 0-".$this->end);
|
||||
|
||||
$c_start = $this->start;
|
||||
$c_end = $this->end;
|
||||
|
||||
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
if (strpos($range, ',') !== false) {
|
||||
header($this->httpString.' 416 Requested Range Not Satisfiable');
|
||||
header("Content-Range: bytes ".$this->start."-".$this->end."/".$this->size);
|
||||
header("X-ERROR-ERROR: TRUE");
|
||||
exit;
|
||||
}
|
||||
if ($range == '-') {
|
||||
$c_start = $this->size - substr($range, 1);
|
||||
}else{
|
||||
$range = explode('-', $range);
|
||||
$c_start = $range[0];
|
||||
|
||||
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $c_end;
|
||||
}
|
||||
$c_end = ($c_end > $this->end) ? $this->end : $c_end;
|
||||
if ($c_start > $c_end || $c_start > $this->size - 1 || $c_end >= $this->size) {
|
||||
header($this->httpString.' 416 Requested Range Not Satisfiable');
|
||||
header("Content-Range: bytes ".$this->start."-".$this->end."/".$this->size);
|
||||
header("X-ERROR-ERROR: TRUE");
|
||||
exit;
|
||||
}
|
||||
$this->start = $c_start;
|
||||
$this->end = $c_end;
|
||||
$length = $this->end - $this->start + 1;
|
||||
fseek($this->stream, $this->start, SEEK_CUR);
|
||||
header($this->httpString.' 206 Partial Content', true, 206);
|
||||
header("Content-Length: ".$length);
|
||||
header("Content-Range: bytes ".$this->start."-".$this->end."/".$this->size);
|
||||
}
|
||||
else
|
||||
{
|
||||
header("Accept-Ranges: bytes");
|
||||
header("Content-Length: ".$this->size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function end(){
|
||||
fclose($this->stream);
|
||||
exit;
|
||||
}
|
||||
|
||||
private function stream(){
|
||||
$i = $this->start;
|
||||
set_time_limit(0);
|
||||
while(!feof($this->stream) && $i <= $this->end) {
|
||||
$bytesToRead = $this->buffer;
|
||||
if(($i+$bytesToRead) > $this->end) {
|
||||
$bytesToRead = $this->end - $i + 1;
|
||||
}
|
||||
$data = fread($this->stream, $bytesToRead);
|
||||
echo $data;
|
||||
flush();
|
||||
$i += $bytesToRead;
|
||||
}
|
||||
}
|
||||
|
||||
function start(){
|
||||
$this->open();
|
||||
$this->setHeader();
|
||||
$this->stream();
|
||||
$this->end();
|
||||
}
|
||||
|
||||
function getContentLengthFromURL($url){
|
||||
$arrayHeaders = get_headers($url,true);
|
||||
$arrayHeaders = array_change_key_case($arrayHeaders, CASE_LOWER);
|
||||
if(isset($arrayHeaders['content-length'])){
|
||||
if(is_numeric($arrayHeaders['content-length']) && $arrayHeaders['content-length'] > 0){
|
||||
return $arrayHeaders['content-length'];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
class AddMonitorCommand implements CommandInterface
|
||||
{
|
||||
public function __construct(
|
||||
public string $userEmail,
|
||||
public string $userId,
|
||||
public string $title,
|
||||
public string $imdbId,
|
||||
public string $tmdbId,
|
||||
|
||||
@@ -22,7 +22,7 @@ readonly class AddMonitorHandler implements HandlerInterface
|
||||
|
||||
public function handle(CommandInterface $command): ResultInterface
|
||||
{
|
||||
$user = $this->userRepository->findOneBy(['email' => $command->userEmail]);
|
||||
$user = $this->userRepository->find($command->userId);
|
||||
$monitor = (new Monitor())
|
||||
->setUser($user)
|
||||
->setTmdbId($command->tmdbId)
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace App\Monitor\Action\Handler;
|
||||
|
||||
use App\Monitor\Action\Command\DownloadMediaCommand;
|
||||
use App\Download\Action\Command\DownloadMediaCommand;
|
||||
use App\Monitor\Action\Command\MonitorMovieCommand;
|
||||
use App\Monitor\Action\Result\MonitorMovieResult;
|
||||
use App\Monitor\Framework\Entity\Monitor;
|
||||
use App\Monitor\Framework\Repository\MonitorRepository;
|
||||
use App\Monitor\Service\MonitorOptionEvaluator;
|
||||
use App\Torrentio\Action\Command\GetMovieOptionsCommand;
|
||||
@@ -15,6 +16,7 @@ use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
use OneToMany\RichBundle\Contract\HandlerInterface;
|
||||
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
/** @implements HandlerInterface<MonitorMovieCommand> */
|
||||
@@ -27,11 +29,13 @@ readonly class MonitorMovieHandler implements HandlerInterface
|
||||
private EntityManagerInterface $entityManager,
|
||||
private MessageBusInterface $bus,
|
||||
private LoggerInterface $logger,
|
||||
private Security $security,
|
||||
) {}
|
||||
|
||||
public function handle(CommandInterface $command): ResultInterface
|
||||
{
|
||||
$this->logger->info('> [MonitorMovieHandler] Executing MonitorMovieHandler');
|
||||
/** @var Monitor $monitor */
|
||||
$monitor = $this->movieMonitorRepository->find($command->movieMonitorId);
|
||||
$monitor->setStatus('In Progress');
|
||||
|
||||
@@ -51,6 +55,7 @@ readonly class MonitorMovieHandler implements HandlerInterface
|
||||
$result->filename,
|
||||
'movies',
|
||||
$monitor->getImdbId(),
|
||||
$monitor->getUser()->getId(),
|
||||
));
|
||||
$monitor->setStatus('Complete');
|
||||
$monitor->setDownloadedAt(new DateTimeIMmutable());
|
||||
@@ -59,7 +64,7 @@ readonly class MonitorMovieHandler implements HandlerInterface
|
||||
}
|
||||
|
||||
$monitor->setLastSearch(new DateTimeImmutable());
|
||||
$monitor->setSearchCount($monitor->getSearchCount() + 1);
|
||||
$monitor->incrementSearchCount();
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new MonitorMovieResult(
|
||||
|
||||
@@ -58,6 +58,7 @@ readonly class MonitorTvEpisodeHandler implements HandlerInterface
|
||||
$result->filename,
|
||||
'tvshows',
|
||||
$monitor->getImdbId(),
|
||||
$monitor->getUser()->getId(),
|
||||
));
|
||||
$monitor->setStatus('Complete');
|
||||
$monitor->setDownloadedAt(new DateTimeImmutable());
|
||||
|
||||
@@ -12,7 +12,7 @@ class AddMonitorInput implements InputInterface
|
||||
{
|
||||
public function __construct(
|
||||
#[SourceSecurity]
|
||||
public string $userEmail,
|
||||
public int|string $userId,
|
||||
|
||||
#[SourceRequest('tmdbId')]
|
||||
public string $tmdbId,
|
||||
@@ -36,7 +36,7 @@ class AddMonitorInput implements InputInterface
|
||||
public function toCommand(): CommandInterface
|
||||
{
|
||||
return new AddMonitorCommand(
|
||||
$this->userEmail,
|
||||
$this->userId,
|
||||
$this->title,
|
||||
$this->imdbId,
|
||||
$this->tmdbId,
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Monitor\Framework\Controller;
|
||||
use App\Monitor\Action\Handler\AddMonitorHandler;
|
||||
use App\Monitor\Action\Input\AddMonitorInput;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\Mercure\HubInterface;
|
||||
use Symfony\Component\Mercure\Update;
|
||||
@@ -16,7 +17,6 @@ class ApiController extends AbstractController
|
||||
public function __construct(
|
||||
#[Autowire(service: 'twig')]
|
||||
private readonly Environment $renderer,
|
||||
private readonly HubInterface $hub,
|
||||
) {}
|
||||
|
||||
#[Route('/api/monitor', name: 'api_monitor', methods: ['POST'])]
|
||||
@@ -25,11 +25,13 @@ class ApiController extends AbstractController
|
||||
AddMonitorHandler $handler,
|
||||
HubInterface $hub,
|
||||
) {
|
||||
$response = $handler->handle($input->toCommand());
|
||||
$command = $input->toCommand();
|
||||
$command->userId = $this->getUser()->getId();
|
||||
$response = $handler->handle($command);
|
||||
|
||||
$hub->publish(new Update(
|
||||
'alerts',
|
||||
$this->renderer->render('broadcast/Alert.html.twig', [
|
||||
$this->renderer->render('broadcast/Alert.stream.html.twig', [
|
||||
'alert_id' => uniqid(),
|
||||
'title' => 'Success',
|
||||
'message' => "New monitor added for {$input->title}",
|
||||
|
||||
@@ -3,41 +3,34 @@
|
||||
namespace App\Monitor\Framework\Repository;
|
||||
|
||||
use App\Monitor\Framework\Entity\Monitor;
|
||||
use App\Util\Paginator;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Monitor>
|
||||
*/
|
||||
class MonitorRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
private Paginator $paginator;
|
||||
|
||||
public function __construct(ManagerRegistry $registry, Paginator $paginator)
|
||||
{
|
||||
parent::__construct($registry, Monitor::class);
|
||||
$this->paginator = $paginator;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return MovieMonitor[] Returns an array of MovieMonitor objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('m')
|
||||
// ->andWhere('m.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('m.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
public function getUserMonitorsPaginated(UserInterface $user, int $page, int $perPage)
|
||||
{
|
||||
$query = $this->createQueryBuilder('m')
|
||||
->andWhere('m.status IN (:statuses)')
|
||||
->andWhere('m.user = :user')
|
||||
->orderBy('m.id', 'ASC')
|
||||
->setParameter('statuses', ['Active', 'New', 'In Progress', 'Complete'])
|
||||
->setParameter('user', $user)
|
||||
->getQuery();
|
||||
|
||||
// public function findOneBySomeField($value): ?MovieMonitor
|
||||
// {
|
||||
// return $this->createQueryBuilder('m')
|
||||
// ->andWhere('m.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
return $this->paginator->paginate($query, $page, $perPage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Scheduler\Attribute\AsCronTask;
|
||||
|
||||
#[AsCronTask('*/10 * * * *', schedule: 'monitor')]
|
||||
#[AsCronTask('* * * * *', schedule: 'monitor')]
|
||||
class MonitorDispatcher
|
||||
{
|
||||
public function __construct(
|
||||
@@ -27,7 +27,7 @@ class MonitorDispatcher
|
||||
'movie' => MonitorMovieCommand::class,
|
||||
'tvepisode' => MonitorTvEpisodeCommand::class,
|
||||
'tvseason' => MonitorTvSeasonCommand::class,
|
||||
'tvshow' => MonitorTvShowCommand::class,
|
||||
'tvshows' => MonitorTvShowCommand::class,
|
||||
];
|
||||
|
||||
$monitors = $this->monitorRepository->findBy(['status' => ['New', 'Active']]);
|
||||
|
||||
@@ -32,6 +32,17 @@ class MediaFiles
|
||||
$this->filesystem = $filesystem;
|
||||
}
|
||||
|
||||
public function getPathByType(string $mediaType): string
|
||||
{
|
||||
if ('movies' === $mediaType) {
|
||||
return $this->moviesPath;
|
||||
} elseif ('tvshows' === $mediaType) {
|
||||
return $this->tvShowsPath;
|
||||
}
|
||||
|
||||
throw new \Exception(sprintf('A path for media type %s does not exist.', $mediaType));
|
||||
}
|
||||
|
||||
public function getMoviesPath(): string
|
||||
{
|
||||
return $this->moviesPath;
|
||||
@@ -83,4 +94,35 @@ class MediaFiles
|
||||
|
||||
return Map::from($results);
|
||||
}
|
||||
|
||||
public function createMovieDirectory(string $path): string
|
||||
{
|
||||
$path = $this->moviesPath . DIRECTORY_SEPARATOR . $path;
|
||||
|
||||
if (false === $this->filesystem->exists($path)) {
|
||||
$this->filesystem->mkdir($path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function createTvShowDirectory(string $path): string
|
||||
{
|
||||
$path = $this->tvShowsPath . DIRECTORY_SEPARATOR . $path;
|
||||
|
||||
if (false === $this->filesystem->exists($path)) {
|
||||
$this->filesystem->mkdir($path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function createDirectory(string $path): string
|
||||
{
|
||||
if (false === $this->filesystem->exists($path)) {
|
||||
$this->filesystem->mkdir($path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,15 @@ namespace App\Torrentio\Client;
|
||||
|
||||
use App\Torrentio\Client\Rule\DownloadOptionFilter\Resolution;
|
||||
use App\Torrentio\Client\Rule\RuleEngine;
|
||||
use App\Torrentio\MediaResult;
|
||||
use App\Torrentio\Result\ResultFactory;
|
||||
use Carbon\Carbon;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
||||
/**
|
||||
* ToDo: Fix
|
||||
*/
|
||||
class Torrentio
|
||||
{
|
||||
private string $baseUrl = 'https://torrentio.strem.fun/providers%253Dyts%252Ceztv%252Crarbg%252C1337x%252Cthepiratebay%252Ckickasstorrents%252Ctorrentgalaxy%252Cmagnetdl%252Chorriblesubs%252Cnyaasi%7Csort%253Dqualitysize%7Cqualityfilter%253D480p%252Cscr%252Ccam%7Crealdebrid={realDebridKey}/stream/movie/{imdbCode}.json';
|
||||
// private string $baseUrl = 'https://torrentio.strem.fun/providers=yts,eztv,rarbg,1337x,thepiratebay,kickasstorrents,torrentgalaxy,magnetdl,horriblesubs|sort=qualitysize|qualityfilter=480p,cam,unknown|debridoptions=nodownloadlinks|realdebrid=QYYBR7OSQ4VEFKWASDEZ2B4VO67KHUJY6IWOT7HHA7ATXO7QCYDQ/stream/{imdbCode}.json';
|
||||
|
||||
private string $searchUrl;
|
||||
|
||||
@@ -44,26 +39,6 @@ class Torrentio
|
||||
return $this->parse($results, $filter);
|
||||
}
|
||||
|
||||
public function searchBySeriesSeason(MediaResult $series): MediaResult
|
||||
{
|
||||
$imdbCode = $series->imdbId;
|
||||
// foreach ($series->episodes as $season => $episodes) {
|
||||
// foreach ($episodes as $key => $episode) {
|
||||
// $cacheKey = "torrentio.$series->imdbId.$season.{$episode['episode_number']}";
|
||||
// $downloadOptions = $this->cache->get($cacheKey, function (ItemInterface $item) use ($imdbCode, $season, $episode) {
|
||||
// $item->expiresAt(new \DateTimeImmutable("today 11:59 pm"));
|
||||
// $response = file_get_contents(str_replace('{imdbCode}', "$imdbCode:$season:{$episode['episode_number']}", $this->searchUrl));
|
||||
// return json_decode(
|
||||
// $response,
|
||||
// true
|
||||
// );
|
||||
// });
|
||||
// $series->episodes[$season][$key]['download_options'] = $this->parse($downloadOptions, []);
|
||||
// }
|
||||
// }
|
||||
return $series;
|
||||
}
|
||||
|
||||
public function fetchEpisodeResults(string $imdbId, int $season, int $episode): array
|
||||
{
|
||||
$cacheKey = "torrentio.$imdbId.$season.$episode";
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use App\Download\Framework\Repository\DownloadRepository;
|
||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveAction;
|
||||
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
||||
|
||||
#[AsLiveComponent]
|
||||
final class ActiveDownloadList
|
||||
{
|
||||
use DefaultActionTrait;
|
||||
|
||||
public function __construct(
|
||||
private DownloadRepository $downloadRepository,
|
||||
) {}
|
||||
|
||||
#[LiveAction]
|
||||
public function getDownloads()
|
||||
{
|
||||
return $this->downloadRepository->getActivePaginated();
|
||||
}
|
||||
}
|
||||
51
src/Twig/Components/DownloadList.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use App\Download\Framework\Repository\DownloadRepository;
|
||||
use App\Util\Paginator;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveAction;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveArg;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveProp;
|
||||
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
||||
|
||||
#[AsLiveComponent]
|
||||
final class DownloadList extends AbstractController
|
||||
{
|
||||
use DefaultActionTrait;
|
||||
|
||||
#[LiveProp(writable: true)]
|
||||
public string $type;
|
||||
|
||||
#[LiveProp(writable: true)]
|
||||
public int $pageNumber = 1;
|
||||
|
||||
#[LiveProp(writable: true)]
|
||||
public int $perPage = 5;
|
||||
|
||||
#[LiveProp(writable: true)]
|
||||
public bool $isWidget = true;
|
||||
|
||||
public function __construct(
|
||||
private readonly DownloadRepository $downloadRepository,
|
||||
) {}
|
||||
|
||||
public function getDownloads()
|
||||
{
|
||||
if ($this->type === "active") {
|
||||
return $this->downloadRepository->getActivePaginated($this->getUser(), $this->pageNumber, $this->perPage);
|
||||
} elseif ($this->type === "complete") {
|
||||
return $this->downloadRepository->getCompletePaginated($this->getUser(), $this->pageNumber, $this->perPage);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
#[LiveAction]
|
||||
public function paginate(#[LiveArg] int $page)
|
||||
{
|
||||
$this->pageNumber = $page;
|
||||
}
|
||||
}
|
||||
25
src/Twig/Components/MonitorList.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use App\Monitor\Framework\Repository\MonitorRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveAction;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveArg;
|
||||
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||
|
||||
#[AsTwigComponent]
|
||||
final class MonitorList extends AbstractController
|
||||
{
|
||||
public bool $isWidget = true;
|
||||
|
||||
public function __construct(
|
||||
private readonly MonitorRepository $monitorRepository,
|
||||
) {}
|
||||
|
||||
#[LiveAction]
|
||||
public function getUserMonitors(#[LiveArg] int $page = 1, #[LiveArg] int $perPage = 5)
|
||||
{
|
||||
return $this->monitorRepository->getUserMonitorsPaginated($this->getUser(), $page, $perPage);
|
||||
}
|
||||
}
|
||||
10
src/Twig/Components/StatusBadge.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||
|
||||
#[AsTwigComponent]
|
||||
final class StatusBadge
|
||||
{
|
||||
}
|
||||
10
src/Twig/Components/TextInput.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||
|
||||
#[AsTwigComponent]
|
||||
final class TextInput
|
||||
{
|
||||
}
|
||||
16
src/User/Action/Command/RegisterLdapUserCommand.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Command;
|
||||
|
||||
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
|
||||
/** @implements CommandInterface<RegisterUserCommand> */
|
||||
class RegisterLdapUserCommand implements CommandInterface
|
||||
{
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $email,
|
||||
public string $username,
|
||||
public string $password,
|
||||
) {}
|
||||
}
|
||||
16
src/User/Action/Command/RegisterUserCommand.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Command;
|
||||
|
||||
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
|
||||
/** @implements CommandInterface<RegisterUserCommand> */
|
||||
class RegisterUserCommand implements CommandInterface
|
||||
{
|
||||
public function __construct(
|
||||
public ?string $name = null,
|
||||
public ?string $email = null,
|
||||
public ?string $username = null,
|
||||
public ?string $password = null,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Command;
|
||||
|
||||
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
|
||||
/** @implements CommandInterface<SaveUserMediaPreferencesCommand> */
|
||||
class SaveUserDownloadPreferencesCommand implements CommandInterface
|
||||
{
|
||||
public function __construct(
|
||||
public string $movie_folder,
|
||||
) {}
|
||||
}
|
||||
57
src/User/Action/Handler/RegisterLdapUserHandler.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Handler;
|
||||
|
||||
use App\User\Action\Command\RegisterLdapUserCommand;
|
||||
use App\User\Action\Result\RegisterLdapUserResult;
|
||||
use App\User\Framework\Entity\User;
|
||||
use App\User\Framework\Entity\UserPreference;
|
||||
use App\User\Framework\Repository\PreferencesRepository;
|
||||
use App\User\Framework\Repository\UserRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface as C;
|
||||
use OneToMany\RichBundle\Contract\HandlerInterface;
|
||||
use OneToMany\RichBundle\Contract\ResultInterface as R;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
|
||||
/** @implements HandlerInterface<RegisterLdapUserCommand, RegisterLdapUserResult> */
|
||||
class RegisterLdapUserHandler implements HandlerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly PreferencesRepository $preferenceRepository,
|
||||
private readonly UserPasswordHasherInterface $userPasswordHasher,
|
||||
private readonly UserRepository $userRepository,
|
||||
) {}
|
||||
|
||||
public function handle(C $command): R
|
||||
{
|
||||
$user = $this->userRepository->findOneBy(['username' => $command->username]);
|
||||
if (null === $user) {
|
||||
$user = new User();
|
||||
$user->setPassword($this->userPasswordHasher->hashPassword($user, $command->password));
|
||||
}
|
||||
|
||||
$user->setUsername($command->username);
|
||||
$user->setEmail($command->email);
|
||||
$user->setName($command->name);
|
||||
$this->entityManager->persist($user);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->setUserPreferences($user, $this->preferenceRepository->findEnabled());
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new RegisterLdapUserResult($user);
|
||||
}
|
||||
|
||||
private function setUserPreferences(User $user, array $preferences): void
|
||||
{
|
||||
foreach ($preferences as $preference) {
|
||||
$user->addUserPreference((new UserPreference())
|
||||
->setUser($user)
|
||||
->setPreference($preference)
|
||||
->setPreferenceValue(null)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
src/User/Action/Handler/RegisterUserHandler.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Handler;
|
||||
|
||||
use App\User\Action\Command\RegisterUserCommand;
|
||||
use App\User\Action\Result\RegisterUserResult;
|
||||
use App\User\Action\Result\SaveUserMediaPreferencesResult;
|
||||
use App\User\Framework\Entity\User;
|
||||
use App\User\Framework\Entity\UserPreference;
|
||||
use App\User\Framework\Repository\PreferencesRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface as C;
|
||||
use OneToMany\RichBundle\Contract\HandlerInterface;
|
||||
use OneToMany\RichBundle\Contract\ResultInterface as R;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
|
||||
/** @implements HandlerInterface<RegisterUserCommand> */
|
||||
class RegisterUserHandler implements HandlerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly PreferencesRepository $preferenceRepository,
|
||||
private readonly UserPasswordHasherInterface $userPasswordHasher,
|
||||
) {}
|
||||
|
||||
public function handle(C $command): R
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$user->setUsername($command->username);
|
||||
$user->setEmail($command->email);
|
||||
$user->setPassword($this->userPasswordHasher->hashPassword($user, $command->password));
|
||||
$user->setName($command->name);
|
||||
$this->entityManager->persist($user);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->setUserPreferences($user, $this->preferenceRepository->findEnabled());
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new RegisterUserResult($user);
|
||||
}
|
||||
|
||||
private function setUserPreferences(User $user, array $preferences): void
|
||||
{
|
||||
foreach ($preferences as $preference) {
|
||||
$user->addUserPreference((new UserPreference())
|
||||
->setUser($user)
|
||||
->setPreference($preference)
|
||||
->setPreferenceValue(null)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Handler;
|
||||
|
||||
use App\User\Action\Command\SaveUserMediaPreferencesCommand;
|
||||
use App\User\Action\Result\SaveUserDownloadPreferencesResult;
|
||||
use App\User\Action\Result\SaveUserMediaPreferencesResult;
|
||||
use App\User\Framework\Entity\User;
|
||||
use App\User\Framework\Entity\UserPreference;
|
||||
use App\User\Framework\Repository\PreferencesRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface as C;
|
||||
use OneToMany\RichBundle\Contract\HandlerInterface;
|
||||
use OneToMany\RichBundle\Contract\ResultInterface as R;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
/** @implements HandlerInterface<SaveUserMediaPreferencesCommand> */
|
||||
class SaveUserDownloadPreferencesHandler implements HandlerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly PreferencesRepository $preferenceRepository,
|
||||
private readonly Security $token,
|
||||
) {}
|
||||
|
||||
public function handle(C $command): R
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->token->getUser();
|
||||
|
||||
foreach ($command as $preference => $value) {
|
||||
if ($user->hasUserPreference($preference)) {
|
||||
$user->updateUserPreference($preference, $value);
|
||||
$this->entityManager->flush();
|
||||
continue;
|
||||
}
|
||||
|
||||
$preference = $this->preferenceRepository->find($preference);
|
||||
|
||||
$user->addUserPreference(
|
||||
(new UserPreference())
|
||||
->setUser($user)
|
||||
->setPreference($preference)
|
||||
->setPreferenceValue($value)
|
||||
);
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new SaveUserDownloadPreferencesResult($user->getDownloadPreferences());
|
||||
}
|
||||
}
|
||||
28
src/User/Action/Input/SaveUserDownloadPreferencesInput.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Input;
|
||||
|
||||
use App\User\Action\Command\SaveUserDownloadPreferencesCommand;
|
||||
use OneToMany\RichBundle\Attribute\SourceRequest;
|
||||
use OneToMany\RichBundle\Attribute\SourceSecurity;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface as C;
|
||||
use OneToMany\RichBundle\Contract\InputInterface;
|
||||
|
||||
/** @implements InputInterface<SaveUserDownloadPreferencesInput, SaveUserDownloadPreferencesCommand> */
|
||||
class SaveUserDownloadPreferencesInput implements InputInterface
|
||||
{
|
||||
public function __construct(
|
||||
#[SourceSecurity]
|
||||
public mixed $userId,
|
||||
|
||||
#[SourceRequest('movie_folder', nullify: true)]
|
||||
public bool $movieFolder,
|
||||
) {}
|
||||
|
||||
public function toCommand(): C
|
||||
{
|
||||
return new SaveUserDownloadPreferencesCommand(
|
||||
$this->movieFolder,
|
||||
);
|
||||
}
|
||||
}
|
||||
14
src/User/Action/Result/RegisterLdapUserResult.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Result;
|
||||
|
||||
use App\User\Framework\Entity\User;
|
||||
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||
|
||||
/** @implements ResultInterface */
|
||||
class RegisterLdapUserResult implements ResultInterface
|
||||
{
|
||||
public function __construct(
|
||||
public User $user,
|
||||
) {}
|
||||
}
|
||||
14
src/User/Action/Result/RegisterUserResult.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Result;
|
||||
|
||||
use App\User\Framework\Entity\User;
|
||||
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||
|
||||
/** @implements ResultInterface */
|
||||
class RegisterUserResult implements ResultInterface
|
||||
{
|
||||
public function __construct(
|
||||
public User $user,
|
||||
) {}
|
||||
}
|
||||
14
src/User/Action/Result/SaveUserDownloadPreferencesResult.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Result;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||
|
||||
/** @implements ResultInterface */
|
||||
class SaveUserDownloadPreferencesResult implements ResultInterface
|
||||
{
|
||||
public function __construct(
|
||||
public array $downloadPreferences,
|
||||
) {}
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace App\User\Framework\Controller\Web;
|
||||
|
||||
use App\User\Action\Handler\RegisterUserHandler;
|
||||
use App\User\Framework\Repository\UserRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
@@ -10,8 +14,12 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
class LoginController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/login', name: 'app_login')]
|
||||
public function login(AuthenticationUtils $authenticationUtils): Response
|
||||
public function login(AuthenticationUtils $authenticationUtils, UserRepository $userRepository): Response
|
||||
{
|
||||
if ((new ArrayCollection($userRepository->findAll()))->count() === 0) {
|
||||
return $this->redirectToRoute('app_getting_started');
|
||||
}
|
||||
|
||||
// get the login error if there is one
|
||||
$error = $authenticationUtils->getLastAuthenticationError();
|
||||
|
||||
|
||||
@@ -4,18 +4,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\User\Framework\Controller\Web;
|
||||
|
||||
use Aimeos\Map;
|
||||
use App\User\Action\Handler\SaveUserDownloadPreferencesHandler;
|
||||
use App\User\Action\Handler\SaveUserMediaPreferencesHandler;
|
||||
use App\User\Action\Input\SaveUserDownloadPreferencesInput;
|
||||
use App\User\Action\Input\SaveUserMediaPreferencesInput;
|
||||
use App\User\Framework\Entity\User;
|
||||
use App\User\Framework\Entity\UserPreference;
|
||||
use App\User\Framework\Repository\PreferencesRepository;
|
||||
use App\Util\CountryCodes;
|
||||
use App\Util\CountryLanguages;
|
||||
use App\Util\ProviderList;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Mercure\HubInterface;
|
||||
use Symfony\Component\Mercure\Update;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class PreferencesController extends AbstractController
|
||||
@@ -23,21 +23,14 @@ class PreferencesController extends AbstractController
|
||||
public function __construct(
|
||||
private readonly PreferencesRepository $preferencesRepository,
|
||||
private readonly SaveUserMediaPreferencesHandler $saveUserMediaPreferencesHandler,
|
||||
private readonly Security $security,
|
||||
private readonly HubInterface $hub,
|
||||
private readonly SaveUserDownloadPreferencesHandler $saveUserDownloadPreferencesHandler,
|
||||
) {}
|
||||
#[Route('/media/preferences', 'app_media_preferences', methods: ['GET'])]
|
||||
#[Route('/user/preferences', 'app_user_preferences', methods: ['GET'])]
|
||||
public function mediaPreferences(): Response
|
||||
{
|
||||
$enabledPreferences = $this->preferencesRepository->findEnabled();
|
||||
|
||||
if ($this->security->getUser()->getUserPreferences()->count() !== count($enabledPreferences)) {
|
||||
$this->setUserPreferences($this->security->getUser(), $enabledPreferences);
|
||||
}
|
||||
|
||||
$userPreferences = $this->security->getUser()->getUserPreferences()->toArray();
|
||||
$userPreferences = Map::from($userPreferences)
|
||||
->rekey(fn($preference) => $preference->getPreference()->getId());
|
||||
|
||||
$mediaPreferences = $this->getUser()->getMediaPreferences();
|
||||
$downloadPreferences = $this->getUser()->getDownloadPreferences();
|
||||
$languages = CountryLanguages::$languages;
|
||||
sort($languages);
|
||||
|
||||
@@ -47,44 +40,76 @@ class PreferencesController extends AbstractController
|
||||
'preferences' => $this->preferencesRepository->findEnabled(),
|
||||
'languages' => $languages,
|
||||
'providers' => ProviderList::$providers,
|
||||
'userPreferences' => $userPreferences->toArray(),
|
||||
'mediaPreferences' => $mediaPreferences,
|
||||
'downloadPreferences' => $downloadPreferences,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[Route('/media/preferences', 'app_save_media_preferences', methods: ['POST'])]
|
||||
#[Route('/user/preferences/media', 'app_save_media_preferences', methods: ['POST'])]
|
||||
public function saveMediaPreferences(
|
||||
Request $request,
|
||||
SaveUserMediaPreferencesInput $input,
|
||||
): Response
|
||||
{
|
||||
$userPreferences = $this->saveUserMediaPreferencesHandler->handle($input->toCommand())->userPreferences;
|
||||
$userPreferences = Map::from($userPreferences)->rekey(fn($preference) => $preference->getPreference()->getId());
|
||||
$this->saveUserMediaPreferencesHandler->handle($input->toCommand());
|
||||
$mediaPreferences = $this->getUser()->getMediaPreferences();
|
||||
$downloadPreferences = $this->getUser()->getDownloadPreferences();
|
||||
|
||||
$languages = CountryLanguages::$languages;
|
||||
sort($languages);
|
||||
|
||||
$this->hub->publish(new Update(
|
||||
$request->getSession()->get('mercure_alert_topic'),
|
||||
$this->renderView('broadcast/Alert.stream.html.twig', [
|
||||
'alert_id' => uniqid(),
|
||||
'title' => 'Success',
|
||||
'message' => 'Your media preferences have been saved.',
|
||||
])
|
||||
));
|
||||
|
||||
return $this->render(
|
||||
'user/preferences.html.twig',
|
||||
[
|
||||
'preferences' => $this->preferencesRepository->findEnabled(),
|
||||
'languages' => $languages,
|
||||
'providers' => ProviderList::$providers,
|
||||
'userPreferences' => $userPreferences->toArray(),
|
||||
'mediaPreferences' => $mediaPreferences,
|
||||
'downloadPreferences' => $downloadPreferences,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function setUserPreferences(User $user, array $preferences): void
|
||||
#[Route('/user/preferences/download', 'app_save_download_preferences', methods: ['POST'])]
|
||||
public function saveDownloadPreferences(
|
||||
Request $request,
|
||||
SaveUserDownloadPreferencesInput $input,
|
||||
): Response
|
||||
{
|
||||
foreach ($preferences as $preference) {
|
||||
if (false === $user->hasUserPreference($preference->getId())) {
|
||||
$user->addUserPreference((new UserPreference())
|
||||
->setUser($user)
|
||||
->setPreference($preference)
|
||||
->setPreferenceValue(null)
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->preferencesRepository->getEntityManager()->flush();
|
||||
$downloadPreferences = $this->saveUserDownloadPreferencesHandler->handle($input->toCommand())->downloadPreferences;
|
||||
$mediaPreferences = $this->getUser()->getMediaPreferences();
|
||||
|
||||
$languages = CountryLanguages::$languages;
|
||||
sort($languages);
|
||||
|
||||
$this->hub->publish(new Update(
|
||||
$request->getSession()->get('mercure_alert_topic'),
|
||||
$this->renderView('broadcast/Alert.stream.html.twig', [
|
||||
'alert_id' => uniqid(),
|
||||
'title' => 'Success',
|
||||
'message' => 'Your download preferences have been saved.',
|
||||
])
|
||||
));
|
||||
|
||||
return $this->render(
|
||||
'user/preferences.html.twig',
|
||||
[
|
||||
'preferences' => $this->preferencesRepository->findEnabled(),
|
||||
'languages' => $languages,
|
||||
'providers' => ProviderList::$providers,
|
||||
'mediaPreferences' => $mediaPreferences,
|
||||
'downloadPreferences' => $downloadPreferences,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,43 +2,48 @@
|
||||
|
||||
namespace App\User\Framework\Controller\Web;
|
||||
|
||||
use App\User\Action\Command\RegisterUserCommand;
|
||||
use App\User\Action\Handler\RegisterUserHandler;
|
||||
use App\User\Framework\Entity\User;
|
||||
use App\User\Framework\Entity\UserPreference;
|
||||
use App\User\Framework\Form\RegistrationFormType;
|
||||
use App\User\Framework\Pipeline\GettingStarted\AddPreferencesToDatabase;
|
||||
use App\User\Framework\Pipeline\GettingStarted\GettingStartedInput;
|
||||
use App\User\Framework\Pipeline\GettingStarted\MigrateDatabase;
|
||||
use App\User\Framework\Repository\PreferencesRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\User\Framework\Repository\UserRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use League\Pipeline\Pipeline;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class RegistrationController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly RegisterUserHandler $registerUserHandler)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/register', name: 'app_register')]
|
||||
public function register(
|
||||
Request $request,
|
||||
UserPasswordHasherInterface $userPasswordHasher,
|
||||
EntityManagerInterface $entityManager,
|
||||
PreferencesRepository $preferencesRepository,
|
||||
Security $security,
|
||||
): Response {
|
||||
$user = new User();
|
||||
$form = $this->createForm(RegistrationFormType::class, $user);
|
||||
$form = $this->createForm(RegistrationFormType::class, new User());
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
/** @var string $plainPassword */
|
||||
$plainPassword = $form->get('plainPassword')->getData();
|
||||
$user = $this->registerUserHandler->handle(new RegisterUserCommand(
|
||||
name: $form->get('name')->getData(),
|
||||
email: $form->get('email')->getData(),
|
||||
username: $form->get('username')->getData(),
|
||||
password: $form->get('plainPassword')->getData(),
|
||||
));
|
||||
|
||||
// encode the plain password
|
||||
$user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword));
|
||||
|
||||
$entityManager->persist($user);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->setUserPreferences($user, $preferencesRepository->findEnabled());
|
||||
|
||||
$preferencesRepository->getEntityManager()->flush();
|
||||
$security->login($user->user);
|
||||
|
||||
return $this->redirectToRoute('app_index');
|
||||
}
|
||||
@@ -48,14 +53,30 @@ class RegistrationController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
private function setUserPreferences(User $user, array $preferences): void
|
||||
#[Route(path: '/getting-started', name: 'app_getting_started')]
|
||||
public function gettingStarted(Request $request, Security $security, UserRepository $userRepository, PreferencesRepository $preferencesRepository, KernelInterface $kernel, LoggerInterface $logger): Response
|
||||
{
|
||||
foreach ($preferences as $preference) {
|
||||
$user->addUserPreference((new UserPreference())
|
||||
->setUser($user)
|
||||
->setPreference($preference)
|
||||
->setPreferenceValue(null)
|
||||
);
|
||||
if ((new ArrayCollection($userRepository->findAll()))->count() !== 0) {
|
||||
return $this->redirectToRoute('app_index');
|
||||
}
|
||||
|
||||
$form = $this->createForm(RegistrationFormType::class, new User());
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$user = $this->registerUserHandler->handle(new RegisterUserCommand(
|
||||
name: $form->get('name')->getData(),
|
||||
email: $form->get('email')->getData(),
|
||||
password: $form->get('plainPassword')->getData(),
|
||||
));
|
||||
|
||||
$security->login($user->user);
|
||||
|
||||
return $this->redirectToRoute('app_index');
|
||||
}
|
||||
|
||||
return $this->render('user/getting-started.html.twig', [
|
||||
'registrationForm' => $form,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ class Preference
|
||||
#[ORM\Column]
|
||||
private ?string $id = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $type = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name = null;
|
||||
|
||||
@@ -44,6 +47,12 @@ class Preference
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setId(string $id): static
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setName(?string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
@@ -51,6 +60,17 @@ class Preference
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setType(string $type): static
|
||||
{
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\User\Framework\Entity;
|
||||
|
||||
use Aimeos\Map;
|
||||
use App\Download\Framework\Entity\Download;
|
||||
use App\Monitor\Framework\Entity\Monitor;
|
||||
use App\User\Framework\Repository\UserRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
@@ -22,6 +23,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private int $id;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 255, nullable: true)]
|
||||
private ?string $username;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 180, unique: true)]
|
||||
private ?string $email;
|
||||
|
||||
@@ -44,12 +48,19 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
* @var Collection<int, Monitor>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Monitor::class, mappedBy: 'user', orphanRemoval: true)]
|
||||
private Collection $yes;
|
||||
private Collection $monitors;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Download>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Download::class, mappedBy: 'user')]
|
||||
private Collection $downloads;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->userPreferences = new ArrayCollection();
|
||||
$this->yes = new ArrayCollection();
|
||||
$this->monitors = new ArrayCollection();
|
||||
$this->downloads = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -88,7 +99,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
*/
|
||||
public function getUserIdentifier(): string
|
||||
{
|
||||
return (string) $this->email;
|
||||
return (string) $this->username ?? $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,7 +204,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUserPreferenceValues()
|
||||
public function getUserPreferenceValues(string $type = 'all'): array
|
||||
{
|
||||
return Map::from($this->userPreferences)
|
||||
->rekey(fn(UserPreference $userPreference) => $userPreference->getPreference()->getId())
|
||||
@@ -202,7 +213,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
return $userPreference->getPreferenceValue();
|
||||
}
|
||||
foreach ($userPreference->getPreference()->getPreferenceOptions() as $preferenceOption) {
|
||||
// dd((int) $userPreference->getPreferenceValue(), $preferenceOption->getId(), $preferenceOption->getValue());
|
||||
if ($preferenceOption->getId() === (int) $userPreference->getPreferenceValue()) {
|
||||
return $preferenceOption->getValue();
|
||||
}
|
||||
@@ -215,30 +225,108 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
/**
|
||||
* @return Collection<int, Monitor>
|
||||
*/
|
||||
public function getYes(): Collection
|
||||
public function getMonitors(): Collection
|
||||
{
|
||||
return $this->yes;
|
||||
return $this->monitors;
|
||||
}
|
||||
|
||||
public function addYe(Monitor $ye): static
|
||||
public function addMonitor(Monitor $monitor): static
|
||||
{
|
||||
if (!$this->yes->contains($ye)) {
|
||||
$this->yes->add($ye);
|
||||
$ye->setUser($this);
|
||||
if (!$this->monitors->contains($monitor)) {
|
||||
$this->monitors->add($monitor);
|
||||
$monitor->setUser($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeYe(Monitor $ye): static
|
||||
public function removeMonitor(Monitor $monitor): static
|
||||
{
|
||||
if ($this->yes->removeElement($ye)) {
|
||||
if ($this->monitors->removeElement($monitor)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($ye->getUser() === $this) {
|
||||
$ye->setUser(null);
|
||||
if ($monitor->getUser() === $this) {
|
||||
$monitor->setUser(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUsername(): ?string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function setUsername(?string $username): static
|
||||
{
|
||||
$this->username = $username;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Download>
|
||||
*/
|
||||
public function getDownloads(): Collection
|
||||
{
|
||||
return $this->downloads;
|
||||
}
|
||||
|
||||
public function getMediaPreferences()
|
||||
{
|
||||
return Map::from($this->userPreferences)
|
||||
->rekey(fn(UserPreference $userPreference) => $userPreference->getPreference()->getId())
|
||||
->filter(fn(UserPreference $userPreference) => $userPreference->getPreference()->getType() === 'media')
|
||||
->toArray()
|
||||
;
|
||||
}
|
||||
|
||||
public function getDownloadPreferences()
|
||||
{
|
||||
return Map::from($this->userPreferences)
|
||||
->rekey(fn(UserPreference $userPreference) => $userPreference->getPreference()->getId())
|
||||
->filter(fn(UserPreference $userPreference) => $userPreference->getPreference()->getType() === 'download')
|
||||
->toArray()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Download>
|
||||
*/
|
||||
public function getActiveDownloads(): Collection
|
||||
{
|
||||
return $this->downloads->filter(fn(Download $download) => in_array($download->getStatus(), ['New', 'In Progress']));
|
||||
}
|
||||
|
||||
public function addDownload(Download $download): static
|
||||
{
|
||||
if (!$this->downloads->contains($download)) {
|
||||
$this->downloads->add($download);
|
||||
$download->setUser($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeDownload(Download $download): static
|
||||
{
|
||||
if ($this->downloads->removeElement($download)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($download->getUser() === $this) {
|
||||
$download->setUser(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function queryDownloads(string $type = 'complete', int $limit = 5)
|
||||
{
|
||||
if ($type === 'complete') {
|
||||
return $this->downloads->filter(fn($item) => in_array($item->getStatus(), ['Complete']))->slice(0, $limit);
|
||||
} elseif ($type === 'in-progress') {
|
||||
return $this->downloads->filter(fn($item) => in_array($item->getStatus(), ['New', 'In Progress']))->slice(0, $limit);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
73
src/User/Framework/Security/LdapAuthenticator.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Framework\Security;
|
||||
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
|
||||
|
||||
/**
|
||||
* @see https://symfony.com/doc/current/security/custom_authenticator.html
|
||||
*/
|
||||
class LdapAuthenticator extends AbstractAuthenticator
|
||||
{
|
||||
/**
|
||||
* Called on every request to decide if this authenticator should be
|
||||
* used for the request. Returning `false` will cause this authenticator
|
||||
* to be skipped.
|
||||
*/
|
||||
public function supports(Request $request): ?bool
|
||||
{
|
||||
// return $request->headers->has('X-AUTH-TOKEN');
|
||||
}
|
||||
|
||||
public function authenticate(Request $request): Passport
|
||||
{
|
||||
// $apiToken = $request->headers->get('X-AUTH-TOKEN');
|
||||
// if (null === $apiToken) {
|
||||
// The token header was empty, authentication fails with HTTP Status
|
||||
// Code 401 "Unauthorized"
|
||||
// throw new CustomUserMessageAuthenticationException('No API token provided');
|
||||
// }
|
||||
|
||||
// implement your own logic to get the user identifier from `$apiToken`
|
||||
// e.g. by looking up a user in the database using its API key
|
||||
// $userIdentifier = /** ... */;
|
||||
|
||||
// return new SelfValidatingPassport(new UserBadge($userIdentifier));
|
||||
}
|
||||
|
||||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
|
||||
{
|
||||
// on success, let the request continue
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
|
||||
{
|
||||
$data = [
|
||||
// you may want to customize or obfuscate the message first
|
||||
'message' => strtr($exception->getMessageKey(), $exception->getMessageData()),
|
||||
|
||||
// or to translate this message
|
||||
// $this->translator->trans($exception->getMessageKey(), $exception->getMessageData())
|
||||
];
|
||||
|
||||
return new JsonResponse($data, Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
// public function start(Request $request, ?AuthenticationException $authException = null): Response
|
||||
// {
|
||||
// /*
|
||||
// * If you would like this class to control what happens when an anonymous user accesses a
|
||||
// * protected page (e.g. redirect to /login), uncomment this method and make this class
|
||||
// * implement Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface.
|
||||
// *
|
||||
// * For more details, see https://symfony.com/doc/current/security/experimental_authenticators.html#configuring-the-authentication-entry-point
|
||||
// */
|
||||
// }
|
||||
}
|
||||
218
src/User/Framework/Security/LdapUserProvider.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\User\Framework\Security;
|
||||
|
||||
use App\User\Action\Command\RegisterLdapUserCommand;
|
||||
use App\User\Action\Handler\RegisterLdapUserHandler;
|
||||
use App\User\Framework\Entity\User;
|
||||
use App\User\Framework\Repository\UserRepository;
|
||||
use Symfony\Component\Ldap\Entry;
|
||||
use Symfony\Component\Ldap\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Ldap\Exception\InvalidCredentialsException;
|
||||
use Symfony\Component\Ldap\Exception\InvalidSearchCredentialsException;
|
||||
use Symfony\Component\Ldap\LdapInterface;
|
||||
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
||||
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||
use Symfony\Component\Ldap\Security\LdapUser;
|
||||
|
||||
/**
|
||||
* LdapUserProvider is a simple user provider on top of LDAP.
|
||||
*
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
* @author Charles Sarrazin <charles@sarraz.in>
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*
|
||||
* @template-implements UserProviderInterface<LdapUser>
|
||||
*/
|
||||
class LdapUserProvider implements UserProviderInterface, PasswordUpgraderInterface
|
||||
{
|
||||
private string $uidKey;
|
||||
private string $defaultSearch;
|
||||
private string $usernameAttribute;
|
||||
private string $emailAttribute;
|
||||
private string $displayNameAttribute;
|
||||
|
||||
public function __construct(
|
||||
private RegisterLdapUserHandler $registerLdapUserHandler,
|
||||
private UserRepository $userRepository,
|
||||
private LdapInterface $ldap,
|
||||
private string $baseDn,
|
||||
private ?string $searchDn = null,
|
||||
#[\SensitiveParameter] private ?string $searchPassword = null,
|
||||
private array $defaultRoles = [],
|
||||
?string $uidKey = null,
|
||||
?string $filter = null,
|
||||
private ?string $passwordAttribute = null,
|
||||
private array $extraFields = [],
|
||||
string $usernameAttribute = 'uid',
|
||||
string $emailAttribute = 'mail',
|
||||
string $displayNameAttribute = 'displayName',
|
||||
) {
|
||||
$uidKey ??= 'sAMAccountName';
|
||||
$filter ??= '({uid_key}={user_identifier})';
|
||||
|
||||
$this->uidKey = $uidKey;
|
||||
$this->defaultSearch = str_replace('{uid_key}', $uidKey, $filter);
|
||||
$this->usernameAttribute = $usernameAttribute;
|
||||
$this->emailAttribute = $emailAttribute;
|
||||
$this->displayNameAttribute = $displayNameAttribute;
|
||||
}
|
||||
|
||||
public function loadUserByIdentifier(string $identifier): UserInterface
|
||||
{
|
||||
try {
|
||||
$this->ldap->bind($this->searchDn, $this->searchPassword);
|
||||
} catch (InvalidCredentialsException) {
|
||||
throw new InvalidSearchCredentialsException();
|
||||
}
|
||||
|
||||
$identifier = $this->ldap->escape($identifier, '', LdapInterface::ESCAPE_FILTER);
|
||||
$query = str_replace('{user_identifier}', $identifier, $this->defaultSearch);
|
||||
$search = $this->ldap->query($this->baseDn, $query, ['filter' => 0 == \count($this->extraFields) ? '*' : $this->extraFields]);
|
||||
|
||||
$entries = $search->execute();
|
||||
$count = \count($entries);
|
||||
|
||||
if (!$count) {
|
||||
$e = new UserNotFoundException(\sprintf('User "%s" not found.', $identifier));
|
||||
$e->setUserIdentifier($identifier);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($count > 1) {
|
||||
$e = new UserNotFoundException('More than one user found.');
|
||||
$e->setUserIdentifier($identifier);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$entry = $entries[0];
|
||||
|
||||
try {
|
||||
$identifier = $this->getAttributeValue($entry, $this->uidKey);
|
||||
} catch (InvalidArgumentException) {
|
||||
// This is empty
|
||||
}
|
||||
|
||||
return $this->loadUser($identifier, $entry);
|
||||
}
|
||||
|
||||
public function refreshUser(UserInterface $user): UserInterface
|
||||
{
|
||||
if (!$user instanceof LdapUser) {
|
||||
throw new UnsupportedUserException(\sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
|
||||
}
|
||||
|
||||
return new LdapUser($user->getEntry(), $user->getUserIdentifier(), $user->getPassword(), $user->getRoles(), $user->getExtraFields());
|
||||
}
|
||||
|
||||
/**
|
||||
* @final
|
||||
*/
|
||||
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
|
||||
{
|
||||
if (!$user instanceof LdapUser) {
|
||||
throw new UnsupportedUserException(\sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
|
||||
}
|
||||
|
||||
if (null === $this->passwordAttribute) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$user->getEntry()->setAttribute($this->passwordAttribute, [$newHashedPassword]);
|
||||
$this->ldap->getEntryManager()->update($user->getEntry());
|
||||
$user->setPassword($newHashedPassword);
|
||||
} catch (ExceptionInterface) {
|
||||
// ignore failed password upgrades
|
||||
}
|
||||
}
|
||||
|
||||
public function supportsClass(string $class): bool
|
||||
{
|
||||
return User::class === $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a user from an LDAP entry.
|
||||
*/
|
||||
protected function loadUser(string $identifier, Entry $entry): UserInterface
|
||||
{
|
||||
$extraFields = [];
|
||||
|
||||
foreach ($this->extraFields as $field) {
|
||||
$extraFields[$field] = $this->getAttributeValue($entry, $field);
|
||||
}
|
||||
|
||||
$dbUser = $this->getDbUser($identifier, $entry);
|
||||
|
||||
if (null === $dbUser) {
|
||||
return $this->registerLdapUserHandler->handle(new RegisterLdapUserCommand(
|
||||
name:$this->getAttributeValue($entry, $this->displayNameAttribute)[0] ?? null,
|
||||
email:$this->getAttributeValue($entry, $this->emailAttribute)[0] ?? null,
|
||||
username:$this->getAttributeValue($entry, $this->usernameAttribute) ?? null,
|
||||
password: uniqid(),
|
||||
))->user;
|
||||
} else {
|
||||
$dbUser
|
||||
->setName($this->getAttributeValue($entry, $this->displayNameAttribute)[0] ?? null)
|
||||
->setEmail($this->getAttributeValue($entry, $this->emailAttribute)[0] ?? null)
|
||||
->setUsername($this->getAttributeValue($entry, $this->usernameAttribute) ?? null);
|
||||
$this->userRepository->getEntityManager()->flush();
|
||||
}
|
||||
|
||||
return $dbUser;
|
||||
}
|
||||
|
||||
/** @return User */
|
||||
private function getDbUser(string $identifier, Entry $entry): ?UserInterface
|
||||
{
|
||||
if (in_array($this->uidKey, ['mail', 'email'])) {
|
||||
$dbUser = $this->userRepository->findOneBy(['email' => $identifier]);
|
||||
} else {
|
||||
$dbUser = $this->userRepository->findOneBy(['username' => $identifier]);
|
||||
}
|
||||
|
||||
// Attempt to map LDAP user to existing user
|
||||
if (null === $dbUser) {
|
||||
if ($entry->hasAttribute($this->emailAttribute)) {
|
||||
$dbUser = $this->userRepository->findOneBy(['email' => $this->getAttributeValue($entry, $this->emailAttribute)]);;
|
||||
}
|
||||
}
|
||||
|
||||
return $dbUser;
|
||||
}
|
||||
|
||||
private function getAttributeValue(Entry $entry, string $attribute): mixed
|
||||
{
|
||||
if (!$entry->hasAttribute($attribute)) {
|
||||
throw new InvalidArgumentException(\sprintf('Missing attribute "%s" for user "%s".', $attribute, $entry->getDn()));
|
||||
}
|
||||
|
||||
$values = $entry->getAttribute($attribute);
|
||||
if (!\in_array($attribute, [$this->uidKey, $this->passwordAttribute])) {
|
||||
return $values;
|
||||
}
|
||||
|
||||
if (1 !== \count($values)) {
|
||||
throw new InvalidArgumentException(\sprintf('Attribute "%s" has multiple values.', $attribute));
|
||||
}
|
||||
|
||||
return $values[0];
|
||||
}
|
||||
}
|
||||
62
src/Util/Paginator.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Util;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator as OrmPaginator;
|
||||
|
||||
class Paginator
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
private $total;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
private $lastPage;
|
||||
|
||||
private $items;
|
||||
|
||||
public $currentPage = 1;
|
||||
|
||||
/**
|
||||
* @param QueryBuilder|Query $query
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return Paginator
|
||||
*/
|
||||
public function paginate($query, int $page = 1, int $limit = 5): Paginator
|
||||
{
|
||||
$paginator = new OrmPaginator($query);
|
||||
|
||||
$paginator
|
||||
->getQuery()
|
||||
->setFirstResult($limit * ($page - 1))
|
||||
->setMaxResults($limit);
|
||||
|
||||
$this->total = $paginator->count();
|
||||
$this->lastPage = (int) ceil($paginator->count() / $paginator->getQuery()->getMaxResults());
|
||||
$this->items = $paginator;
|
||||
$this->currentPage = $page;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTotal(): int
|
||||
{
|
||||
return $this->total;
|
||||
}
|
||||
|
||||
public function getLastPage(): int
|
||||
{
|
||||
return $this->lastPage;
|
||||
}
|
||||
|
||||
public function getItems()
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
}
|
||||
12
symfony.lock
@@ -16,6 +16,18 @@
|
||||
"src/Repository/.gitignore"
|
||||
]
|
||||
},
|
||||
"doctrine/doctrine-fixtures-bundle": {
|
||||
"version": "4.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "3.0",
|
||||
"ref": "1f5514cfa15b947298df4d771e694e578d4c204d"
|
||||
},
|
||||
"files": [
|
||||
"src/DataFixtures/AppFixtures.php"
|
||||
]
|
||||
},
|
||||
"doctrine/doctrine-migrations-bundle": {
|
||||
"version": "3.4",
|
||||
"recipe": {
|
||||
|
||||