Compare commits
94 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8004de1dc8 | |||
| 2d9a2a1f14 | |||
| b6bc1645b4 | |||
| 16023f1a26 | |||
| 725034dd4e | |||
| 234aeab120 | |||
| 044df00982 | |||
| 92015feaac | |||
| 5b704d9b36 | |||
| 4f72481829 | |||
| 4ee338e397 | |||
| 08d28d9a4f | |||
| b17313c8fb | |||
| f2b50b4f60 | |||
| 393e3ef41f | |||
| b1ccf3bf00 | |||
| 785794790c | |||
| c0f67a32ff | |||
| 325e4e14a7 | |||
| f9017297f3 | |||
| 0c4def42a2 | |||
| 3100912927 | |||
| 07553a172f | |||
| a88da4f637 | |||
| a88f128ccb | |||
| b1ec344f42 | |||
| 1ee6db4668 | |||
| 76bad88190 | |||
| a4029725f9 | |||
| aed3d92462 | |||
| 76531f397f | |||
| c763d67fcb | |||
| e85ae5ac95 | |||
| 794189d70a | |||
| 34d9029b7c | |||
| 168bf04550 | |||
| 81eb2d1f62 | |||
| f5102b859f | |||
| 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 |
9
.env
@@ -15,7 +15,7 @@
|
|||||||
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
|
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
|
||||||
|
|
||||||
###> symfony/framework-bundle ###
|
###> symfony/framework-bundle ###
|
||||||
APP_ENV=dev
|
APP_ENV=prod
|
||||||
APP_SECRET=
|
APP_SECRET=
|
||||||
###< symfony/framework-bundle ###
|
###< symfony/framework-bundle ###
|
||||||
|
|
||||||
@@ -26,12 +26,15 @@ APP_SECRET=
|
|||||||
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
|
# 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=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="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"
|
# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
||||||
###< doctrine/doctrine-bundle ###
|
|
||||||
|
|
||||||
|
###< doctrine/doctrine-bundle ###
|
||||||
|
MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!"
|
||||||
###> symfony/messenger ###
|
###> symfony/messenger ###
|
||||||
# Choose one of the transports below
|
# Choose one of the transports below
|
||||||
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
|
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
|
||||||
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
|
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
|
||||||
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
|
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
|
||||||
###< symfony/messenger ###
|
###< symfony/messenger ###
|
||||||
|
|
||||||
|
REDIS_HOST=redis://redis
|
||||||
|
|||||||
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="* * * * *"
|
|
||||||
31
.env.dist
@@ -1,31 +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%%"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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="cn=admins,cn=groups,cn=accounts,dc=caldwell,dc=local"
|
|
||||||
LDAP_EMAIL_ATTRIBUTE=mail
|
|
||||||
LDAP_USERNAME_ATTRIBUTE=uid
|
|
||||||
LDAP_NAME_ATTRIBUTE=displayname
|
|
||||||
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
.idea
|
.idea
|
||||||
|
bolt.db
|
||||||
###> symfony/framework-bundle ###
|
###> symfony/framework-bundle ###
|
||||||
/.env.local
|
/.env.local
|
||||||
/.env.local.php
|
/.env.local.php
|
||||||
|
|||||||
24
Dockerfile
@@ -1,10 +1,18 @@
|
|||||||
FROM registry.caldwell.digital/library/php:8.4-apache
|
FROM dunglas/frankenphp:php8.4-alpine
|
||||||
|
|
||||||
RUN apt-get update && \
|
ENV SERVER_NAME=":80"
|
||||||
apt-get install libldap2-dev -y && \
|
ENV CADDY_GLOBAL_OPTIONS="auto_https off"
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
ENV APP_RUNTIME="Runtime\\FrankenPhpSymfony\\Runtime"
|
||||||
docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
|
|
||||||
docker-php-ext-install ldap
|
|
||||||
|
|
||||||
COPY ./bash/vhost.conf /etc/apache2/sites-enabled/vhost.conf
|
RUN install-php-extensions \
|
||||||
RUN rm /etc/apache2/sites-enabled/000-default.conf
|
pdo_mysql \
|
||||||
|
gd \
|
||||||
|
intl \
|
||||||
|
zip \
|
||||||
|
opcache
|
||||||
|
|
||||||
|
RUN apk add --no-cache wget
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=3s --timeout=3s --retries=10 CMD [ "php", "/app/bin/console", "startup:status" ]
|
||||||
|
|
||||||
|
COPY docker/app/Caddyfile /etc/frankenphp/Caddyfile
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
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
|
|
||||||
RUN rm /etc/apache2/sites-enabled/000-default.conf
|
|
||||||
57
README.md
@@ -1,13 +1,50 @@
|
|||||||
# Caldwell Digital - Symfony Template
|
# Torsearch
|
||||||
Get up and running quickly with this Symfony framework template!
|
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
|
## Getting Started
|
||||||
1. Run `source bash/get_certs.sh` to grab the wildcard certs
|
1. Clone the repo
|
||||||
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`
|
|
||||||
|
|
||||||
## 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() {
|
download() {
|
||||||
fetch('/download', {
|
fetch('/api/download', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
48
assets/controllers/download_list_controller.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteDownload(data) {
|
||||||
|
fetch(`/api/download/${data.params.id}`, {method: 'DELETE'})
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(json => console.debug(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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,24 +0,0 @@
|
|||||||
import { Controller } from '@hotwired/stimulus';
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The following line makes this controller "lazy": it won't be downloaded until needed
|
|
||||||
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
|
||||||
*/
|
|
||||||
/* stimulusFetch: 'lazy' */
|
|
||||||
export default class extends Controller {
|
|
||||||
static values = {
|
|
||||||
title: String,
|
|
||||||
tmdbId: String,
|
|
||||||
imdbId: String,
|
|
||||||
mediaType: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
addMovieMonitor() {
|
|
||||||
console.log(`/monitor/movies/${this.tmdbIdValue}/${this.imdbIdValue}/${encodeURI(this.titleValue)}`)
|
|
||||||
fetch(`/monitor/movies/${this.tmdbIdValue}/${this.imdbIdValue}/${encodeURI(this.titleValue)}`)
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(json => {
|
|
||||||
console.log(json)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
14
assets/controllers/monitor_list_controller.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { Controller } from '@hotwired/stimulus';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following line makes this controller "lazy": it won't be downloaded until needed
|
||||||
|
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
||||||
|
*/
|
||||||
|
/* stimulusFetch: 'lazy' */
|
||||||
|
export default class extends Controller {
|
||||||
|
deleteMonitor(data) {
|
||||||
|
fetch(`/api/monitor/${data.params.id}`, {method: 'DELETE'})
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(json => console.debug(json));
|
||||||
|
}
|
||||||
|
}
|
||||||
1
assets/icons/ic/twotone-cancel.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="https://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="currentColor" d="M12 4c-4.41 0-8 3.59-8 8s3.59 8 8 8s8-3.59 8-8s-3.59-8-8-8m5 11.59L15.59 17L12 13.41L8.41 17L7 15.59L10.59 12L7 8.41L8.41 7L12 10.59L15.59 7L17 8.41L13.41 12z" opacity=".3"/><path fill="currentColor" d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10s10-4.47 10-10S17.53 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8s8 3.59 8 8s-3.59 8-8 8m3.59-13L12 10.59L8.41 7L7 8.41L10.59 12L7 15.59L8.41 17L12 13.41L15.59 17L17 15.59L13.41 12L17 8.41z"/></svg>
|
||||||
|
After Width: | Height: | Size: 526 B |
@@ -1,2 +0,0 @@
|
|||||||
# $1 = movies/tvshows/etc, $2 = title of media, $3 = URL of download
|
|
||||||
cd /var/download/${1} && if [ ! -d "${2}" ]; then mkdir "${2}"; fi && cd "${2}" && wget "${3}"
|
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
echo "> Building ${IMG} for linux/amd64"
|
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"
|
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}"
|
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
|
tls /etc/ssl/wildcard.crt /etc/ssl/wildcard.pem
|
||||||
|
|
||||||
reverse_proxy php:80
|
reverse_proxy app:80
|
||||||
|
|
||||||
|
|||||||
@@ -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"?>
|
<?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 -->
|
<!-- build dev for dev envs -->
|
||||||
<target name="build" depends="setEnv,composer,compileAssets,migrateDb,clearCache" />
|
<target name="build" depends="setEnv,composer,compileAssets,migrateDb,clearCache" />
|
||||||
|
|
||||||
<target name="composer" description="Run composer">
|
<target name="composer" description="Run composer">
|
||||||
<exec executable="composer">
|
<exec executable="composer">
|
||||||
<arg value="install" />
|
<arg value="install" />
|
||||||
|
<arg value="--ignore-platform-reqs" />
|
||||||
</exec>
|
</exec>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
|||||||
78
compose.yml
@@ -12,6 +12,41 @@ services:
|
|||||||
- $PWD/bash/caddy:/etc/caddy
|
- $PWD/bash/caddy:/etc/caddy
|
||||||
- $PWD/bash/certs:/etc/ssl
|
- $PWD/bash/certs:/etc/ssl
|
||||||
|
|
||||||
|
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- $PWD:/app
|
||||||
|
- mercure_data:/data
|
||||||
|
- mercure_config:/config
|
||||||
|
tty: true
|
||||||
|
environment:
|
||||||
|
MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
|
||||||
|
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
|
||||||
|
depends_on:
|
||||||
|
database:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
|
|
||||||
|
worker:
|
||||||
|
build: .
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- $PWD:/app
|
||||||
|
tty: true
|
||||||
|
command: php /app/bin/console messenger:consume async -vv --time-limit=3600 --limit=10
|
||||||
|
|
||||||
|
|
||||||
|
scheduler:
|
||||||
|
build: .
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- $PWD:/app
|
||||||
|
command: php /app/bin/console messenger:consume scheduler_monitor -vv
|
||||||
|
tty: true
|
||||||
|
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
volumes:
|
volumes:
|
||||||
@@ -19,42 +54,6 @@ services:
|
|||||||
command: redis-server --maxmemory 512MB
|
command: redis-server --maxmemory 512MB
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
php:
|
|
||||||
build: .
|
|
||||||
volumes:
|
|
||||||
- ./:/var/www
|
|
||||||
|
|
||||||
worker:
|
|
||||||
build: .
|
|
||||||
volumes:
|
|
||||||
- ./:/var/www
|
|
||||||
- ./var/download:/var/download
|
|
||||||
command: php ./bin/console messenger:consume async -vv --time-limit=3600
|
|
||||||
|
|
||||||
scheduler:
|
|
||||||
build: .
|
|
||||||
volumes:
|
|
||||||
- ./:/var/www
|
|
||||||
- ./var/download:/var/download
|
|
||||||
command: php ./bin/console messenger:consume scheduler_monitor -vv --time-limit=3600
|
|
||||||
|
|
||||||
mercure:
|
|
||||||
image: dunglas/mercure
|
|
||||||
restart: unless-stopped
|
|
||||||
ports:
|
|
||||||
- "3000: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:
|
database:
|
||||||
image: mariadb:10.11.2
|
image: mariadb:10.11.2
|
||||||
@@ -67,12 +66,19 @@ services:
|
|||||||
MYSQL_USERNAME: app
|
MYSQL_USERNAME: app
|
||||||
MYSQL_PASSWORD: password
|
MYSQL_PASSWORD: password
|
||||||
MYSQL_ROOT_PASSWORD: password
|
MYSQL_ROOT_PASSWORD: password
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
|
||||||
adminer:
|
adminer:
|
||||||
image: adminer
|
image: adminer
|
||||||
ports:
|
ports:
|
||||||
- "8081:8080"
|
- "8081:8080"
|
||||||
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
mysql:
|
mysql:
|
||||||
mercure_data:
|
mercure_data:
|
||||||
|
|||||||
@@ -11,37 +11,40 @@
|
|||||||
"aimeos/map": "^3.12",
|
"aimeos/map": "^3.12",
|
||||||
"doctrine/dbal": "^3",
|
"doctrine/dbal": "^3",
|
||||||
"doctrine/doctrine-bundle": "^2.14",
|
"doctrine/doctrine-bundle": "^2.14",
|
||||||
|
"doctrine/doctrine-fixtures-bundle": "^4.1",
|
||||||
"doctrine/doctrine-migrations-bundle": "^3.4",
|
"doctrine/doctrine-migrations-bundle": "^3.4",
|
||||||
"doctrine/orm": "^3.3",
|
"doctrine/orm": "^3.3",
|
||||||
"dragonmantank/cron-expression": "^3.4",
|
"dragonmantank/cron-expression": "^3.4",
|
||||||
|
"league/pipeline": "^1.1",
|
||||||
"nesbot/carbon": "^3.9",
|
"nesbot/carbon": "^3.9",
|
||||||
"nihilarr/parse-torrent-name": "^0.0.1",
|
"nihilarr/parse-torrent-name": "^0.0.1",
|
||||||
"nyholm/psr7": "*",
|
"nyholm/psr7": "*",
|
||||||
"p3k/emoji-detector": "^1.2",
|
"p3k/emoji-detector": "^1.2",
|
||||||
"php-tmdb/api": "^4.1",
|
"php-tmdb/api": "^4.1",
|
||||||
"predis/predis": "^2.4",
|
"predis/predis": "^2.4",
|
||||||
"symfony/asset": "7.2.*",
|
"runtime/frankenphp-symfony": "^0.2.0",
|
||||||
"symfony/console": "7.2.*",
|
"symfony/asset": "7.3.*",
|
||||||
"symfony/doctrine-messenger": "7.2.*",
|
"symfony/console": "7.3.*",
|
||||||
"symfony/dotenv": "7.2.*",
|
"symfony/doctrine-messenger": "7.3.*",
|
||||||
"symfony/filesystem": "7.2.*",
|
"symfony/dotenv": "7.3.*",
|
||||||
"symfony/finder": "7.2.*",
|
"symfony/filesystem": "7.3.*",
|
||||||
|
"symfony/finder": "7.3.*",
|
||||||
"symfony/flex": "^2",
|
"symfony/flex": "^2",
|
||||||
"symfony/form": "7.2.*",
|
"symfony/form": "7.3.*",
|
||||||
"symfony/framework-bundle": "7.2.*",
|
"symfony/framework-bundle": "7.3.*",
|
||||||
"symfony/ldap": "7.2.*",
|
"symfony/ldap": "7.3.*",
|
||||||
"symfony/mercure-bundle": "^0.3.9",
|
"symfony/mercure-bundle": "^0.3.9",
|
||||||
"symfony/messenger": "7.2.*",
|
"symfony/messenger": "7.3.*",
|
||||||
"symfony/runtime": "7.2.*",
|
"symfony/runtime": "7.3.*",
|
||||||
"symfony/scheduler": "7.2.*",
|
"symfony/scheduler": "7.3.*",
|
||||||
"symfony/security-bundle": "7.2.*",
|
"symfony/security-bundle": "7.3.*",
|
||||||
"symfony/stimulus-bundle": "^2.24",
|
"symfony/stimulus-bundle": "^2.24",
|
||||||
"symfony/twig-bundle": "7.2.*",
|
"symfony/twig-bundle": "7.3.*",
|
||||||
"symfony/ux-icons": "^2.24",
|
"symfony/ux-icons": "^2.24",
|
||||||
"symfony/ux-live-component": "^2.24",
|
"symfony/ux-live-component": "^2.24",
|
||||||
"symfony/ux-turbo": "^2.24",
|
"symfony/ux-turbo": "^2.24",
|
||||||
"symfony/ux-twig-component": "^2.24",
|
"symfony/ux-twig-component": "^2.24",
|
||||||
"symfony/yaml": "7.2.*",
|
"symfony/yaml": "7.3.*",
|
||||||
"symfonycasts/tailwind-bundle": "^0.10.0",
|
"symfonycasts/tailwind-bundle": "^0.10.0",
|
||||||
"twig/extra-bundle": "^2.12|^3.0",
|
"twig/extra-bundle": "^2.12|^3.0",
|
||||||
"twig/twig": "^2.12|^3.0"
|
"twig/twig": "^2.12|^3.0"
|
||||||
@@ -87,7 +90,7 @@
|
|||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
"@auto-scripts"
|
"@auto-scripts"
|
||||||
],
|
],
|
||||||
"sym": "docker compose exec php ./bin/console"
|
"sym": "docker compose exec app ./bin/console"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"symfony/symfony": "*"
|
"symfony/symfony": "*"
|
||||||
@@ -95,13 +98,13 @@
|
|||||||
"extra": {
|
"extra": {
|
||||||
"symfony": {
|
"symfony": {
|
||||||
"allow-contrib": false,
|
"allow-contrib": false,
|
||||||
"require": "7.2.*"
|
"require": "7.3.*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpstan/phpstan": "^2.1",
|
"phpstan/phpstan": "^2.1",
|
||||||
"symfony/maker-bundle": "^1.62",
|
"symfony/maker-bundle": "^1.62",
|
||||||
"symfony/stopwatch": "7.2.*",
|
"symfony/stopwatch": "7.3.*",
|
||||||
"symfony/web-profiler-bundle": "7.2.*"
|
"symfony/web-profiler-bundle": "7.3.*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1050
composer.lock
generated
@@ -17,4 +17,5 @@ return [
|
|||||||
Symfony\Bundle\MercureBundle\MercureBundle::class => ['all' => true],
|
Symfony\Bundle\MercureBundle\MercureBundle::class => ['all' => true],
|
||||||
Symfony\UX\Turbo\TurboBundle::class => ['all' => true],
|
Symfony\UX\Turbo\TurboBundle::class => ['all' => true],
|
||||||
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
|
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
|
||||||
|
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
|
||||||
];
|
];
|
||||||
|
|||||||
1
config/dist/ldap.security.yaml
vendored
@@ -38,6 +38,7 @@ security:
|
|||||||
# Easy way to control access for large sections of your site
|
# Easy way to control access for large sections of your site
|
||||||
# Note: Only the *first* access control that matches will be used
|
# Note: Only the *first* access control that matches will be used
|
||||||
access_control:
|
access_control:
|
||||||
|
- { path: ^/getting-started, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/register, roles: PUBLIC_ACCESS }
|
- { path: ^/register, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/login, roles: PUBLIC_ACCESS }
|
- { path: ^/login, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/, roles: ROLE_USER } # Or ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
- { path: ^/, roles: ROLE_USER } # Or ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
||||||
|
|||||||
1
config/dist/local.security.yaml
vendored
@@ -36,6 +36,7 @@ security:
|
|||||||
# Easy way to control access for large sections of your site
|
# Easy way to control access for large sections of your site
|
||||||
# Note: Only the *first* access control that matches will be used
|
# Note: Only the *first* access control that matches will be used
|
||||||
access_control:
|
access_control:
|
||||||
|
- { path: ^/getting-started, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/register, roles: PUBLIC_ACCESS }
|
- { path: ^/register, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/login, roles: PUBLIC_ACCESS }
|
- { path: ^/login, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/, roles: ROLE_USER } # Or ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
- { path: ^/, roles: ROLE_USER } # Or ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ framework:
|
|||||||
|
|
||||||
# Redis
|
# Redis
|
||||||
app: cache.adapter.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)
|
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
|
||||||
#app: cache.adapter.apcu
|
#app: cache.adapter.apcu
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
mercure:
|
mercure:
|
||||||
hubs:
|
hubs:
|
||||||
default:
|
default:
|
||||||
url: '%env(MERCURE_URL)%'
|
url: '%app.mercure.url%'
|
||||||
public_url: '%env(MERCURE_PUBLIC_URL)%'
|
public_url: '%app.mercure.public_url%'
|
||||||
jwt:
|
jwt:
|
||||||
secret: '%env(MERCURE_JWT_SECRET)%'
|
secret: '%env(MERCURE_JWT_SECRET)%'
|
||||||
publish: '*'
|
publish: '*'
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ framework:
|
|||||||
'App\Monitor\Action\Command\MonitorTvSeasonCommand': async
|
'App\Monitor\Action\Command\MonitorTvSeasonCommand': async
|
||||||
'App\Monitor\Action\Command\MonitorTvShowCommand': async
|
'App\Monitor\Action\Command\MonitorTvShowCommand': async
|
||||||
'App\Monitor\Action\Command\MonitorMovieCommand': async
|
'App\Monitor\Action\Command\MonitorMovieCommand': async
|
||||||
|
'App\Torrentio\Action\Command\GetTvShowOptionsCommand': async
|
||||||
|
|
||||||
# when@test:
|
# when@test:
|
||||||
# framework:
|
# framework:
|
||||||
|
|||||||
3
config/packages/property_info.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
framework:
|
||||||
|
property_info:
|
||||||
|
with_constructor_extractor: true
|
||||||
@@ -19,13 +19,11 @@ security:
|
|||||||
security: false
|
security: false
|
||||||
main:
|
main:
|
||||||
lazy: true
|
lazy: true
|
||||||
provider: app_ldap
|
provider: app_local
|
||||||
form_login_ldap:
|
form_login:
|
||||||
login_path: app_login
|
login_path: app_login
|
||||||
check_path: app_login
|
check_path: app_login
|
||||||
enable_csrf: true
|
enable_csrf: true
|
||||||
service: Symfony\Component\Ldap\Ldap
|
|
||||||
dn_string: '%env(LDAP_DN_STRING)%'
|
|
||||||
logout:
|
logout:
|
||||||
path: app_logout
|
path: app_logout
|
||||||
|
|
||||||
@@ -38,6 +36,7 @@ security:
|
|||||||
# Easy way to control access for large sections of your site
|
# Easy way to control access for large sections of your site
|
||||||
# Note: Only the *first* access control that matches will be used
|
# Note: Only the *first* access control that matches will be used
|
||||||
access_control:
|
access_control:
|
||||||
|
- { path: ^/getting-started, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/register, roles: PUBLIC_ACCESS }
|
- { path: ^/register, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/login, roles: PUBLIC_ACCESS }
|
- { path: ^/login, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/, roles: ROLE_USER } # Or ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
- { path: ^/, roles: ROLE_USER } # Or ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ controllersUser:
|
|||||||
defaults:
|
defaults:
|
||||||
schemes: ['https']
|
schemes: ['https']
|
||||||
|
|
||||||
|
controllersDownload:
|
||||||
|
resource:
|
||||||
|
path: ../src/Download/Framework/Controller
|
||||||
|
namespace: App\Download\Framework\Controller
|
||||||
|
type: attribute
|
||||||
|
defaults:
|
||||||
|
schemes: [ 'https' ]
|
||||||
|
|
||||||
controllersMonitor:
|
controllersMonitor:
|
||||||
resource:
|
resource:
|
||||||
path: ../src/Monitor/Framework/Controller
|
path: ../src/Monitor/Framework/Controller
|
||||||
|
|||||||
@@ -4,11 +4,22 @@
|
|||||||
# Put parameters here that don't need to change on each machine where the app is deployed
|
# 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
|
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
||||||
parameters:
|
parameters:
|
||||||
|
# Media
|
||||||
media.default_movies_dir: movies
|
media.default_movies_dir: movies
|
||||||
media.default_tvshows_dir: tvshows
|
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)%'
|
media.tvshows_path: '/var/download/%env(default:media.default_tvshows_dir:TVSHOWS_PATH)%'
|
||||||
|
|
||||||
|
# Mercure
|
||||||
|
app.mercure.url: 'http://app/.well-known/mercure'
|
||||||
|
app.mercure.public_url: '%env(APP_URL)%/.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:
|
services:
|
||||||
# default configuration for services in *this* file
|
# default configuration for services in *this* file
|
||||||
_defaults:
|
_defaults:
|
||||||
@@ -36,6 +47,7 @@ services:
|
|||||||
# LDAP
|
# LDAP
|
||||||
App\User\Framework\Security\LdapUserProvider:
|
App\User\Framework\Security\LdapUserProvider:
|
||||||
arguments:
|
arguments:
|
||||||
|
$registerLdapUserHandler: '@App\User\Action\Handler\RegisterLdapUserHandler'
|
||||||
$userRepository: '@App\User\Framework\Repository\UserRepository'
|
$userRepository: '@App\User\Framework\Repository\UserRepository'
|
||||||
$ldap: '@Symfony\Component\Ldap\LdapInterface'
|
$ldap: '@Symfony\Component\Ldap\LdapInterface'
|
||||||
$baseDn: '%env(LDAP_BASE_DN)%'
|
$baseDn: '%env(LDAP_BASE_DN)%'
|
||||||
|
|||||||
@@ -1,42 +1,57 @@
|
|||||||
services:
|
services:
|
||||||
php:
|
app:
|
||||||
image: registry.caldwell.digital/home/torsearch/app:${TAG}
|
image: registry.caldwell.digital/home/torsearch-app:${TAG}
|
||||||
ports:
|
ports:
|
||||||
- "8001:80"
|
- '8001:80'
|
||||||
deploy:
|
|
||||||
replicas: 2
|
|
||||||
|
|
||||||
worker:
|
|
||||||
image: registry.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
|
|
||||||
deploy:
|
|
||||||
replicas: 2
|
|
||||||
|
|
||||||
scheduler:
|
|
||||||
image: registry.caldwell.digital/home/torsearch/app:${TAG}
|
|
||||||
volumes:
|
|
||||||
- /mnt/media/downloads:/var/download
|
|
||||||
command: php ./bin/console messenger:consume scheduler_monitor -vv --time-limit=3600
|
|
||||||
|
|
||||||
mercure:
|
|
||||||
image: dunglas/mercure
|
|
||||||
restart: unless-stopped
|
|
||||||
ports:
|
|
||||||
- "3000:80"
|
|
||||||
environment:
|
environment:
|
||||||
SERVER_NAME: ':80'
|
|
||||||
MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
|
MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
|
||||||
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
|
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
|
||||||
MERCURE_EXTRA_DIRECTIVES: |
|
deploy:
|
||||||
cors_origins *
|
replicas: 2
|
||||||
anonymous
|
|
||||||
command: /usr/bin/caddy run --config /etc/caddy/dev.Caddyfile
|
|
||||||
volumes:
|
volumes:
|
||||||
|
- /mnt/media/downloads/movies:/var/download/movies
|
||||||
|
- /mnt/media/downloads/tvshows:/var/download/tvshows
|
||||||
- mercure_data:/data
|
- mercure_data:/data
|
||||||
- mercure_config:/config
|
- mercure_config:/config
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
|
|
||||||
|
|
||||||
|
worker:
|
||||||
|
image: registry.caldwell.digital/home/torsearch-worker:${TAG}
|
||||||
|
volumes:
|
||||||
|
- /mnt/media/downloads/movies:/var/download/movies
|
||||||
|
- /mnt/media/downloads/tvshows:/var/download/tvshows
|
||||||
|
restart: always
|
||||||
|
command: -vv --time-limit=3600 --limit=10
|
||||||
|
deploy:
|
||||||
|
replicas: 2
|
||||||
|
depends_on:
|
||||||
|
- app
|
||||||
|
|
||||||
|
|
||||||
|
scheduler:
|
||||||
|
image: registry.caldwell.digital/home/torsearch-scheduler:${TAG}
|
||||||
|
volumes:
|
||||||
|
- /mnt/media/downloads/movies:/var/download/movies
|
||||||
|
- /mnt/media/downloads/tvshows:/var/download/tvshows
|
||||||
|
restart: always
|
||||||
|
command: -vv
|
||||||
|
depends_on:
|
||||||
|
- app
|
||||||
|
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:latest
|
||||||
|
volumes:
|
||||||
|
- redis_data:/data
|
||||||
|
command: redis-server --maxmemory 512MB
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
|
mysql:
|
||||||
mercure_config:
|
mercure_config:
|
||||||
mercure_data:
|
mercure_data:
|
||||||
|
redis_data:
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ assets
|
|||||||
bash
|
bash
|
||||||
bin
|
bin
|
||||||
config
|
config
|
||||||
|
docker
|
||||||
migrations
|
migrations
|
||||||
public
|
public
|
||||||
src
|
src
|
||||||
|
|||||||
22
docker/Dockerfile.app
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
FROM dunglas/frankenphp
|
||||||
|
|
||||||
|
ENV SERVER_NAME=":80"
|
||||||
|
ENV CADDY_GLOBAL_OPTIONS="auto_https off"
|
||||||
|
ENV APP_RUNTIME="Runtime\\FrankenPhpSymfony\\Runtime"
|
||||||
|
|
||||||
|
RUN install-php-extensions \
|
||||||
|
pdo_mysql \
|
||||||
|
gd \
|
||||||
|
intl \
|
||||||
|
zip \
|
||||||
|
opcache
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
COPY --chmod=775 docker/app/entrypoint.sh /usr/local/bin/docker-entrypoint
|
||||||
|
COPY docker/app/Caddyfile /etc/frankenphp/Caddyfile
|
||||||
|
|
||||||
|
ENTRYPOINT [ "/usr/local/bin/docker-entrypoint" ]
|
||||||
|
|
||||||
|
CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile" ]
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=3s --timeout=3s --retries=10 CMD [ "php", "/app/bin/console", "startup:status" ]
|
||||||
18
docker/Dockerfile.scheduler
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
FROM dunglas/frankenphp:php8.4-alpine
|
||||||
|
|
||||||
|
ENV SERVER_NAME=":80"
|
||||||
|
ENV CADDY_GLOBAL_OPTIONS="auto_https off"
|
||||||
|
ENV APP_RUNTIME="Runtime\\FrankenPhpSymfony\\Runtime"
|
||||||
|
|
||||||
|
RUN install-php-extensions \
|
||||||
|
pdo_mysql \
|
||||||
|
gd \
|
||||||
|
intl \
|
||||||
|
zip \
|
||||||
|
opcache
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
ENTRYPOINT [ "php", "/app/bin/console", "messenger:consume", "scheduler_monitor" ]
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=3s --timeout=3s --retries=10 CMD return 0
|
||||||
20
docker/Dockerfile.worker
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
FROM dunglas/frankenphp:php8.4-alpine
|
||||||
|
|
||||||
|
ENV SERVER_NAME=":80"
|
||||||
|
ENV CADDY_GLOBAL_OPTIONS="auto_https off"
|
||||||
|
ENV APP_RUNTIME="Runtime\\FrankenPhpSymfony\\Runtime"
|
||||||
|
|
||||||
|
RUN install-php-extensions \
|
||||||
|
pdo_mysql \
|
||||||
|
gd \
|
||||||
|
intl \
|
||||||
|
zip \
|
||||||
|
opcache
|
||||||
|
|
||||||
|
RUN apk add --no-cache wget
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
ENTRYPOINT [ "php", "/app/bin/console", "messenger:consume", "async" ]
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=3s --timeout=3s --retries=10 CMD return 0
|
||||||
59
docker/app/Caddyfile
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
{$CADDY_GLOBAL_OPTIONS}
|
||||||
|
|
||||||
|
frankenphp {
|
||||||
|
{$FRANKENPHP_CONFIG}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{$CADDY_EXTRA_CONFIG}
|
||||||
|
|
||||||
|
{$SERVER_NAME:localhost} {
|
||||||
|
log {
|
||||||
|
{$CADDY_SERVER_LOG_OPTIONS}
|
||||||
|
# Redact the authorization query parameter that can be set by Mercure
|
||||||
|
format filter {
|
||||||
|
request>uri query {
|
||||||
|
replace authorization REDACTED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
root /app/public
|
||||||
|
encode zstd br gzip
|
||||||
|
|
||||||
|
mercure {
|
||||||
|
# Publisher JWT key
|
||||||
|
publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG}
|
||||||
|
# Subscriber JWT key
|
||||||
|
subscriber_jwt {env.MERCURE_SUBSCRIBER_JWT_KEY} {env.MERCURE_SUBSCRIBER_JWT_ALG}
|
||||||
|
# Allow anonymous subscribers (double-check that it's what you want)
|
||||||
|
anonymous
|
||||||
|
# Enable the subscription API (double-check that it's what you want)
|
||||||
|
subscriptions
|
||||||
|
# Custmo cors
|
||||||
|
cors_origins *
|
||||||
|
# Extra directives
|
||||||
|
{$MERCURE_EXTRA_DIRECTIVES}
|
||||||
|
}
|
||||||
|
|
||||||
|
vulcain
|
||||||
|
|
||||||
|
{$CADDY_SERVER_EXTRA_DIRECTIVES}
|
||||||
|
|
||||||
|
# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
|
||||||
|
header ?Permissions-Policy "browsing-topics=()"
|
||||||
|
|
||||||
|
@phpRoute {
|
||||||
|
not path /.well-known/mercure*
|
||||||
|
not file {path}
|
||||||
|
}
|
||||||
|
rewrite @phpRoute index.php
|
||||||
|
|
||||||
|
@frontController path index.php
|
||||||
|
php @frontController
|
||||||
|
|
||||||
|
file_server {
|
||||||
|
hide *.php
|
||||||
|
}
|
||||||
|
}
|
||||||
12
docker/app/entrypoint.sh
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Sleep for a second to ensure DB is awake and ready
|
||||||
|
SLEEP_TIME=$(shuf -i 2-4 -n 1)
|
||||||
|
echo "> Sleeping for ${SLEEP_TIME} seconds to wait for the database"
|
||||||
|
sleep $SLEEP_TIME
|
||||||
|
|
||||||
|
# Provision database
|
||||||
|
php /app/bin/console doctrine:migrations:migrate --no-interaction
|
||||||
|
php /app/bin/console db:seed
|
||||||
|
|
||||||
|
exec docker-php-entrypoint "$@"
|
||||||
57
docs/examples/.env
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# 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=
|
||||||
|
|
||||||
|
REAL_DEBRID_KEY="QYYBR7OSQ4VEFKWASDEZ2B4VO67KHUJY6IWOT7HHA7ATXO7QCYDQ"
|
||||||
|
TMDB_API=eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI0ZTJjYjJhOGUzOGJhNjdiNjVhOGU1NGM0ZWI1MzhmOCIsIm5iZiI6MTczNzkyNjA0NC41NjQsInN1YiI6IjY3OTZhNTljYzdiMDFiNzJjNzIzZWM5YiIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.e8DbNe9qrSBC1y-ANRv-VWBAtls-ZS2r7aNCiI68mpw
|
||||||
|
|
||||||
|
|
||||||
|
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: -vvv
|
||||||
|
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
|
||||||
|
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" ]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
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:
|
||||||
115
docs/examples/swarm.compose.yml
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
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'
|
||||||
|
configs:
|
||||||
|
- env_file
|
||||||
|
deploy:
|
||||||
|
replicas: 2
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
|
|
||||||
|
# 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
|
||||||
|
configs:
|
||||||
|
- source: env_file
|
||||||
|
target: /app/bin/.env.local
|
||||||
|
volumes:
|
||||||
|
- /mnt/media/downloads/movies:/var/download/movies
|
||||||
|
- /mnt/media/downloads/tvshows:/var/download/tvshows
|
||||||
|
restart: always
|
||||||
|
command: -vv
|
||||||
|
deploy:
|
||||||
|
replicas: 4
|
||||||
|
depends_on:
|
||||||
|
- app
|
||||||
|
|
||||||
|
# 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
|
||||||
|
configs:
|
||||||
|
- env_file
|
||||||
|
volumes:
|
||||||
|
- ./downloads:/var/download
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
- app
|
||||||
|
|
||||||
|
# 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" ]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
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:
|
||||||
|
|
||||||
|
configs:
|
||||||
|
env_file:
|
||||||
|
file: $PWD/.env
|
||||||
|
|
||||||
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/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);
|
||||||
|
}
|
||||||
|
}
|
||||||
129
nomad.deploy.hcl
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
variable "image_tag" {
|
||||||
|
type = string
|
||||||
|
description = "Docker image tag to deploy."
|
||||||
|
default = "latest"
|
||||||
|
}
|
||||||
|
|
||||||
|
job "torsearch" {
|
||||||
|
datacenters = [ "home" ]
|
||||||
|
type = "service"
|
||||||
|
|
||||||
|
group "app" {
|
||||||
|
count = 2
|
||||||
|
|
||||||
|
update {
|
||||||
|
max_parallel = 4
|
||||||
|
min_healthy_time = "30s"
|
||||||
|
healthy_deadline = "3m"
|
||||||
|
auto_revert = true
|
||||||
|
}
|
||||||
|
|
||||||
|
network {
|
||||||
|
port "app" {
|
||||||
|
to = 80
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task "app" {
|
||||||
|
driver = "docker"
|
||||||
|
|
||||||
|
config {
|
||||||
|
image = "registry.caldwell.digital/home/torsearch-app:${var.image_tag}"
|
||||||
|
ports = ["app"]
|
||||||
|
}
|
||||||
|
|
||||||
|
env {
|
||||||
|
MERCURE_PUBLISHER_JWT_KEY = "!ChangeThisMercureHubJWTSecretKey!"
|
||||||
|
MERCURE_SUBSCRIBER_JWT_KEY = "!ChangeThisMercureHubJWTSecretKey!"
|
||||||
|
}
|
||||||
|
|
||||||
|
service {
|
||||||
|
name = "torsearch-app"
|
||||||
|
provider = "nomad"
|
||||||
|
port = "app"
|
||||||
|
|
||||||
|
meta {
|
||||||
|
nomad_ingress_enabled = true
|
||||||
|
nomad_ingress_hostname = "torsearch-nomad.caldwell.digital"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
group "worker" {
|
||||||
|
count = 2
|
||||||
|
update {
|
||||||
|
max_parallel = 4
|
||||||
|
min_healthy_time = "30s"
|
||||||
|
healthy_deadline = "3m"
|
||||||
|
auto_revert = true
|
||||||
|
}
|
||||||
|
|
||||||
|
volume "media" {
|
||||||
|
type = "host"
|
||||||
|
source = "media"
|
||||||
|
read_only = false
|
||||||
|
}
|
||||||
|
|
||||||
|
task "worker" {
|
||||||
|
driver = "docker"
|
||||||
|
|
||||||
|
volume_mount {
|
||||||
|
volume = "media"
|
||||||
|
destination = "/var/download"
|
||||||
|
read_only = false
|
||||||
|
}
|
||||||
|
|
||||||
|
config {
|
||||||
|
image = "registry.caldwell.digital/home/torsearch-worker:${var.image_tag}"
|
||||||
|
args = [
|
||||||
|
"-vv"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
service {
|
||||||
|
name = "torsearch-worker"
|
||||||
|
provider = "nomad"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
group "scheduler" {
|
||||||
|
count = 1
|
||||||
|
|
||||||
|
update {
|
||||||
|
max_parallel = 2
|
||||||
|
min_healthy_time = "30s"
|
||||||
|
healthy_deadline = "3m"
|
||||||
|
auto_revert = true
|
||||||
|
}
|
||||||
|
|
||||||
|
volume "media" {
|
||||||
|
type = "host"
|
||||||
|
source = "media"
|
||||||
|
read_only = false
|
||||||
|
}
|
||||||
|
|
||||||
|
task "scheduler" {
|
||||||
|
driver = "docker"
|
||||||
|
|
||||||
|
volume_mount {
|
||||||
|
volume = "media"
|
||||||
|
destination = "/var/download"
|
||||||
|
read_only = false
|
||||||
|
}
|
||||||
|
|
||||||
|
config {
|
||||||
|
image = "registry.caldwell.digital/home/torsearch-scheduler:${var.image_tag}"
|
||||||
|
args = [
|
||||||
|
"-vv"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
service {
|
||||||
|
name = "torsearch-scheduler"
|
||||||
|
provider = "nomad"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,34 +2,25 @@
|
|||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Util\Broadcaster;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Mercure\HubInterface;
|
|
||||||
use Symfony\Component\Mercure\Update;
|
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Twig\Environment;
|
|
||||||
|
|
||||||
final class AlertController extends AbstractController
|
final class AlertController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(service: 'twig')] private readonly Environment $renderer,
|
private readonly Broadcaster $broadcaster,
|
||||||
private readonly HubInterface $hub,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/alert', name: 'app_alert')]
|
#[Route('/alert', name: 'app_alert')]
|
||||||
public function index(): Response
|
public function index(): Response
|
||||||
{
|
{
|
||||||
$update = new Update(
|
$this->broadcaster->alert(
|
||||||
'alerts',
|
'Added to queue',
|
||||||
$this->renderer->render('broadcast/Alert.html.twig', [
|
'This is a testy test!'
|
||||||
'alert_id' => 1,
|
|
||||||
'title' => 'Added to queue',
|
|
||||||
'message' => 'This is a testy test!',
|
|
||||||
])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->hub->publish($update);
|
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'Success' => 'Published'
|
'Success' => 'Published'
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -1,42 +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\Mercure\HubInterface;
|
|
||||||
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(
|
|
||||||
$this->getUser(),
|
|
||||||
$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\Download\Framework\Repository\DownloadRepository;
|
||||||
use App\Tmdb\Tmdb;
|
use App\Tmdb\Tmdb;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
@@ -16,9 +17,10 @@ final class IndexController extends AbstractController
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/', name: 'app_index')]
|
#[Route('/', name: 'app_index')]
|
||||||
public function index(): Response
|
public function index(Request $request): Response
|
||||||
{
|
{
|
||||||
// dd($this->getUser()->getActiveDownloads());
|
$request->getSession()->set('mercure_alert_topic', 'alerts_' . uniqid());
|
||||||
|
|
||||||
return $this->render('index/index.html.twig', [
|
return $this->render('index/index.html.twig', [
|
||||||
'active_downloads' => $this->getUser()->getActiveDownloads(),
|
'active_downloads' => $this->getUser()->getActiveDownloads(),
|
||||||
'recent_downloads' => $this->getUser()->getDownloads(),
|
'recent_downloads' => $this->getUser()->getDownloads(),
|
||||||
|
|||||||
@@ -6,18 +6,20 @@ use App\Search\Action\Handler\GetMediaInfoHandler;
|
|||||||
use App\Search\Action\Handler\SearchHandler;
|
use App\Search\Action\Handler\SearchHandler;
|
||||||
use App\Search\Action\Input\GetMediaInfoInput;
|
use App\Search\Action\Input\GetMediaInfoInput;
|
||||||
use App\Search\Action\Input\SearchInput;
|
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\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Symfony\Contracts\Cache\CacheInterface;
|
|
||||||
use Symfony\Contracts\Cache\ItemInterface;
|
|
||||||
|
|
||||||
final class SearchController extends AbstractController
|
final class SearchController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private SearchHandler $searchHandler,
|
private SearchHandler $searchHandler,
|
||||||
private GetMediaInfoHandler $getMediaInfoHandler,
|
private GetMediaInfoHandler $getMediaInfoHandler,
|
||||||
|
private MessageBusInterface $bus,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/search', name: 'app_search', methods: ['GET'])]
|
#[Route('/search', name: 'app_search', methods: ['GET'])]
|
||||||
@@ -36,6 +38,8 @@ final class SearchController extends AbstractController
|
|||||||
GetMediaInfoInput $input,
|
GetMediaInfoInput $input,
|
||||||
): Response {
|
): Response {
|
||||||
$result = $this->getMediaInfoHandler->handle($input->toCommand());
|
$result = $this->getMediaInfoHandler->handle($input->toCommand());
|
||||||
|
$this->warmDownloadOptionCache($result->media);
|
||||||
|
|
||||||
return $this->render('search/result.html.twig', [
|
return $this->render('search/result.html.twig', [
|
||||||
'results' => $result,
|
'results' => $result,
|
||||||
'filter' => [
|
'filter' => [
|
||||||
@@ -48,4 +52,32 @@ final class SearchController extends AbstractController
|
|||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ use App\Torrentio\Action\Handler\GetMovieOptionsHandler;
|
|||||||
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
||||||
use App\Torrentio\Action\Input\GetMovieOptionsInput;
|
use App\Torrentio\Action\Input\GetMovieOptionsInput;
|
||||||
use App\Torrentio\Action\Input\GetTvShowOptionsInput;
|
use App\Torrentio\Action\Input\GetTvShowOptionsInput;
|
||||||
|
use App\Util\Broadcaster;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Mercure\HubInterface;
|
|
||||||
use Symfony\Component\Mercure\Update;
|
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Symfony\Contracts\Cache\CacheInterface;
|
use Symfony\Contracts\Cache\CacheInterface;
|
||||||
use Symfony\Contracts\Cache\ItemInterface;
|
use Symfony\Contracts\Cache\ItemInterface;
|
||||||
@@ -20,8 +20,7 @@ final class TorrentioController extends AbstractController
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly GetMovieOptionsHandler $getMovieOptionsHandler,
|
private readonly GetMovieOptionsHandler $getMovieOptionsHandler,
|
||||||
private readonly GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
private readonly GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
||||||
private readonly HubInterface $hub,
|
private readonly Broadcaster $broadcaster,
|
||||||
private readonly \Twig\Environment $renderer,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/torrentio/movies/{tmdbId}/{imdbId}', name: 'app_torrentio_movies')]
|
#[Route('/torrentio/movies/{tmdbId}/{imdbId}', name: 'app_torrentio_movies')]
|
||||||
@@ -63,7 +62,7 @@ final class TorrentioController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/torrentio/tvshows/clear/{tmdbId}/{imdbId}/{season?}/{episode?}', name: 'app_clear_torrentio_tvshows')]
|
#[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(
|
$cacheId = sprintf(
|
||||||
"page.torrentio.tvshows.%s.%s.%s.%s",
|
"page.torrentio.tvshows.%s.%s.%s.%s",
|
||||||
@@ -74,14 +73,10 @@ final class TorrentioController extends AbstractController
|
|||||||
);
|
);
|
||||||
$cache->delete($cacheId);
|
$cache->delete($cacheId);
|
||||||
|
|
||||||
$this->hub->publish(new Update(
|
$this->broadcaster->alert(
|
||||||
'alerts',
|
title: 'Success',
|
||||||
$this->renderer->render('broadcast/Alert.html.twig', [
|
message: 'Torrentio cache Cleared.'
|
||||||
'alert_id' => uniqid(),
|
);
|
||||||
'title' => 'Success',
|
|
||||||
'message' => 'Torrentio cache Cleared.',
|
|
||||||
])
|
|
||||||
));
|
|
||||||
|
|
||||||
return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
||||||
$item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
$item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
||||||
|
|||||||
15
src/Download/Action/Command/DeleteDownloadCommand.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Download\Action\Command;
|
||||||
|
|
||||||
|
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @implements CommandInterface<DeleteDownloadCommand>
|
||||||
|
*/
|
||||||
|
class DeleteDownloadCommand implements CommandInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $downloadId,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
26
src/Download/Action/Handler/DeleteDownloadHandler.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Download\Action\Handler;
|
||||||
|
|
||||||
|
use App\Download\Action\Command\DeleteDownloadCommand;
|
||||||
|
use App\Download\Action\Result\DeleteDownloadResult;
|
||||||
|
use App\Download\Framework\Repository\DownloadRepository;
|
||||||
|
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||||
|
use OneToMany\RichBundle\Contract\HandlerInterface;
|
||||||
|
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||||
|
|
||||||
|
/** @implements HandlerInterface<DeleteDownloadCommand, DeleteDownloadResult> */
|
||||||
|
readonly class DeleteDownloadHandler implements HandlerInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private DownloadRepository $downloadRepository,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function handle(CommandInterface $command): ResultInterface
|
||||||
|
{
|
||||||
|
$download = $this->downloadRepository->find($command->downloadId);
|
||||||
|
$this->downloadRepository->delete($command->downloadId);
|
||||||
|
|
||||||
|
return new DeleteDownloadResult(200, 'Success', $download);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/Download/Action/Input/DeleteDownloadInput.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Download\Action\Input;
|
||||||
|
|
||||||
|
use App\Download\Action\Command\DeleteDownloadCommand;
|
||||||
|
use OneToMany\RichBundle\Attribute\SourceRoute;
|
||||||
|
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||||
|
use OneToMany\RichBundle\Contract\InputInterface;
|
||||||
|
|
||||||
|
/** @implements InputInterface<DeleteDownloadInput> */
|
||||||
|
class DeleteDownloadInput implements InputInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[SourceRoute('downloadId')]
|
||||||
|
public int $downloadId,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function toCommand(): CommandInterface
|
||||||
|
{
|
||||||
|
return new DeleteDownloadCommand(
|
||||||
|
$this->downloadId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,8 +39,8 @@ class DownloadMediaInput implements InputInterface
|
|||||||
$this->filename,
|
$this->filename,
|
||||||
$this->mediaType,
|
$this->mediaType,
|
||||||
$this->imdbId,
|
$this->imdbId,
|
||||||
|
$this->userId,
|
||||||
$this->downloadId,
|
$this->downloadId,
|
||||||
$this->userId
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
16
src/Download/Action/Result/DeleteDownloadResult.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Download\Action\Result;
|
||||||
|
|
||||||
|
use App\Download\Framework\Entity\Download;
|
||||||
|
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||||
|
|
||||||
|
/** @implements ResultInterface<DownloadMediaResult> */
|
||||||
|
class DeleteDownloadResult implements ResultInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $status,
|
||||||
|
public string $message,
|
||||||
|
public Download $download,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
@@ -10,11 +10,11 @@ use App\Message\DownloadTvShowMessage;
|
|||||||
interface DownloaderInterface
|
interface DownloaderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param string $baseDir
|
* @param string $mediaType
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @return void
|
* @return void
|
||||||
* Downloads the requested file.
|
* 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;
|
namespace App\Download\Downloader;
|
||||||
|
|
||||||
use App\Download\Framework\Entity\Download;
|
use App\Download\Framework\Entity\Download;
|
||||||
|
use App\Monitor\Service\MediaFiles;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
@@ -11,25 +12,26 @@ class ProcessDownloader implements DownloaderInterface
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private EntityManagerInterface $entityManager,
|
private EntityManagerInterface $entityManager,
|
||||||
|
private MediaFiles $mediaFiles,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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 */
|
/** @var Download $downloadEntity */
|
||||||
$downloadEntity = $this->entityManager->getRepository(Download::class)->find($downloadId);
|
$downloadEntity = $this->entityManager->getRepository(Download::class)->find($downloadId);
|
||||||
$downloadEntity->setProgress(0);
|
$downloadEntity->setProgress(0);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$process = new Process([
|
$downloadPreferences = $downloadEntity->getUser()->getDownloadPreferences();
|
||||||
'/bin/sh',
|
$path = $this->getDownloadPath($mediaType, $title, $downloadPreferences);
|
||||||
'/var/www/bash/app/wget_download.sh',
|
|
||||||
$baseDir,
|
$process = (new Process([
|
||||||
$title,
|
'wget',
|
||||||
$url
|
$url
|
||||||
]);
|
]))->setWorkingDirectory($path);
|
||||||
|
|
||||||
$process->setTimeout(1800); // 30 min
|
$process->setTimeout(1800); // 30 min
|
||||||
$process->setIdleTimeout(600); // 10 min
|
$process->setIdleTimeout(600); // 10 min
|
||||||
@@ -61,4 +63,20 @@ class ProcessDownloader implements DownloaderInterface
|
|||||||
|
|
||||||
$this->entityManager->flush();
|
$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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
68
src/Download/Framework/Controller/ApiController.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Download\Framework\Controller;
|
||||||
|
|
||||||
|
use App\Download\Action\Handler\DeleteDownloadHandler;
|
||||||
|
use App\Download\Action\Input\DeleteDownloadInput;
|
||||||
|
use App\Download\Action\Input\DownloadMediaInput;
|
||||||
|
use App\Download\Framework\Repository\DownloadRepository;
|
||||||
|
use App\Util\Broadcaster;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
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 Broadcaster $broadcaster,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#[Route('/api/download', name: 'api_download', methods: ['POST'])]
|
||||||
|
public function download(
|
||||||
|
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->broadcaster->alert(
|
||||||
|
title: 'Success',
|
||||||
|
message: "$input->title added to Queue."
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->json(['status' => 200, 'message' => 'Added to Queue']);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/api/download/{downloadId}', name: 'api_download_delete', methods: ['DELETE'])]
|
||||||
|
public function deleteDownload(
|
||||||
|
DeleteDownloadInput $input,
|
||||||
|
DeleteDownloadHandler $handler,
|
||||||
|
): Response {
|
||||||
|
$result = $handler->handle($input->toCommand());
|
||||||
|
$this->broadcaster->alert(
|
||||||
|
title: 'Success',
|
||||||
|
message: "{$result->download->getTitle()} has been deleted.",
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->json(['status' => 200, 'message' => 'Download Deleted']);
|
||||||
|
}
|
||||||
|
}
|
||||||
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,9 @@ namespace App\Download\Framework\Repository;
|
|||||||
|
|
||||||
use App\Download\Framework\Entity\Download;
|
use App\Download\Framework\Entity\Download;
|
||||||
use App\User\Framework\Entity\User;
|
use App\User\Framework\Entity\User;
|
||||||
|
use App\Util\Paginator;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
use Knp\Component\Pager\Paginator;
|
|
||||||
use Knp\Component\Pager\PaginatorInterface;
|
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,38 +16,39 @@ class DownloadRepository extends ServiceEntityRepository
|
|||||||
{
|
{
|
||||||
private ManagerRegistry $managerRegistry;
|
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);
|
parent::__construct($registry, Download::class);
|
||||||
$this->managerRegistry = $managerRegistry;
|
$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): Paginator
|
||||||
{
|
{
|
||||||
$firstResult = ($pageNumber - 1) * $perPage;
|
|
||||||
$query = $this->createQueryBuilder('d')
|
$query = $this->createQueryBuilder('d')
|
||||||
->andWhere('d.status IN (:statuses)')
|
->andWhere('d.status IN (:statuses)')
|
||||||
|
->andWhere('d.user = :user')
|
||||||
->orderBy('d.id', 'DESC')
|
->orderBy('d.id', 'DESC')
|
||||||
->setParameter('statuses', ['Complete'])
|
->setParameter('statuses', ['Complete'])
|
||||||
->setFirstResult($firstResult)
|
->setParameter('user', $user)
|
||||||
->setMaxResults($perPage)
|
|
||||||
->getQuery();
|
->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): Paginator
|
||||||
{
|
{
|
||||||
$firstResult = ($pageNumber - 1) * $perPage;
|
|
||||||
$query = $this->createQueryBuilder('d')
|
$query = $this->createQueryBuilder('d')
|
||||||
->andWhere('d.status IN (:statuses)')
|
->andWhere('d.status IN (:statuses)')
|
||||||
|
->andWhere('d.user = :user')
|
||||||
->orderBy('d.id', 'ASC')
|
->orderBy('d.id', 'ASC')
|
||||||
->setParameter('statuses', ['New', 'In Progress'])
|
->setParameter('statuses', ['New', 'In Progress'])
|
||||||
->setFirstResult($firstResult)
|
->setParameter('user', $user)
|
||||||
->setMaxResults($perPage)
|
|
||||||
->getQuery();
|
->getQuery();
|
||||||
|
|
||||||
return new \Doctrine\ORM\Tools\Pagination\Paginator($query);
|
return $this->paginator->paginate($query, $pageNumber, $perPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insert(
|
public function insert(
|
||||||
|
|||||||
13
src/Monitor/Action/Command/DeleteMonitorCommand.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Monitor\Action\Command;
|
||||||
|
|
||||||
|
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||||
|
|
||||||
|
/** @implements CommandInterface<DeleteMonitorCommand> */
|
||||||
|
class DeleteMonitorCommand implements CommandInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public string $monitorId,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
36
src/Monitor/Action/Handler/DeleteMonitorHandler.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Monitor\Action\Handler;
|
||||||
|
|
||||||
|
use App\Monitor\Action\Command\AddMonitorCommand;
|
||||||
|
use App\Monitor\Action\Command\DeleteMonitorCommand;
|
||||||
|
use App\Monitor\Action\Result\AddMonitorResult;
|
||||||
|
use App\Monitor\Action\Result\DeleteMonitorResult;
|
||||||
|
use App\Monitor\Framework\Entity\Monitor;
|
||||||
|
use App\Monitor\Framework\Repository\MonitorRepository;
|
||||||
|
use App\User\Framework\Repository\UserRepository;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||||
|
use OneToMany\RichBundle\Contract\HandlerInterface;
|
||||||
|
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||||
|
|
||||||
|
/** @implements HandlerInterface<DeleteMonitorCommand, DeleteMonitorResult> */
|
||||||
|
readonly class DeleteMonitorHandler implements HandlerInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private MonitorRepository $monitorRepository,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function handle(CommandInterface $command): ResultInterface
|
||||||
|
{
|
||||||
|
$monitor = $this->monitorRepository->find($command->monitorId);
|
||||||
|
$this->monitorRepository->getEntityManager()->remove($monitor);
|
||||||
|
$this->monitorRepository->getEntityManager()->flush();
|
||||||
|
|
||||||
|
return new DeleteMonitorResult(
|
||||||
|
status: 'OK',
|
||||||
|
result: [],
|
||||||
|
monitor: $monitor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/Monitor/Action/Input/DeleteMonitorInput.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Monitor\Action\Input;
|
||||||
|
|
||||||
|
use App\Monitor\Action\Command\DeleteMonitorCommand;
|
||||||
|
use OneToMany\RichBundle\Attribute\SourceRoute;
|
||||||
|
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||||
|
use OneToMany\RichBundle\Contract\InputInterface;
|
||||||
|
|
||||||
|
/** @implements InputInterface<DeleteMonitorInput, DeleteMonitorCommand> */
|
||||||
|
class DeleteMonitorInput implements InputInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[SourceRoute('monitorId')]
|
||||||
|
public int $monitorId,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function toCommand(): CommandInterface
|
||||||
|
{
|
||||||
|
return new DeleteMonitorCommand(
|
||||||
|
$this->monitorId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/Monitor/Action/Result/DeleteMonitorResult.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Monitor\Action\Result;
|
||||||
|
|
||||||
|
use App\Monitor\Framework\Entity\Monitor;
|
||||||
|
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||||
|
|
||||||
|
class DeleteMonitorResult implements ResultInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public string $status,
|
||||||
|
public array $result,
|
||||||
|
public Monitor $monitor,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
@@ -2,23 +2,23 @@
|
|||||||
|
|
||||||
namespace App\Monitor\Framework\Controller;
|
namespace App\Monitor\Framework\Controller;
|
||||||
|
|
||||||
|
use App\Download\Action\Input\DeleteDownloadInput;
|
||||||
use App\Monitor\Action\Handler\AddMonitorHandler;
|
use App\Monitor\Action\Handler\AddMonitorHandler;
|
||||||
|
use App\Monitor\Action\Handler\DeleteMonitorHandler;
|
||||||
use App\Monitor\Action\Input\AddMonitorInput;
|
use App\Monitor\Action\Input\AddMonitorInput;
|
||||||
|
use App\Monitor\Action\Input\DeleteMonitorInput;
|
||||||
|
use App\Util\Broadcaster;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\Mercure\HubInterface;
|
use Symfony\Component\Mercure\HubInterface;
|
||||||
use Symfony\Component\Mercure\Update;
|
use Symfony\Component\Mercure\Update;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Twig\Environment;
|
|
||||||
|
|
||||||
class ApiController extends AbstractController
|
class ApiController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(service: 'twig')]
|
private readonly Broadcaster $broadcaster,
|
||||||
private readonly Environment $renderer,
|
|
||||||
private readonly HubInterface $hub,
|
|
||||||
private readonly Security $security,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/api/monitor', name: 'api_monitor', methods: ['POST'])]
|
#[Route('/api/monitor', name: 'api_monitor', methods: ['POST'])]
|
||||||
@@ -28,15 +28,34 @@ class ApiController extends AbstractController
|
|||||||
HubInterface $hub,
|
HubInterface $hub,
|
||||||
) {
|
) {
|
||||||
$command = $input->toCommand();
|
$command = $input->toCommand();
|
||||||
$command->userId = $this->security->getUser()->getId();
|
$command->userId = $this->getUser()->getId();
|
||||||
$response = $handler->handle($command);
|
$response = $handler->handle($command);
|
||||||
|
|
||||||
|
$this->broadcaster->alert(
|
||||||
|
title: 'Success',
|
||||||
|
message: "New monitor added for {$input->title}",
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->json([
|
||||||
|
'status' => 200,
|
||||||
|
'message' => $response
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/api/monitor/{monitorId}', name: 'api_monitor_delete', methods: ['DELETE'])]
|
||||||
|
public function deleteMonitor(
|
||||||
|
DeleteMonitorInput $input,
|
||||||
|
DeleteMonitorHandler $handler,
|
||||||
|
HubInterface $hub,
|
||||||
|
) {
|
||||||
|
$response = $handler->handle($input->toCommand());
|
||||||
|
|
||||||
$hub->publish(new Update(
|
$hub->publish(new Update(
|
||||||
'alerts',
|
'alerts',
|
||||||
$this->renderer->render('broadcast/Alert.html.twig', [
|
$this->renderer->render('broadcast/Alert.stream.html.twig', [
|
||||||
'alert_id' => uniqid(),
|
'alert_id' => uniqid(),
|
||||||
'title' => 'Success',
|
'title' => 'Success',
|
||||||
'message' => "New monitor added for {$input->title}",
|
'message' => "New monitor added for {$response->monitor->getTitle()}",
|
||||||
])
|
])
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
31
src/Monitor/Framework/Controller/WebController.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Monitor\Framework\Controller;
|
||||||
|
|
||||||
|
use App\Download\Action\Input\DeleteDownloadInput;
|
||||||
|
use App\Monitor\Action\Handler\AddMonitorHandler;
|
||||||
|
use App\Monitor\Action\Handler\DeleteMonitorHandler;
|
||||||
|
use App\Monitor\Action\Input\AddMonitorInput;
|
||||||
|
use App\Monitor\Action\Input\DeleteMonitorInput;
|
||||||
|
use App\Monitor\Framework\Repository\MonitorRepository;
|
||||||
|
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;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
class WebController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[Autowire(service: 'twig')]
|
||||||
|
private readonly Environment $renderer,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#[Route('/monitors', name: 'app_monitors', methods: ['GET'])]
|
||||||
|
public function addMonitor()
|
||||||
|
{
|
||||||
|
return $this->render('monitor/index.html.twig');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,9 @@ use App\User\Framework\Entity\User;
|
|||||||
use Doctrine\DBAL\Types\Types;
|
use Doctrine\DBAL\Types\Types;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Serializer\Attribute\Ignore;
|
use Symfony\Component\Serializer\Attribute\Ignore;
|
||||||
|
use Symfony\UX\Turbo\Attribute\Broadcast;
|
||||||
|
|
||||||
|
#[Broadcast(template: 'broadcast/Monitor.stream.html.twig')]
|
||||||
#[ORM\Entity(repositoryClass: MonitorRepository::class)]
|
#[ORM\Entity(repositoryClass: MonitorRepository::class)]
|
||||||
class Monitor
|
class Monitor
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,41 +3,34 @@
|
|||||||
namespace App\Monitor\Framework\Repository;
|
namespace App\Monitor\Framework\Repository;
|
||||||
|
|
||||||
use App\Monitor\Framework\Entity\Monitor;
|
use App\Monitor\Framework\Entity\Monitor;
|
||||||
|
use App\Util\Paginator;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends ServiceEntityRepository<Monitor>
|
* @extends ServiceEntityRepository<Monitor>
|
||||||
*/
|
*/
|
||||||
class MonitorRepository extends ServiceEntityRepository
|
class MonitorRepository extends ServiceEntityRepository
|
||||||
{
|
{
|
||||||
public function __construct(ManagerRegistry $registry)
|
private Paginator $paginator;
|
||||||
|
|
||||||
|
public function __construct(ManagerRegistry $registry, Paginator $paginator)
|
||||||
{
|
{
|
||||||
parent::__construct($registry, Monitor::class);
|
parent::__construct($registry, Monitor::class);
|
||||||
|
$this->paginator = $paginator;
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
public function getUserMonitorsPaginated(UserInterface $user, int $page, int $perPage): Paginator
|
||||||
// * @return MovieMonitor[] Returns an array of MovieMonitor objects
|
{
|
||||||
// */
|
$query = $this->createQueryBuilder('m')
|
||||||
// public function findByExampleField($value): array
|
->andWhere('m.status IN (:statuses)')
|
||||||
// {
|
->andWhere('m.user = :user')
|
||||||
// return $this->createQueryBuilder('m')
|
->orderBy('m.id', 'ASC')
|
||||||
// ->andWhere('m.exampleField = :val')
|
->setParameter('statuses', ['Active', 'New', 'In Progress', 'Complete'])
|
||||||
// ->setParameter('val', $value)
|
->setParameter('user', $user)
|
||||||
// ->orderBy('m.id', 'ASC')
|
->getQuery();
|
||||||
// ->setMaxResults(10)
|
|
||||||
// ->getQuery()
|
|
||||||
// ->getResult()
|
|
||||||
// ;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public function findOneBySomeField($value): ?MovieMonitor
|
return $this->paginator->paginate($query, $page, $perPage);
|
||||||
// {
|
}
|
||||||
// return $this->createQueryBuilder('m')
|
|
||||||
// ->andWhere('m.exampleField = :val')
|
|
||||||
// ->setParameter('val', $value)
|
|
||||||
// ->getQuery()
|
|
||||||
// ->getOneOrNullResult()
|
|
||||||
// ;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,17 @@ class MediaFiles
|
|||||||
$this->filesystem = $filesystem;
|
$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
|
public function getMoviesPath(): string
|
||||||
{
|
{
|
||||||
return $this->moviesPath;
|
return $this->moviesPath;
|
||||||
@@ -83,4 +94,35 @@ class MediaFiles
|
|||||||
|
|
||||||
return Map::from($results);
|
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\DownloadOptionFilter\Resolution;
|
||||||
use App\Torrentio\Client\Rule\RuleEngine;
|
use App\Torrentio\Client\Rule\RuleEngine;
|
||||||
use App\Torrentio\MediaResult;
|
|
||||||
use App\Torrentio\Result\ResultFactory;
|
use App\Torrentio\Result\ResultFactory;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Contracts\Cache\CacheInterface;
|
use Symfony\Contracts\Cache\CacheInterface;
|
||||||
use Symfony\Contracts\Cache\ItemInterface;
|
use Symfony\Contracts\Cache\ItemInterface;
|
||||||
|
|
||||||
/**
|
|
||||||
* ToDo: Fix
|
|
||||||
*/
|
|
||||||
class Torrentio
|
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%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;
|
private string $searchUrl;
|
||||||
|
|
||||||
@@ -44,26 +39,6 @@ class Torrentio
|
|||||||
return $this->parse($results, $filter);
|
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
|
public function fetchEpisodeResults(string $imdbId, int $season, int $episode): array
|
||||||
{
|
{
|
||||||
$cacheKey = "torrentio.$imdbId.$season.$episode";
|
$cacheKey = "torrentio.$imdbId.$season.$episode";
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Twig\Components;
|
|
||||||
|
|
||||||
use App\Download\Framework\Repository\DownloadRepository;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
||||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
|
||||||
use Symfony\UX\LiveComponent\Attribute\LiveAction;
|
|
||||||
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
|
||||||
|
|
||||||
#[AsLiveComponent]
|
|
||||||
final class ActiveDownloadList extends AbstractController
|
|
||||||
{
|
|
||||||
use DefaultActionTrait;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
private DownloadRepository $downloadRepository,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
#[LiveAction]
|
|
||||||
public function getDownloads()
|
|
||||||
{
|
|
||||||
return $this->getUser()->getActiveDownloads();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
41
src/Twig/Components/DownloadList.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use PaginateTrait;
|
||||||
|
|
||||||
|
#[LiveProp(writable: true)]
|
||||||
|
public string $type;
|
||||||
|
|
||||||
|
#[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 [];
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/Twig/Components/DownloadListRow.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Twig\Components;
|
||||||
|
|
||||||
|
use App\Download\Framework\Entity\Download;
|
||||||
|
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||||
|
|
||||||
|
#[AsTwigComponent]
|
||||||
|
final class DownloadListRow
|
||||||
|
{
|
||||||
|
public Download $download;
|
||||||
|
|
||||||
|
public bool $isWidget = true;
|
||||||
|
}
|
||||||
63
src/Twig/Components/MonitorList.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Twig\Components;
|
||||||
|
|
||||||
|
use App\Monitor\Framework\Repository\MonitorRepository;
|
||||||
|
use Doctrine\ORM\Query\Expr\OrderBy;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
||||||
|
use Symfony\UX\LiveComponent\Attribute\LiveAction;
|
||||||
|
use Symfony\UX\LiveComponent\Attribute\LiveProp;
|
||||||
|
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
||||||
|
|
||||||
|
#[AsLiveComponent]
|
||||||
|
final class MonitorList extends AbstractController
|
||||||
|
{
|
||||||
|
use DefaultActionTrait;
|
||||||
|
|
||||||
|
use PaginateTrait;
|
||||||
|
|
||||||
|
#[LiveProp(writable: true)]
|
||||||
|
public string $type;
|
||||||
|
|
||||||
|
#[LiveProp(writable: true)]
|
||||||
|
public bool $isWidget = true;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly MonitorRepository $monitorRepository,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#[LiveAction]
|
||||||
|
public function getMonitors()
|
||||||
|
{
|
||||||
|
if ($this->type === "active") {
|
||||||
|
return $this->getActiveUserMonitors();
|
||||||
|
} elseif ($this->type === "complete") {
|
||||||
|
return $this->getCompleteUserMonitors();
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
#[LiveAction]
|
||||||
|
public function getActiveUserMonitors()
|
||||||
|
{
|
||||||
|
return $this->asPaginator($this->monitorRepository->createQueryBuilder('m')
|
||||||
|
->andWhere('m.status IN (:statuses)')
|
||||||
|
->setParameter('statuses', ['New', 'In Progress'])
|
||||||
|
->orderBy('m.id', 'DESC')
|
||||||
|
->getQuery()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[LiveAction]
|
||||||
|
public function getCompleteUserMonitors()
|
||||||
|
{
|
||||||
|
return $this->asPaginator($this->monitorRepository->createQueryBuilder('m')
|
||||||
|
->andWhere('m.status = :status')
|
||||||
|
->setParameter('status', 'Complete')
|
||||||
|
->orderBy('m.id', 'DESC')
|
||||||
|
->getQuery()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/Twig/Components/MonitorListRow.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Twig\Components;
|
||||||
|
|
||||||
|
use App\Monitor\Framework\Entity\Monitor;
|
||||||
|
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||||
|
|
||||||
|
#[AsTwigComponent]
|
||||||
|
final class MonitorListRow
|
||||||
|
{
|
||||||
|
public Monitor $monitor;
|
||||||
|
}
|
||||||
30
src/Twig/Components/PaginateTrait.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Twig\Components;
|
||||||
|
|
||||||
|
use App\Util\Paginator;
|
||||||
|
use Doctrine\ORM\Query;
|
||||||
|
use Symfony\UX\LiveComponent\Attribute\LiveAction;
|
||||||
|
use Symfony\UX\LiveComponent\Attribute\LiveArg;
|
||||||
|
use Symfony\UX\LiveComponent\Attribute\LiveProp;
|
||||||
|
|
||||||
|
trait PaginateTrait
|
||||||
|
{
|
||||||
|
#[LiveProp(writable: true)]
|
||||||
|
public int $pageNumber = 1;
|
||||||
|
|
||||||
|
#[LiveProp(writable: true)]
|
||||||
|
public int $perPage = 5;
|
||||||
|
|
||||||
|
#[LiveAction]
|
||||||
|
public function paginate(#[LiveArg] int $page)
|
||||||
|
{
|
||||||
|
$this->pageNumber = $page;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function asPaginator(Query $query): Paginator
|
||||||
|
{
|
||||||
|
return (new Paginator())
|
||||||
|
->paginate($query, $this->pageNumber, $this->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
|
||||||
|
{
|
||||||
|
}
|
||||||
36
src/Twig/Extensions/MonitorExtension.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Twig\Extensions;
|
||||||
|
|
||||||
|
use App\Monitor\Framework\Entity\Monitor;
|
||||||
|
use Twig\Attribute\AsTwigFilter;
|
||||||
|
|
||||||
|
class MonitorExtension
|
||||||
|
{
|
||||||
|
#[AsTwigFilter('monitor_type')]
|
||||||
|
public function type(string $type)
|
||||||
|
{
|
||||||
|
$types = [
|
||||||
|
'tvshows' => 'Show',
|
||||||
|
'tvseason' => 'Season',
|
||||||
|
'tvepisode' => 'Episode',
|
||||||
|
];
|
||||||
|
|
||||||
|
return $types[$type] ?? '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
#[AsTwigFilter('monitor_media_id')]
|
||||||
|
public function mediaId(Monitor $monitor)
|
||||||
|
{
|
||||||
|
if ($monitor->getMonitorType() === "tvseason") {
|
||||||
|
return "S". str_pad($monitor->getSeason(), 2, "0", STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($monitor->getMonitorType() === "tvepisode") {
|
||||||
|
return "S". str_pad($monitor->getSeason(), 2, "0", STR_PAD_LEFT) .
|
||||||
|
"E". str_pad($monitor->getEpisode(), 2, "0", STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "-";
|
||||||
|
}
|
||||||
|
}
|
||||||
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,8 @@
|
|||||||
|
|
||||||
namespace App\User\Framework\Controller\Web;
|
namespace App\User\Framework\Controller\Web;
|
||||||
|
|
||||||
|
use App\User\Framework\Repository\UserRepository;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
@@ -10,8 +12,12 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
|||||||
class LoginController extends AbstractController
|
class LoginController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route(path: '/login', name: 'app_login')]
|
#[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
|
// get the login error if there is one
|
||||||
$error = $authenticationUtils->getLastAuthenticationError();
|
$error = $authenticationUtils->getLastAuthenticationError();
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\User\Framework\Controller\Web;
|
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\Handler\SaveUserMediaPreferencesHandler;
|
||||||
|
use App\User\Action\Input\SaveUserDownloadPreferencesInput;
|
||||||
use App\User\Action\Input\SaveUserMediaPreferencesInput;
|
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\User\Framework\Repository\PreferencesRepository;
|
||||||
use App\Util\CountryCodes;
|
use App\Util\Broadcaster;
|
||||||
use App\Util\CountryLanguages;
|
use App\Util\CountryLanguages;
|
||||||
use App\Util\ProviderList;
|
use App\Util\ProviderList;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
@@ -22,22 +20,14 @@ class PreferencesController extends AbstractController
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly PreferencesRepository $preferencesRepository,
|
private readonly PreferencesRepository $preferencesRepository,
|
||||||
private readonly SaveUserMediaPreferencesHandler $saveUserMediaPreferencesHandler,
|
private readonly Broadcaster $broadcaster,
|
||||||
private readonly Security $security,
|
|
||||||
) {}
|
) {}
|
||||||
#[Route('/media/preferences', 'app_media_preferences', methods: ['GET'])]
|
|
||||||
|
#[Route('/user/preferences', 'app_user_preferences', methods: ['GET'])]
|
||||||
public function mediaPreferences(): Response
|
public function mediaPreferences(): Response
|
||||||
{
|
{
|
||||||
$enabledPreferences = $this->preferencesRepository->findEnabled();
|
$mediaPreferences = $this->getUser()->getMediaPreferences();
|
||||||
|
$downloadPreferences = $this->getUser()->getDownloadPreferences();
|
||||||
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());
|
|
||||||
|
|
||||||
$languages = CountryLanguages::$languages;
|
$languages = CountryLanguages::$languages;
|
||||||
sort($languages);
|
sort($languages);
|
||||||
|
|
||||||
@@ -47,44 +37,68 @@ class PreferencesController extends AbstractController
|
|||||||
'preferences' => $this->preferencesRepository->findEnabled(),
|
'preferences' => $this->preferencesRepository->findEnabled(),
|
||||||
'languages' => $languages,
|
'languages' => $languages,
|
||||||
'providers' => ProviderList::$providers,
|
'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(
|
public function saveMediaPreferences(
|
||||||
SaveUserMediaPreferencesInput $input,
|
SaveUserMediaPreferencesInput $input,
|
||||||
|
SaveUserMediaPreferencesHandler $saveUserMediaPreferencesHandler,
|
||||||
): Response
|
): Response
|
||||||
{
|
{
|
||||||
$userPreferences = $this->saveUserMediaPreferencesHandler->handle($input->toCommand())->userPreferences;
|
$saveUserMediaPreferencesHandler->handle($input->toCommand());
|
||||||
$userPreferences = Map::from($userPreferences)->rekey(fn($preference) => $preference->getPreference()->getId());
|
$mediaPreferences = $this->getUser()->getMediaPreferences();
|
||||||
|
$downloadPreferences = $this->getUser()->getDownloadPreferences();
|
||||||
|
|
||||||
$languages = CountryLanguages::$languages;
|
$languages = CountryLanguages::$languages;
|
||||||
sort($languages);
|
sort($languages);
|
||||||
|
|
||||||
|
$this->broadcaster->alert(
|
||||||
|
title: 'Success',
|
||||||
|
message: 'Your media preferences have been saved.'
|
||||||
|
);
|
||||||
|
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'user/preferences.html.twig',
|
'user/preferences.html.twig',
|
||||||
[
|
[
|
||||||
'preferences' => $this->preferencesRepository->findEnabled(),
|
'preferences' => $this->preferencesRepository->findEnabled(),
|
||||||
'languages' => $languages,
|
'languages' => $languages,
|
||||||
'providers' => ProviderList::$providers,
|
'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(
|
||||||
|
SaveUserDownloadPreferencesInput $input,
|
||||||
|
SaveUserDownloadPreferencesHandler $saveUserDownloadPreferencesHandler,
|
||||||
|
): Response
|
||||||
{
|
{
|
||||||
foreach ($preferences as $preference) {
|
$downloadPreferences = $saveUserDownloadPreferencesHandler->handle($input->toCommand())->downloadPreferences;
|
||||||
if (false === $user->hasUserPreference($preference->getId())) {
|
$mediaPreferences = $this->getUser()->getMediaPreferences();
|
||||||
$user->addUserPreference((new UserPreference())
|
|
||||||
->setUser($user)
|
$languages = CountryLanguages::$languages;
|
||||||
->setPreference($preference)
|
sort($languages);
|
||||||
->setPreferenceValue(null)
|
|
||||||
);
|
$this->broadcaster->alert(
|
||||||
}
|
title: 'Success',
|
||||||
}
|
message: 'Your download preferences have been saved.'
|
||||||
$this->preferencesRepository->getEntityManager()->flush();
|
);
|
||||||
|
|
||||||
|
return $this->render(
|
||||||
|
'user/preferences.html.twig',
|
||||||
|
[
|
||||||
|
'preferences' => $this->preferencesRepository->findEnabled(),
|
||||||
|
'languages' => $languages,
|
||||||
|
'providers' => ProviderList::$providers,
|
||||||
|
'mediaPreferences' => $mediaPreferences,
|
||||||
|
'downloadPreferences' => $downloadPreferences,
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||