Switched Seria config to Syokuhou format.

This commit is contained in:
flash 2023-12-15 02:04:53 +00:00
parent 16b16670d5
commit bf10db5163
10 changed files with 194 additions and 115 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@
/config.php /config.php
/errors.log /errors.log
/vendor /vendor
/seria.cfg

View file

@ -4,6 +4,7 @@
"require": { "require": {
"flashwave/index": "dev-master", "flashwave/index": "dev-master",
"flashwave/sasae": "dev-master", "flashwave/sasae": "dev-master",
"flashwave/syokuhou": "dev-master",
"erusev/parsedown": "~1.6" "erusev/parsedown": "~1.6"
}, },
"autoload": { "autoload": {

238
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "6c0d442a01899edbfc60a28c35e7f945", "content-hash": "783f9604312991e2ccea8a65f381c9a4",
"packages": [ "packages": [
{ {
"name": "erusev/parsedown", "name": "erusev/parsedown",
@ -144,89 +144,60 @@
"time": "2023-11-20T19:09:35+00:00" "time": "2023-11-20T19:09:35+00:00"
}, },
{ {
"name": "symfony/deprecation-contracts", "name": "flashwave/syokuhou",
"version": "v3.4.0", "version": "dev-master",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git", "url": "https://patchii.net/flash/syokuhou.git",
"reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" "reference": "fdf3c38cc216bf7024af331cbe1758532355c22f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf",
"reference": "7c3aff79d10325257a001fcf92d991f24fc967cf",
"shasum": ""
}, },
"require": { "require": {
"php": ">=8.1" "flashwave/index": "dev-master",
"php": ">=8.2"
}, },
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.4"
},
"default-branch": true,
"type": "library", "type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.4-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": { "autoload": {
"files": [ "psr-4": {
"function.php" "Syokuhou\\": "src"
] }
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
"license": [ "license": [
"MIT" "bsd-3-clause-clear"
], ],
"authors": [ "authors": [
{ {
"name": "Nicolas Grekas", "name": "flashwave",
"email": "p@tchwork.com" "email": "packagist@flash.moe",
}, "homepage": "https://flash.moe",
{ "role": "mom"
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
} }
], ],
"description": "A generic function and convention to trigger deprecation notices", "description": "Configuration library for PHP.",
"homepage": "https://symfony.com", "homepage": "https://railgun.sh/syokuhou",
"support": { "time": "2023-11-20T19:10:04+00:00"
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-05-23T14:45:45+00:00"
}, },
{ {
"name": "symfony/mime", "name": "symfony/mime",
"version": "v6.3.5", "version": "v7.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/mime.git", "url": "https://github.com/symfony/mime.git",
"reference": "d5179eedf1cb2946dbd760475ebf05c251ef6a6e" "reference": "0a2fff95c1a10df97f571d67e76c7ae0f0d4f535"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/mime/zipball/d5179eedf1cb2946dbd760475ebf05c251ef6a6e", "url": "https://api.github.com/repos/symfony/mime/zipball/0a2fff95c1a10df97f571d67e76c7ae0f0d4f535",
"reference": "d5179eedf1cb2946dbd760475ebf05c251ef6a6e", "reference": "0a2fff95c1a10df97f571d67e76c7ae0f0d4f535",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.1", "php": ">=8.2",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/polyfill-intl-idn": "^1.10", "symfony/polyfill-intl-idn": "^1.10",
"symfony/polyfill-mbstring": "^1.0" "symfony/polyfill-mbstring": "^1.0"
}, },
@ -234,17 +205,17 @@
"egulias/email-validator": "~3.0.0", "egulias/email-validator": "~3.0.0",
"phpdocumentor/reflection-docblock": "<3.2.2", "phpdocumentor/reflection-docblock": "<3.2.2",
"phpdocumentor/type-resolver": "<1.4.0", "phpdocumentor/type-resolver": "<1.4.0",
"symfony/mailer": "<5.4", "symfony/mailer": "<6.4",
"symfony/serializer": "<6.2.13|>=6.3,<6.3.2" "symfony/serializer": "<6.4"
}, },
"require-dev": { "require-dev": {
"egulias/email-validator": "^2.1.10|^3.1|^4", "egulias/email-validator": "^2.1.10|^3.1|^4",
"league/html-to-markdown": "^5.0", "league/html-to-markdown": "^5.0",
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
"symfony/dependency-injection": "^5.4|^6.0", "symfony/dependency-injection": "^6.4|^7.0",
"symfony/property-access": "^5.4|^6.0", "symfony/property-access": "^6.4|^7.0",
"symfony/property-info": "^5.4|^6.0", "symfony/property-info": "^6.4|^7.0",
"symfony/serializer": "~6.2.13|^6.3.2" "symfony/serializer": "^6.4|^7.0"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -276,7 +247,7 @@
"mime-type" "mime-type"
], ],
"support": { "support": {
"source": "https://github.com/symfony/mime/tree/v6.3.5" "source": "https://github.com/symfony/mime/tree/v7.0.0"
}, },
"funding": [ "funding": [
{ {
@ -292,7 +263,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-09-29T06:59:36+00:00" "time": "2023-10-19T14:20:43+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
@ -707,26 +678,109 @@
"time": "2023-01-26T09:26:14+00:00" "time": "2023-01-26T09:26:14+00:00"
}, },
{ {
"name": "twig/html-extra", "name": "symfony/polyfill-php80",
"version": "v3.7.1", "version": "v1.28.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/html-extra.git", "url": "https://github.com/symfony/polyfill-php80.git",
"reference": "95ceb36e70fa8d07af08cf5135ecbf5e0bd8f386" "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/html-extra/zipball/95ceb36e70fa8d07af08cf5135ecbf5e0bd8f386", "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5",
"reference": "95ceb36e70fa8d07af08cf5135ecbf5e0bd8f386", "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=7.1.3", "php": ">=7.1"
"symfony/mime": "^5.4|^6.0", },
"twig/twig": "^2.7|^3.0" "type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.28-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Php80\\": ""
},
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ion Bazan",
"email": "ion.bazan@gmail.com"
},
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-01-26T09:26:14+00:00"
},
{
"name": "twig/html-extra",
"version": "v3.8.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/html-extra.git",
"reference": "c04603bb3b71d8d2ece9e583dbf7bd77811df1f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/html-extra/zipball/c04603bb3b71d8d2ece9e583dbf7bd77811df1f2",
"reference": "c04603bb3b71d8d2ece9e583dbf7bd77811df1f2",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"symfony/mime": "^5.4|^6.0|^7.0",
"twig/twig": "^3.0"
}, },
"require-dev": { "require-dev": {
"symfony/phpunit-bridge": "^5.4|^6.3" "symfony/phpunit-bridge": "^6.4|^7.0"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -756,7 +810,7 @@
"twig" "twig"
], ],
"support": { "support": {
"source": "https://github.com/twigphp/html-extra/tree/v3.7.1" "source": "https://github.com/twigphp/html-extra/tree/v3.8.0"
}, },
"funding": [ "funding": [
{ {
@ -768,30 +822,31 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-07-29T15:34:56+00:00" "time": "2023-11-21T14:02:01+00:00"
}, },
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v3.7.1", "version": "v3.8.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/Twig.git", "url": "https://github.com/twigphp/Twig.git",
"reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554" "reference": "9d15f0ac07f44dc4217883ec6ae02fd555c6f71d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/a0ce373a0ca3bf6c64b9e3e2124aca502ba39554", "url": "https://api.github.com/repos/twigphp/Twig/zipball/9d15f0ac07f44dc4217883ec6ae02fd555c6f71d",
"reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554", "reference": "9d15f0ac07f44dc4217883ec6ae02fd555c6f71d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/polyfill-ctype": "^1.8", "symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-mbstring": "^1.3" "symfony/polyfill-mbstring": "^1.3",
"symfony/polyfill-php80": "^1.22"
}, },
"require-dev": { "require-dev": {
"psr/container": "^1.0|^2.0", "psr/container": "^1.0|^2.0",
"symfony/phpunit-bridge": "^5.4.9|^6.3" "symfony/phpunit-bridge": "^5.4.9|^6.3|^7.0"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -827,7 +882,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/twigphp/Twig/issues", "issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v3.7.1" "source": "https://github.com/twigphp/Twig/tree/v3.8.0"
}, },
"funding": [ "funding": [
{ {
@ -839,22 +894,22 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-08-28T11:09:02+00:00" "time": "2023-11-21T18:54:41+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "1.10.43", "version": "1.10.50",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "2c4129f6ca8c7cfa870098884b8869b410a5a361" "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/2c4129f6ca8c7cfa870098884b8869b410a5a361", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/06a98513ac72c03e8366b5a0cb00750b487032e4",
"reference": "2c4129f6ca8c7cfa870098884b8869b410a5a361", "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -903,14 +958,15 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-11-19T19:55:25+00:00" "time": "2023-12-13T10:59:42+00:00"
} }
], ],
"aliases": [], "aliases": [],
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": { "stability-flags": {
"flashwave/index": 20, "flashwave/index": 20,
"flashwave/sasae": 20 "flashwave/sasae": 20,
"flashwave/syokuhou": 20
}, },
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,

