Skip to content

Commit

Permalink
Replaced dictionary import process from file copying to file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
simjanos-dev committed May 24, 2024
1 parent a8faf48 commit 38c3040
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 337 deletions.
25 changes: 14 additions & 11 deletions app/Http/Controllers/DictionaryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use App\Services\DictionaryImportService;


// request classes
use App\Http\Requests\Dictionaries\GetDictionaryFileInformationRequest;

class DictionaryController extends Controller
{
/*
Expand Down Expand Up @@ -614,18 +617,18 @@ public function importDictionaryCsvFile(Request $request) {
return 'success';
}

/*
Scans the /storage/app/dictionaries folder,
and returns a list of importable dictionaries.
*/
public function getImportableDictionaryList() {

public function getDictionaryFileInformation(GetDictionaryFileInformationRequest $request) {
$dictionaryFile = $request->file('dictionaryFile');
$dictCcLanguageCodes = config('linguacafe.languages.dict_cc_language_codes');
$databaseLanguageCodes = config('linguacafe.languages.database_name_language_codes');
$supportedSourceLanguages = config('linguacafe.languages.supported_languages');

$dictionaryImportService = new DictionaryImportService();
$dictionariesFound = $dictionaryImportService->getImportableDictionaryList($supportedSourceLanguages, $dictCcLanguageCodes, $databaseLanguageCodes);
try {
$dictionaryImportService = new DictionaryImportService();
$dictionariesFound = $dictionaryImportService->getDictionaryFileInformation($dictionaryFile, $supportedSourceLanguages, $dictCcLanguageCodes, $databaseLanguageCodes);
} catch (\Exception $e) {
abort(500, $e->getMessage());
}

return json_encode($dictionariesFound);
}
Expand All @@ -637,7 +640,7 @@ public function importSupportedDictionary(Request $request) {
$dictionarySourceLanguage = $request->post('dictionarySourceLanguage');
$dictionaryTargetLanguage = $request->post('dictionaryTargetLanguage');
$dictionaryDatabaseName = $request->post('dictionaryDatabaseName');

// import jmdict files
if ($dictionaryName == 'JMDict') {
try {
Expand All @@ -646,9 +649,9 @@ public function importSupportedDictionary(Request $request) {
$dictionaryImportService->kanjiImport();
$dictionaryImportService->kanjiRadicalImport();
} catch (\Throwable $t) {
return 'error';
return $t->getMessage();
} catch (\Exception $e) {
return 'error';
return $e->getMessage();
}

return 'success';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests\Dictionaries;

use Illuminate\Foundation\Http\FormRequest;

class GetDictionaryFileInformationRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'dictionaryFile' => 'required|file',
];
}
}
Loading

0 comments on commit 38c3040

Please sign in to comment.