Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show error message from opml import in web-ui #3036

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

### 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