View file

@ -7,7 +7,7 @@ use Seria\Users\UserInfo;
require_once __DIR__ . '/../seria.php'; require_once __DIR__ . '/../seria.php';
$authToken = (string)filter_input(INPUT_COOKIE, 'msz_auth'); $authToken = (string)filter_input(INPUT_COOKIE, 'msz_auth');
$authInfo = ChatAuth::attempt(SERIA_CAUTH_ENDPOINT, SERIA_MSZ_SECRET, $authToken); $authInfo = ChatAuth::attempt($cfg->scopeTo('cauth'), $authToken);
if($authInfo->success) { if($authInfo->success) {
$users = $seria->getUsersContext()->getUsers(); $users = $seria->getUsersContext()->getUsers();
@ -17,7 +17,7 @@ if($authInfo->success) {
} else $sUserInfo = null; } else $sUserInfo = null;
$seria->startCSRFP( $seria->startCSRFP(
SERIA_CSRFP_SECRET, $cfg->getString('csrfp:secret', 'mewow'),
$authInfo->success ? $authToken : (string)filter_input(INPUT_SERVER, 'REMOTE_ADDR') $authInfo->success ? $authToken : (string)filter_input(INPUT_SERVER, 'REMOTE_ADDR')
); );

View file

@ -3,6 +3,7 @@ namespace Seria;
use Index\Environment; use Index\Environment;
use Index\Data\DbTools; use Index\Data\DbTools;
use Syokuhou\SharpConfig;
define('SERIA_STARTUP', microtime(true)); define('SERIA_STARTUP', microtime(true));
define('SERIA_ROOT', __DIR__); define('SERIA_ROOT', __DIR__);
@ -17,9 +18,9 @@ Environment::setDebug(SERIA_DEBUG);
mb_internal_encoding('utf-8'); mb_internal_encoding('utf-8');
date_default_timezone_set('utc'); date_default_timezone_set('utc');
require_once SERIA_ROOT . '/config.php'; $cfg = SharpConfig::fromFile(SERIA_ROOT . '/seria.cfg');
$db = DbTools::create(SERIA_DSN); $db = DbTools::create($cfg->getString('database:dsn', 'null:'));
$db->execute('SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';'); $db->execute('SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';');
$seria = new SeriaContext($db); $seria = new SeriaContext($db, $cfg);

View file

@ -2,15 +2,16 @@
namespace Seria\Auth; namespace Seria\Auth;
use stdClass; use stdClass;
use Syokuhou\IConfig;
final class ChatAuth { final class ChatAuth {
public static function attempt(string $endPoint, string $secret, string $cookie): object { public static function attempt(IConfig $config, string $cookie): object {
if(!empty($cookie)) { if(!empty($cookie)) {
$method = 'Misuzu'; $method = 'Misuzu';
$signature = sprintf('verify#%s#%s#%s', $method, $cookie, $_SERVER['REMOTE_ADDR']); $signature = sprintf('verify#%s#%s#%s', $method, $cookie, $_SERVER['REMOTE_ADDR']);
$signature = hash_hmac('sha256', $signature, $secret); $signature = hash_hmac('sha256', $signature, $config->getString('secret'));
$login = curl_init($endPoint); $login = curl_init($config->getString('endpoint'));
curl_setopt_array($login, [ curl_setopt_array($login, [
CURLOPT_AUTOREFERER => false, CURLOPT_AUTOREFERER => false,
CURLOPT_FAILONERROR => false, CURLOPT_FAILONERROR => false,

View file

@ -9,12 +9,14 @@ use Index\Data\Migration\DbMigrationManager;
use Index\Data\Migration\FsDbMigrationRepo; use Index\Data\Migration\FsDbMigrationRepo;
use Index\Security\CSRFP; use Index\Security\CSRFP;
use Sasae\SasaeEnvironment; use Sasae\SasaeEnvironment;
use Syokuhou\IConfig;
use Seria\Auth\AuthInfo; use Seria\Auth\AuthInfo;
use Seria\Torrents\TorrentsContext; use Seria\Torrents\TorrentsContext;
use Seria\Users\UsersContext; use Seria\Users\UsersContext;
final class SeriaContext { final class SeriaContext {
private IDbTransactions $dbConn; private IDbTransactions $dbConn;
private IConfig $config;
private ?SasaeEnvironment $templating = null; private ?SasaeEnvironment $templating = null;
private AuthInfo $authInfo; private AuthInfo $authInfo;
@ -25,11 +27,12 @@ final class SeriaContext {
private TorrentsContext $torrentsCtx; private TorrentsContext $torrentsCtx;
private UsersContext $usersCtx; private UsersContext $usersCtx;
public function __construct(IDbTransactions $dbConn) { public function __construct(IDbTransactions $dbConn, IConfig $config) {
$this->dbConn = $dbConn; $this->dbConn = $dbConn;
$this->config = $config;
$this->authInfo = new AuthInfo; $this->authInfo = new AuthInfo;
$this->siteInfo = new SiteInfo; $this->siteInfo = new SiteInfo($config->scopeTo('site'));
$this->torrentsCtx = new TorrentsContext($dbConn); $this->torrentsCtx = new TorrentsContext($dbConn);
$this->usersCtx = new UsersContext($dbConn); $this->usersCtx = new UsersContext($dbConn);
@ -93,7 +96,7 @@ final class SeriaContext {
cache: $isDebug ? null : ['Seria', GitInfo::hash(true)], cache: $isDebug ? null : ['Seria', GitInfo::hash(true)],
debug: $isDebug, debug: $isDebug,
); );
$this->templating->addExtension(new SeriaSasaeExtension($this)); $this->templating->addExtension(new SeriaSasaeExtension($this, $this->siteInfo));
$this->templating->addGlobal('globals', $globals); $this->templating->addGlobal('globals', $globals);
} }
@ -109,7 +112,14 @@ final class SeriaContext {
$routing->register(new Users\SettingsRoutes($this->authInfo, $this->usersCtx, $this->csrfp, $this->templating)); $routing->register(new Users\SettingsRoutes($this->authInfo, $this->usersCtx, $this->csrfp, $this->templating));
$routing->register(new Torrents\AnnounceRouting($this->torrentsCtx, $this->usersCtx)); $routing->register(new Torrents\AnnounceRouting($this->torrentsCtx, $this->usersCtx));
$routing->register(new Torrents\TorrentCreateRouting($this->dbConn, $this->authInfo, $this->torrentsCtx, $this->csrfp, $this->templating)); $routing->register(new Torrents\TorrentCreateRouting($this->dbConn, $this->authInfo, $this->torrentsCtx, $this->csrfp, $this->templating));
$routing->register(new Torrents\TorrentInfoRouting($this->authInfo, $this->torrentsCtx, $this->usersCtx, $this->csrfp, $this->templating)); $routing->register(new Torrents\TorrentInfoRouting(
$this->config->scopeTo('announce'),
$this->authInfo,
$this->torrentsCtx,
$this->usersCtx,
$this->csrfp,
$this->templating
));
$routing->register(new Torrents\TorrentListRouting($this->authInfo, $this->torrentsCtx, $this->usersCtx, $this->templating)); $routing->register(new Torrents\TorrentListRouting($this->authInfo, $this->torrentsCtx, $this->usersCtx, $this->templating));
return $routing; return $routing;

View file

@ -9,7 +9,8 @@ final class SeriaSasaeExtension extends AbstractExtension {
private TorrentPeers $peers; private TorrentPeers $peers;
public function __construct( public function __construct(
private SeriaContext $ctx private SeriaContext $ctx,
private SiteInfo $siteInfo
) { ) {
$this->peers = $ctx->getTorrentsContext()->getPeers(); $this->peers = $ctx->getTorrentsContext()->getPeers();
} }
@ -42,7 +43,7 @@ final class SeriaSasaeExtension extends AbstractExtension {
else else
$menu[] = [ $menu[] = [
'text' => 'Log in', 'text' => 'Log in',
'url' => SERIA_CAUTH_LOGIN, 'url' => $this->siteInfo->getLoginUrl(),
]; ];
$menu[] = [ $menu[] = [

View file

@ -1,34 +1,39 @@
<?php <?php
namespace Seria; namespace Seria;
use Syokuhou\IConfig;
use Seria\Users\UserInfo; use Seria\Users\UserInfo;
// this should pull from some db config or something at some point
class SiteInfo { class SiteInfo {
public function __construct(private IConfig $config) {}
public function getName(): string { public function getName(): string {
return SERIA_FLASHII . ' Tracker'; return $this->config->getString('name');
} }
public function getHost(): string { public function getHost(): string {
return (string)filter_input(INPUT_SERVER, 'HTTP_HOST'); return $this->config->getString('host');
} }
public function getMainSiteName(): string { public function getMainSiteName(): string {
return SERIA_FLASHIINET; return $this->config->getString('parent');
}
public function getLoginUrl(): string {
return $this->config->getString('login');
} }
public function getProfileUrl(UserInfo|string $userInfo): string { public function getProfileUrl(UserInfo|string $userInfo): string {
if($userInfo instanceof UserInfo) if($userInfo instanceof UserInfo)
$userInfo = $userInfo->getId(); $userInfo = $userInfo->getId();
return sprintf(SERIA_PROFILE_FORMAT, $userInfo); return sprintf($this->config->getString('profile'), $userInfo);
} }
public function getAvatarUrl(UserInfo|string $userInfo, int $res = 0): string { public function getAvatarUrl(UserInfo|string $userInfo, int $res = 0): string {
if($userInfo instanceof UserInfo) if($userInfo instanceof UserInfo)
$userInfo = $userInfo->getId(); $userInfo = $userInfo->getId();
return sprintf($res < 1 ? SERIA_AVATAR_FORMAT : SERIA_AVATAR_FORMAT_RES, $userInfo, $res); return sprintf($this->config->getString($res < 1 ? 'avatar' : 'avatar:res'), $userInfo, $res);
} }
} }

View file

@ -6,6 +6,7 @@ use Index\Routing\Route;
use Index\Routing\RouteHandler; use Index\Routing\RouteHandler;
use Index\Security\CSRFP; use Index\Security\CSRFP;
use Sasae\SasaeEnvironment; use Sasae\SasaeEnvironment;
use Syokuhou\IConfig;
use Seria\Auth\AuthInfo; use Seria\Auth\AuthInfo;
use Seria\Users\UsersContext; use Seria\Users\UsersContext;
@ -13,6 +14,7 @@ class TorrentInfoRouting extends RouteHandler {
private ?TorrentInfo $torrentInfo = null; private ?TorrentInfo $torrentInfo = null;
public function __construct( public function __construct(
private IConfig $config,
private AuthInfo $authInfo, private AuthInfo $authInfo,
private TorrentsContext $torrentsCtx, private TorrentsContext $torrentsCtx,
private UsersContext $usersCtx, private UsersContext $usersCtx,
@ -41,15 +43,16 @@ class TorrentInfoRouting extends RouteHandler {
}; };
} }
$trackerUrl = SERIA_ANNOUNCE_URL_ANON; $trackerUrl = '';
if($this->authInfo->isLoggedIn()) { if($this->authInfo->isLoggedIn()) {
$userInfo = $this->authInfo->getUserInfo(); $userInfo = $this->authInfo->getUserInfo();
$passKey = $userInfo->hasPassKey() $passKey = $userInfo->hasPassKey()
? $userInfo->getPassKey() ? $userInfo->getPassKey()
: $this->usersCtx->getUsers()->updatePassKey($userInfo); : $this->usersCtx->getUsers()->updatePassKey($userInfo);
$trackerUrl = sprintf(SERIA_ANNOUNCE_URL, $passKey); $trackerUrl = sprintf($this->config->getString('url:user'), $passKey);
} } else
$trackerUrl = $this->config->getString('url:anon');
$response->setContentType('application/x-bittorrent'); $response->setContentType('application/x-bittorrent');
$response->setFileName(htmlspecialchars($torrentInfo->getName()) . '.torrent'); $response->setFileName(htmlspecialchars($torrentInfo->getName()) . '.torrent');