Skip to content

Commit

Permalink
feat: show error message from opml import in web-ui
Browse files Browse the repository at this point in the history
Signed-off-by: Wolfgang <[email protected]>
  • Loading branch information
wofferl committed Jan 8, 2025
1 parent 31cb113 commit ca99a17
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the
## [25.x.x]
### Changed
- add explanations for the individual values in the feed information table
- show error message from opml import in web-ui

Check failure on line 11 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'opml'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'opml'?", "location": {"path": "CHANGELOG.md", "range": {"start": {"line": 11, "column": 27}}}, "severity": "ERROR"}

### Fixed

Expand Down
20 changes: 18 additions & 2 deletions lib/Controller/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace OCA\News\Controller;

use OCA\News\Service\OpmlService;
use OCA\News\Service\Exceptions\ServiceValidationException;
use \OCP\IRequest;
use OCP\IUserSession;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
Expand All @@ -38,7 +39,7 @@ public function __construct(

#[NoCSRFRequired]
#[NoAdminRequired]
public function opml(): void
public function opml(): array
{
$data = '';
if (isset($this->request->files['file'])) {
Expand All @@ -49,6 +50,21 @@ public function opml(): void
}


$this->opmlService->import($this->getUserId(), $data);
$status = '';
$message = '';
try {
$this->opmlService->import($this->getUserId(), $data);
$status = "ok";
} catch (ServiceValidationException $e) {
$status = "error";
$message = $e->getMessage();
}

$response = [
'status' => $status,
'message' => $message,
];

return $response;
}
}
7 changes: 6 additions & 1 deletion src/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,12 @@ export default Vue.extend({
})
if (response.ok) {
showSuccess(t('news', 'File successfully uploaded'))
const data = await response.json()
if (data.status === 'ok') {
showSuccess(t('news', 'File successfully uploaded'))
} else {
showError(data.message, { timeout: -1 })
}
} else {
showError(t('news', 'Error uploading the opml file'))
}
Expand Down

0 comments on commit ca99a17

Please sign in to comment.