mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
cleanup and tests
This commit is contained in:
parent
ae39548ddb
commit
05f48fd0a0
7 changed files with 110 additions and 25 deletions
|
|
@ -12,15 +12,23 @@ class DemoStore {
|
|||
}
|
||||
|
||||
public function store(string $sourcePath, string $name): string {
|
||||
rename($sourcePath, $this->generatePath($name));
|
||||
$target = $this->generatePath($name);
|
||||
if (!is_dir(dirname($target))) {
|
||||
mkdir(dirname($target), 0777, true);
|
||||
}
|
||||
rename($sourcePath, $target);
|
||||
return $this->getUrl($name);
|
||||
}
|
||||
|
||||
private function generatePath(string $name): string {
|
||||
return $this->root . '/' . substr($name, 0, 2) . '/' . substr($name, 2, 4) . '/' . $name;
|
||||
return $this->root . $this->getPrefix($name) . $name;
|
||||
}
|
||||
|
||||
private function getPrefix(string $name) {
|
||||
return '/' . substr($name, 0, 2) . '/' . substr($name, 2, 2) . '/';
|
||||
}
|
||||
|
||||
private function getUrl(string $name): string {
|
||||
return 'https://' . $this->webroot . '/' . substr($name, 0, 2) . '/' . substr($name, 2, 4) . '/' . $name;
|
||||
return 'https://' . $this->webroot . $this->getPrefix($name) . $name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,24 @@
|
|||
|
||||
namespace Demostf\API\Demo;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
/**
|
||||
* Higher level parser
|
||||
*
|
||||
* Processes the raw demo.js output to something more suitable for our purpose
|
||||
*/
|
||||
class Parser {
|
||||
const CLASSES = [
|
||||
1 => 'scout',
|
||||
2 => 'sniper',
|
||||
3 => 'soldier',
|
||||
4 => 'demoman',
|
||||
5 => 'medic',
|
||||
6 => 'heavyweapons',
|
||||
7 => 'pyro',
|
||||
8 => 'spy',
|
||||
9 => 'engineer'
|
||||
];
|
||||
|
||||
/** @var RawParser */
|
||||
private $rawParser;
|
||||
|
||||
|
|
@ -81,17 +91,6 @@ class Parser {
|
|||
}
|
||||
|
||||
private function getClassName(int $classId): string {
|
||||
$classes = [
|
||||
1 => 'scout',
|
||||
2 => 'sniper',
|
||||
3 => 'soldier',
|
||||
4 => 'demoman',
|
||||
5 => 'medic',
|
||||
6 => 'heavyweapons',
|
||||
7 => 'pyro',
|
||||
8 => 'spy',
|
||||
9 => 'engineer'
|
||||
];
|
||||
return $classes[$classId] ?? 'Unknown';
|
||||
return self::CLASSES[$classId] ?? 'Unknown';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Demostf\API\Exception;
|
||||
|
||||
class NotFoundException extends \Exception {
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue