From 2376e8532f05f451d2c0048738daf934ebdfa5e1 Mon Sep 17 00:00:00 2001 From: korelstar Date: Wed, 1 Aug 2018 19:57:45 +0200 Subject: [PATCH] don't load content for notes list in web browser --- controller/notescontroller.php | 2 +- db/note.php | 16 ++++++++++------ service/notesservice.php | 19 ++++++++++--------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/controller/notescontroller.php b/controller/notescontroller.php index ae8115468..4398dca8c 100644 --- a/controller/notescontroller.php +++ b/controller/notescontroller.php @@ -55,7 +55,7 @@ public function __construct($AppName, IRequest $request, * @NoAdminRequired */ public function index() { - return new DataResponse($this->notesService->getAll($this->userId)); + return new DataResponse($this->notesService->getAll($this->userId, true)); } diff --git a/db/note.php b/db/note.php index 7fc6ff2ea..a871f4f8b 100644 --- a/db/note.php +++ b/db/note.php @@ -56,14 +56,16 @@ public function __construct() { * @param File $file * @return static */ - public static function fromFile(File $file, Folder $notesFolder, $tags=[]){ + public static function fromFile(File $file, Folder $notesFolder, $tags=[], $onlyMeta=false) { $note = new static(); $note->setId($file->getId()); - $fileContent=$file->getContent(); - if($fileContent===false){ - throw new FileNotFoundException("File not found"); + if(!$onlyMeta) { + $fileContent=$file->getContent(); + if($fileContent===false){ + throw new FileNotFoundException("File not found"); + } + $note->setContent(self::convertEncoding($fileContent)); } - $note->setContent(self::convertEncoding($fileContent)); $note->setModified($file->getMTime()); $note->setTitle(pathinfo($file->getName(),PATHINFO_FILENAME)); // remove extension $subdir = substr(dirname($file->getPath()), strlen($notesFolder->getPath())+1); @@ -72,7 +74,9 @@ public static function fromFile(File $file, Folder $notesFolder, $tags=[]){ $note->setFavorite(true); //unset($tags[array_search(\OC\Tags::TAG_FAVORITE, $tags)]); } - $note->updateETag(); + if(!$onlyMeta) { + $note->updateETag(); + } $note->resetUpdatedFields(); return $note; } diff --git a/service/notesservice.php b/service/notesservice.php index f235a5f6e..3322b5f45 100644 --- a/service/notesservice.php +++ b/service/notesservice.php @@ -60,7 +60,7 @@ public function __construct (IRootFolder $root, IL10N $l10n, ILogger $logger, IC * @param string $userId * @return array with all notes in the current directory */ - public function getAll ($userId){ + public function getAll ($userId, $onlyMeta=false) { $notesFolder = $this->getFolderForUser($userId); $notes = $this->gatherNoteFiles($notesFolder); $filesById = []; @@ -76,7 +76,7 @@ public function getAll ($userId){ $notes = []; foreach($filesById as $id=>$file) { - $notes[] = $this->getNote($file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []); + $notes[] = $this->getNote($file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : [], $onlyMeta); } return $notes; @@ -104,21 +104,22 @@ private function getTags ($id) { } return array_key_exists($id, $tags) ? $tags[$id] : []; } - private function getNote($file,$notesFolder,$tags=[]){ + private function getNote($file, $notesFolder, $tags=[], $onlyMeta=false) { $id=$file->getId(); - - try{ - $note=Note::fromFile($file, $notesFolder, $tags); - }catch(FileNotFoundException $e){ + try { + $note=Note::fromFile($file, $notesFolder, $tags, $onlyMeta); + } catch(FileNotFoundException $e){ $note = Note::fromException($this->l10n->t('File error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []); - }catch(DecryptionFailedException $e){ + } catch(DecryptionFailedException $e) { $note = Note::fromException($this->l10n->t('Encryption Error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []); - }catch(\Exception $e){ + } catch(\Exception $e) { $note = Note::fromException($this->l10n->t('Error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []); } return $note; } + + /** * Creates a note and returns the empty note * @param string $userId