mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
delete static demo when changing demo url
This commit is contained in:
parent
df83a46e20
commit
611e7c3415
5 changed files with 138 additions and 21 deletions
|
|
@ -93,7 +93,7 @@ class Container {
|
|||
$this->baseUrl,
|
||||
new HeaderParser(),
|
||||
new Parser(new RawParser($this->parserUrl)),
|
||||
new DemoStore($this->storeRoot, $this->storeUrl),
|
||||
$this->getDemoStore(),
|
||||
$this->getUserProvider(),
|
||||
$this->getDemoProvider(),
|
||||
new DemoSaver(
|
||||
|
|
@ -106,6 +106,10 @@ class Container {
|
|||
);
|
||||
}
|
||||
|
||||
public function getDemoStore(): DemoStore {
|
||||
return new DemoStore($this->storeRoot, $this->storeUrl);
|
||||
}
|
||||
|
||||
public function getUserProvider(): UserProvider {
|
||||
return new UserProvider($this->connection, $this->generator);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Demostf\API\Controllers;
|
||||
|
||||
use Demostf\API\Demo\DemoStore;
|
||||
use Demostf\API\Providers\ChatProvider;
|
||||
use Demostf\API\Providers\DemoListProvider;
|
||||
use Demostf\API\Providers\DemoProvider;
|
||||
|
|
@ -21,18 +22,22 @@ class DemoController extends BaseController {
|
|||
|
||||
private $editKey;
|
||||
|
||||
private $store;
|
||||
|
||||
public function __construct(
|
||||
Request $request,
|
||||
Response $response,
|
||||
DemoProvider $demoProvider,
|
||||
ChatProvider $chatProvider,
|
||||
DemoListProvider $demoListProvider,
|
||||
DemoStore $store,
|
||||
string $editKey
|
||||
) {
|
||||
parent::__construct($request, $response);
|
||||
$this->demoProvider = $demoProvider;
|
||||
$this->chatProvider = $chatProvider;
|
||||
$this->demoListProvider = $demoListProvider;
|
||||
$this->store = $store;
|
||||
$this->editKey = $editKey;
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +118,10 @@ class DemoController extends BaseController {
|
|||
$existingHash = $demo->getHash();
|
||||
if ($existingHash === '' || $existingHash === $hash) {
|
||||
$this->demoProvider->setDemoUrl((int) $id, $backend, $url, $path);
|
||||
|
||||
if ($demo->getBackend() === 'static') {
|
||||
$this->store->remove($demo);
|
||||
}
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Invalid demo hash');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,4 +39,10 @@ class DemoStore {
|
|||
private function getUrl(string $name): string {
|
||||
return 'https://' . $this->webRoot . $this->getPrefix($name) . $name;
|
||||
}
|
||||
|
||||
public function remove(Demo $demo) {
|
||||
if (file_exists($demo->getPath())) {
|
||||
unlink($demo->getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ $demoController = new Controllers\DemoController(
|
|||
$container->getDemoProvider(),
|
||||
$container->getChatProvider(),
|
||||
$container->getDemoListProvider(),
|
||||
$container->getDemoStore(),
|
||||
$container->getEditKey()
|
||||
);
|
||||
$authController = new Controllers\AuthController(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue