Manage uploaded files
This commit is contained in:
81
.idea/contabilidad.iml
generated
81
.idea/contabilidad.iml
generated
@ -1,81 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/kint-php/kint" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/zeuxisoo/slim-whoops" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phar-io/version" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phar-io/manifest" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/theseer/tokenizer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/webmozart/assert" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/philo/laravel-blade" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/nesbot/carbon" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/type" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/diff" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/support" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/lines-of-code" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/filesystem" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/object-enumerator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/events" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/comparator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/contracts" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/simple-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/code-unit" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/view" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/http-server-handler" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/doctrine/instantiator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/exporter" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/container" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/http-factory" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/doctrine/inflector" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/cli-parser" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/container" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/version" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/http-message" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/complexity" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/http-server-middleware" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/recursion-context" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/log" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/resource-operations" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/global-state" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/composer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/environment" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpdocumentor/reflection-docblock" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/code-unit-reverse-lookup" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpdocumentor/type-resolver" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/polyfill-mbstring" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/object-reflector" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpdocumentor/reflection-common" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/finder" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/deprecation-contracts" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/translation-contracts" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/filp/whoops" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/polyfill-ctype" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/debug" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/nyholm/psr7-server" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/translation" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/nyholm/psr7" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/polyfill-php80" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/nikic/php-parser" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/nikic/fast-route" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/php-di/php-di" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/php-di/phpdoc-reader" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/php-di/slim-bridge" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/php-di/invoker" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/php-code-coverage" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/phpunit" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/php-text-template" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/php-invoker" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/php-file-iterator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/php-timer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/myclabs/deep-copy" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpspec/prophecy" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/opis/closure" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/php-http/message-factory" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/rubellum/slim-blade-view" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/slim/slim" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
87
.idea/php.xml
generated
87
.idea/php.xml
generated
@ -1,87 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpIncludePathManager">
|
||||
<include_path>
|
||||
<path value="$PROJECT_DIR$/ui/vendor/kint-php/kint" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/zeuxisoo/slim-whoops" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phar-io/version" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phar-io/manifest" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/theseer/tokenizer" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/webmozart/assert" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/philo/laravel-blade" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/nesbot/carbon" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/type" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/diff" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/support" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/lines-of-code" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/filesystem" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/object-enumerator" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/events" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/comparator" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/contracts" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/simple-cache" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/code-unit" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/view" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/http-server-handler" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/doctrine/instantiator" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/exporter" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/container" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/http-factory" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/doctrine/inflector" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/cli-parser" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/container" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/version" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/http-message" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/complexity" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/http-server-middleware" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/recursion-context" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/log" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/resource-operations" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/global-state" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/composer" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/environment" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpdocumentor/reflection-docblock" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/code-unit-reverse-lookup" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpdocumentor/type-resolver" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/polyfill-mbstring" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/object-reflector" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpdocumentor/reflection-common" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/finder" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/deprecation-contracts" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/translation-contracts" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/filp/whoops" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/polyfill-ctype" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/debug" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/nyholm/psr7-server" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/translation" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/nyholm/psr7" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/polyfill-php80" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/nikic/php-parser" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/nikic/fast-route" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/php-di/php-di" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/php-di/phpdoc-reader" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/php-di/slim-bridge" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/php-di/invoker" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/php-code-coverage" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/phpunit" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/php-text-template" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/php-invoker" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/php-file-iterator" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/php-timer" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/myclabs/deep-copy" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpspec/prophecy" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/opis/closure" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/php-http/message-factory" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/rubellum/slim-blade-view" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/slim/slim" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.0">
|
||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||
</component>
|
||||
<component name="PhpUnit">
|
||||
<phpunit_settings>
|
||||
<PhpUnitSettings custom_loader_path="$PROJECT_DIR$/ui/vendor/autoload.php" />
|
||||
</phpunit_settings>
|
||||
</component>
|
||||
</project>
|
77
api/common/Controller/Files.php
Normal file
77
api/common/Controller/Files.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use Contabilidad\Common\Service\FileHandler as Handler;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Cuenta;
|
||||
|
||||
class Files {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Handler $handler): Response {
|
||||
$files = $handler->listFiles();
|
||||
usort($files, function($a, $b) {
|
||||
$f = strcmp($a->folder, $b->folder);
|
||||
if ($f == 0) {
|
||||
return strcmp($a->filename, $b->filename);
|
||||
}
|
||||
return $f;
|
||||
});
|
||||
return $this->withJson($response, compact('files'));
|
||||
}
|
||||
public function upload(Request $request, Response $response, Handler $handler, Factory $factory): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$cuenta = $factory->find(Cuenta::class)->one($post['cuenta']);
|
||||
$file = $request->getUploadedFiles()['archivo'];
|
||||
$new_name = implode(' - ', [$cuenta->nombre, $cuenta->categoria()->nombre, $post['fecha']]);
|
||||
$output = [
|
||||
'input' => [
|
||||
'name' => $file->getClientFilename(),
|
||||
'type' => $file->getClientMediaType(),
|
||||
'size' => $file->getSize(),
|
||||
'error' => $file->getError()
|
||||
],
|
||||
'new_name' => $new_name,
|
||||
'uploaded' => $handler->uploadFile($file, $new_name)
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function get(Request $request, Response $response, Handler $handler, $folder, $filename): Response {
|
||||
$file = $handler->getFile($folder, $filename);
|
||||
return $response
|
||||
->withHeader('Content-Type', $handler->getType($folder))
|
||||
->withHeader('Content-Disposition', 'attachment; filename=' . $filename)
|
||||
->withAddedHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
|
||||
->withHeader('Cache-Control', 'post-check=0, pre-check=0')
|
||||
->withHeader('Pragma', 'no-cache')
|
||||
->withBody($file);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Handler $handler, Factory $factory, $folder, $filename): Response {
|
||||
$post = json_decode($request->getBody());
|
||||
$cuenta = $factory->find(Cuenta::class)->one($post->cuenta);
|
||||
$filenfo = $handler->getInfo($folder, $filename);
|
||||
$new_name = implode('.', [implode(' - ', [$cuenta->nombre, $cuenta->categoria()->nombre, $post->fecha]), $filenfo->getExtension()]);
|
||||
$output = [
|
||||
'input' => [
|
||||
'folder' => $folder,
|
||||
'filename' => $filename,
|
||||
'post' => $post
|
||||
],
|
||||
'edited' => $handler->editFilename($folder, $filename, $new_name)
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Handler $handler, $folder, $filename): Response {
|
||||
$output = [
|
||||
'input' => [
|
||||
'folder' => $folder,
|
||||
'filename' => $filename
|
||||
],
|
||||
'deleted' => $handler->deleteFile($folder, $filename)
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
109
api/common/Service/FileHandler.php
Normal file
109
api/common/Service/FileHandler.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Service;
|
||||
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Nyholm\Psr7\Stream;
|
||||
|
||||
class FileHandler {
|
||||
protected $base_folder;
|
||||
protected $valid_types;
|
||||
protected $folders;
|
||||
public function __construct(object $params) {
|
||||
$this->base_folder = $params->folder;
|
||||
$this->addValidTypes(array_keys($params->types));
|
||||
$this->addFolders($params->types);
|
||||
}
|
||||
public function addFolders(array $folders): FileHandler {
|
||||
foreach ($folders as $type => $folder) {
|
||||
$this->addFolder($type, $folder);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function addFolder(string $type, string $folder): FileHandler {
|
||||
$this->folders[$type] = $folder;
|
||||
return $this;
|
||||
}
|
||||
public function addValidTypes(array $valid_types): FileHandler {
|
||||
foreach ($valid_types as $type) {
|
||||
$this->addValidType($type);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function addValidType(string $type): FileHandler {
|
||||
$this->valid_types []= $type;
|
||||
return $this;
|
||||
}
|
||||
public function getType(string $folder): string {
|
||||
return array_search($folder, $this->folders);
|
||||
}
|
||||
|
||||
public function uploadFile(UploadedFileInterface $file, string $new_name = null): bool {
|
||||
if ($file->getError() !== UPLOAD_ERR_OK) {
|
||||
return false;
|
||||
}
|
||||
if (!in_array($file->getClientMediaType(), array_keys($this->valid_types))) {
|
||||
return false;
|
||||
}
|
||||
if ($new_name === null) {
|
||||
$new_name = $file->getClientFilename();
|
||||
}
|
||||
$filenfo = new \SplFileInfo($file->getClientFilename());
|
||||
if (!str_contains($new_name, $filenfo->getExtension())) {
|
||||
$new_name .= '.' . $filenfo->getExtension();
|
||||
}
|
||||
$to = implode(DIRECTORY_SEPARATOR, [$this->base_folder, $this->folders[$file->getClientMediaType()], $new_name]);
|
||||
$file->moveTo($to);
|
||||
return file_exists($to);
|
||||
}
|
||||
public function listFiles(): array {
|
||||
$output = [];
|
||||
foreach ($this->folders as $f) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [$this->base_folder, $f]);
|
||||
$files = new \DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$output []= (object) ['folder' => $f, 'filename' => $file->getBasename()];
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
protected function validateFilename(string $folder, string $filename): bool|string {
|
||||
if (!in_array($folder, $this->folders)) {
|
||||
return false;
|
||||
}
|
||||
$f = implode(DIRECTORY_SEPARATOR, [$this->base_folder, $folder, $filename]);
|
||||
if (!file_exists($f)) {
|
||||
return false;
|
||||
}
|
||||
return $f;
|
||||
}
|
||||
public function getInfo(string $folder, string $filename): \SplFileInfo|bool {
|
||||
if (!$f = $this->validateFilename($folder, $filename)) {
|
||||
return false;
|
||||
}
|
||||
return new \SplFileInfo($f);
|
||||
}
|
||||
public function getFile(string $folder, string $filename): StreamInterface|bool {
|
||||
if (!$f = $this->validateFilename($folder, $filename)) {
|
||||
return false;
|
||||
}
|
||||
return Stream::create(file_get_contents($f));
|
||||
}
|
||||
public function editFilename(string $folder, string $filename, string $new_name): bool {
|
||||
if (!$f = $this->validateFilename($folder, $filename)) {
|
||||
return false;
|
||||
}
|
||||
$info = new \SplFileInfo($f);
|
||||
$new = implode(DIRECTORY_SEPARATOR, [$this->base_folder, $folder, $new_name . '.' . $info->getExtension()]);
|
||||
return rename($f, $new);
|
||||
}
|
||||
public function deleteFile(string $folder, string $filename): bool {
|
||||
if (!$f = $this->validateFilename($folder, $filename)) {
|
||||
return false;
|
||||
}
|
||||
return unlink($f);
|
||||
}
|
||||
}
|
@ -15,8 +15,7 @@ server {
|
||||
if ($request_method = 'OPTIONS') {
|
||||
add_header 'Access-Control-Max-Age' 1728000;
|
||||
add_header 'Access-Control-Allow-Origin' '*';
|
||||
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,
|
||||
X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
|
||||
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
|
||||
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
|
||||
add_header 'Content-Type' 'application/json';
|
||||
add_header 'Content-Length' 0;
|
||||
@ -24,8 +23,7 @@ server {
|
||||
}
|
||||
|
||||
add_header 'Access-Control-Allow-Origin' '*';
|
||||
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,
|
||||
X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
|
||||
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
|
||||
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
|
||||
|
||||
try_files $uri =404;
|
||||
|
Binary file not shown.
Binary file not shown.
12
api/resources/routes/uploads.php
Normal file
12
api/resources/routes/uploads.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Files;
|
||||
|
||||
$app->group('/uploads', function($app) {
|
||||
$app->post('/add[/]', [Files::class, 'upload']);
|
||||
$app->get('[/]', Files::class);
|
||||
});
|
||||
$app->group('/upload/{folder}/{filename}', function($app) {
|
||||
$app->put('[/]', [Files::class, 'edit']);
|
||||
$app->delete('[/]', [Files::class, 'delete']);
|
||||
$app->get('[/]', [Files::class, 'get']);
|
||||
});
|
@ -19,7 +19,7 @@ return [
|
||||
'public'
|
||||
]);
|
||||
$arr['uploads'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['public'],
|
||||
$arr['base'],
|
||||
'uploads'
|
||||
]);
|
||||
$arr['pdfs'] = implode(DIRECTORY_SEPARATOR, [
|
||||
|
@ -14,27 +14,27 @@ return [
|
||||
$c->get(Contabilidad\Common\Service\Auth::class)
|
||||
);
|
||||
},
|
||||
Contabilidad\Common\Service\PdfHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\PdfHandler($c->get(GuzzleHttp\Client::class), $c->get('folders')->pdfs, implode('/', [
|
||||
$c->get('urls')->python,
|
||||
'pdf',
|
||||
'parse'
|
||||
]));
|
||||
},
|
||||
Contabilidad\Common\Service\CsvHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\CsvHandler($c->get('folders')->csvs);
|
||||
},
|
||||
Contabilidad\Common\Service\XlsHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\XlsHandler($c->get('folders')->xlss);
|
||||
},
|
||||
Contabilidad\Common\Service\DocumentHandler::class => function(Container $c) {
|
||||
$handlers = [
|
||||
$c->get(Contabilidad\Common\Service\XlsHandler::class),
|
||||
$c->get(Contabilidad\Common\Service\CsvHandler::class),
|
||||
$c->get(Contabilidad\Common\Service\PdfHandler::class)
|
||||
];
|
||||
return new Contabilidad\Common\Service\DocumentHandler($handlers);
|
||||
},
|
||||
Contabilidad\Common\Service\PdfHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\PdfHandler($c->get(GuzzleHttp\Client::class), $c->get('folders')->pdfs, implode('/', [
|
||||
$c->get('urls')->python,
|
||||
'pdf',
|
||||
'parse'
|
||||
]));
|
||||
},
|
||||
Contabilidad\Common\Service\CsvHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\CsvHandler($c->get('folders')->csvs);
|
||||
},
|
||||
Contabilidad\Common\Service\XlsHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\XlsHandler($c->get('folders')->xlss);
|
||||
},
|
||||
Contabilidad\Common\Service\DocumentHandler::class => function(Container $c) {
|
||||
$handlers = [
|
||||
$c->get(Contabilidad\Common\Service\XlsHandler::class),
|
||||
$c->get(Contabilidad\Common\Service\CsvHandler::class),
|
||||
$c->get(Contabilidad\Common\Service\PdfHandler::class)
|
||||
];
|
||||
return new Contabilidad\Common\Service\DocumentHandler($handlers);
|
||||
},
|
||||
Contabilidad\Common\Service\TiposCambios::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\TiposCambios(
|
||||
$c->get(GuzzleHttp\Client::class),
|
||||
@ -42,5 +42,17 @@ return [
|
||||
$c->get('python_api'),
|
||||
$c->get('python_key')
|
||||
);
|
||||
},
|
||||
Contabilidad\Common\Service\FileHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\FileHandler((object) [
|
||||
'folder' => $c->get('folders')->uploads,
|
||||
'types' => [
|
||||
'text/csv' => 'csvs',
|
||||
'application/pdf' => 'pdfs',
|
||||
'application/vnd.ms-excel' => 'xlss',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlss',
|
||||
'application/json' => 'jsons'
|
||||
]
|
||||
]);
|
||||
}
|
||||
];
|
||||
|
Reference in New Issue
Block a user