Browse Source

Add auto upload methods

pull/24/head
James Cole 4 years ago
parent
commit
5d01127455
  1. 38
      app/Console/AutoImports.php
  2. 10
      app/Http/Controllers/AutoImportController.php
  3. 11
      app/Http/Controllers/AutoUploadController.php
  4. 1
      config/importer.php
  5. 2
      routes/web.php

38
app/Console/AutoImports.php

@ -395,4 +395,42 @@ trait AutoImports
}
}
}
/**
* @param string $csvFile
* @param string $jsonFile
*/
private function importUpload(string $csvFile, string $jsonFile): void
{
// do JSON check
$jsonResult = $this->verifyJSON($jsonFile);
if (false === $jsonResult) {
$message = sprintf('The importer can\'t import %s: could not decode the JSON in config file %s.', $csvFile, $jsonFile);
$this->error($message);
return;
}
$configuration = Configuration::fromArray(json_decode(file_get_contents($jsonFile), true));
$configuration->updateDateRange();
$this->line(sprintf('Going to convert from file %s using configuration %s and flow "%s".', $csvFile, $jsonFile, $configuration->getFlow()));
// this is it!
$this->startConversion($configuration, $csvFile);
$this->reportConversion();
$this->line(sprintf('Done converting from file %s using configuration %s.', $csvFile, $jsonFile));
$this->startImport($configuration);
$this->reportImport();
$this->line('Done!');
event(new ImportedTransactions(
array_merge($this->conversionMessages, $this->importMessages),
array_merge($this->conversionWarnings, $this->importWarnings),
array_merge($this->conversionErrors, $this->importErrors)
)
);
}
}

10
app/Http/Controllers/AutoImportController.php

@ -48,11 +48,6 @@ class AutoImportController extends Controller
*/
public function index(Request $request): Response
{
$access = $this->haveAccess();
if (false === $access) {
throw new ImporterErrorException('Could not connect to your local Firefly III instance.');
}
if (false === config('importer.can_post_autoimport')) {
throw new ImporterErrorException('Disabled, not allowed to import.');
}
@ -70,6 +65,11 @@ class AutoImportController extends Controller
throw new ImporterErrorException('Not allowed to import from this path.');
}
$access = $this->haveAccess();
if (false === $access) {
throw new ImporterErrorException('Could not connect to your local Firefly III instance.');
}
// take code from auto importer.
app('log')->info(sprintf('Going to automatically import everything found in %s (%s)', $directory, $argument));

11
app/Http/Controllers/AutoUploadController.php

@ -45,7 +45,16 @@ class AutoUploadController extends Controller
*/
public function index(AutoUploadRequest $request)
{
die('todo' . __METHOD__);
if (false === config('importer.can_post_files')) {
throw new ImporterErrorException('Disabled, not allowed to import.');
}
$secret = (string) ($request->get('secret') ?? '');
$systemSecret = (string) config('importer.auto_import_secret');
if ('' === $secret || '' === $systemSecret || $secret !== config('importer.auto_import_secret') || strlen($systemSecret) < 16) {
throw new ImporterErrorException('Bad secret, not allowed to import.');
}
$access = $this->haveAccess();
if (false === $access) {
throw new ImporterErrorException('Could not connect to your local Firefly III instance.');

1
config/importer.php

@ -33,6 +33,7 @@ return [
'import_dir_whitelist' => explode(',', env('IMPORT_DIR_WHITELIST', '')),
'auto_import_secret' => env('AUTO_IMPORT_SECRET', ''),
'can_post_autoimport' => env('CAN_POST_AUTOIMPORT', false),
'can_post_files' => env('CAN_POST_FILES', false),
'access_token' => env('FIREFLY_III_ACCESS_TOKEN'),
'url' => env('FIREFLY_III_URL'),
'client_id' => env('FIREFLY_III_CLIENT_ID'),

2
routes/web.php

@ -103,7 +103,7 @@ Route::get('/back/conversion', 'NavController@toConversion')->name('back.convers
// import by POST
Route::post('/autoimport', 'AutoImportController@index')->name('autoimport');
//Route::post('/autoupload', 'AutoUploadController@index')->name('autoupload');
Route::post('/autoupload', 'AutoUploadController@index')->name('autoupload');
//
//

Loading…
Cancel
Save