diff options
author | Phie <phie@phie.ovh> | 2019-11-08 21:15:03 +0300 |
---|---|---|
committer | Phie <phie@phie.ovh> | 2019-11-08 21:15:03 +0300 |
commit | 8e2288aa64941369a901160ecc722de1d24fc9c1 (patch) | |
tree | 48b909a65833c3f423189db0e52f6262c42cf5a2 /lib | |
parent | 63c42ca8ec130376c163ce22f1bdfb378dcc32b7 (diff) |
premisces to folder-note support instead of zip
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Controller/NoteController.php | 80 | ||||
-rw-r--r-- | lib/Misc/NoteUtils.php | 83 |
2 files changed, 110 insertions, 53 deletions
diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index 59644aa..b24f686 100755 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -49,6 +49,10 @@ // \OC_Util::setupFS($UserId); } + + public function isNote($node){ + return $node->getType() !== "dir" || substr($node->getName(), 0, strlen("note$")) === "note$"; + } /** * CAUTION: the @Stuff turns off security checks; for this page no admin is * required and no CSRF check. If you don't know what CSRF is, read @@ -67,11 +71,12 @@ $paths = array(); $data = array(); foreach($this->CarnetFolder->get($path)->getDirectoryListing() as $in){ + $inf = $in->getFileInfo(); $file = array(); $file['name'] = $inf->getName(); $file['path'] = $path.$inf->getName(); - $file['isDir'] = $inf->getType() === "dir"; + $file['isDir'] = !$this->isNote($inf); $file['mtime'] = $inf->getMtime(); if($inf->getType() !== "dir"){ array_push($paths, $file['path']); @@ -909,17 +914,26 @@ public function getOpusEncoder(){ $data = array(); $path = $_GET['path']; - $cache = $this->getCacheFolder(); try{ - $tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip"); - file_put_contents($tmppath,$this->CarnetFolder->get($path)->fopen("r")); - $zipFile = new MyZipFile(); - $zipFile->openFile($tmppath); - try{ - $data['metadata'] = json_decode($zipFile['metadata.json']); - } catch(\PhpZip\Exception\ZipNotFoundEntry $e){} - $data['html'] = $zipFile['index.html']; - unlink($tmppath); + $noteNode = $this->CarnetFolder->get($path); + if($noteNode->getType() === "dir"){ + $data['html'] = $noteNode->get('index.html')->getContent(); + try{ + $data['metadata'] = json_decode($noteNode->get('metadata.json')->getContent()); + } catch(\OCP\Files\NotFoundException $e) { + } + } + else { + $tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip"); + file_put_contents($tmppath,$noteNode->fopen("r")); + $zipFile = new MyZipFile(); + $zipFile->openFile($tmppath); + try{ + $data['metadata'] = json_decode($zipFile['metadata.json']); + } catch(\PhpZip\Exception\ZipNotFoundEntry $e){} + $data['html'] = $zipFile['index.html']; + unlink($tmppath); + } } catch(\OCP\Files\NotFoundException $e) { $data["error"] = "not found"; } @@ -949,28 +963,36 @@ public function getOpusEncoder(){ } } } - $folder = $cache->newFolder("currentnote".$editUniqueID); - + + $noteFolderName = "currentnote".$editUniqueID; try{ - $tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip"); - file_put_contents($tmppath,$this->CarnetFolder->get($path)->fopen("r")); - $zipFile = new \PhpZip\ZipFile(); - $zipFile->openFile($tmppath); - foreach($zipFile as $entryName => $contents){ - if($entryName === ".extraction_finished") - continue; - if($contents === "" AND $zipFile->isDirectory($entryName)){ - $folder->newFolder($entryName); + + $noteNode = $this->CarnetFolder->get($path); + if($noteNode->getType() === "dir"){ + $folder = $noteNode->copy($cache->getFullPath($noteFolderName)); } - else if($contents !== "" && $contents !== NULL){ - $parent = dirname($entryName); - if($parent !== "." && !$folder->nodeExists($parent)){ - $folder->newFolder($parent); + else{ + $folder = $cache->newFolder($noteFolderNam); + $tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip"); + file_put_contents($tmppath,$noteNode->fopen("r")); + $zipFile = new \PhpZip\ZipFile(); + $zipFile->openFile($tmppath); + foreach($zipFile as $entryName => $contents){ + if($entryName === ".extraction_finished") + continue; + if($contents === "" AND $zipFile->isDirectory($entryName)){ + $folder->newFolder($entryName); + } + else if($contents !== "" && $contents !== NULL){ + $parent = dirname($entryName); + if($parent !== "." && !$folder->nodeExists($parent)){ + $folder->newFolder($parent); + } + $folder->newFile($entryName)->putContent($contents); + } } - $folder->newFile($entryName)->putContent($contents); + unlink($tmppath); } - } - unlink($tmppath); } catch(\OCP\Files\NotFoundException $e) { } diff --git a/lib/Misc/NoteUtils.php b/lib/Misc/NoteUtils.php index 80921f4..fc03209 100644 --- a/lib/Misc/NoteUtils.php +++ b/lib/Misc/NoteUtils.php @@ -7,44 +7,79 @@ class NoteUtils{ } public function getMetadata($carnetFolder, $path){ $meta = array(); - $tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip"); $node = $carnetFolder->get($path); - - file_put_contents($tmppath, $node->fopen("r")); - $zipFile = new \PhpZip\ZipFile(); - $zipFile->openFromStream(fopen($tmppath, "r")); //issue with encryption when open directly + unexpectedly faster to copy before Oo' + if($node->getType() === "dir"){ $meta['lastmodfile'] = $node->getMTime(); try{ - $meta['metadata'] = json_decode($zipFile->getEntryContents("metadata.json")); - } catch(\PhpZip\Exception\ZipNotFoundEntry $e){ + $meta['metadata'] = json_decode($node->get('metadata.json')->getContent()); + } catch(\OCP\Files\NotFoundException $e){ } try{ - - $meta['shorttext'] = self::getShortTextFromHTML($zipFile->getEntryContents("index.html")); - $meta['media'] = array(); - $meta['previews'] = array(); + + $meta['shorttext'] = self::getShortTextFromHTML($node->get('index.html')->getContent()); + $meta['media'] = array(); + $meta['previews'] = array(); - $i=0; - try{ - foreach($zipFile->getListFiles() as $f){ - if(substr($f, 0, strlen("data/preview")) === "data/preview"){ - $meta['previews'][$i] = "./note/getmedia?note=".$path."&media=".$f; - $i++; - } else if(substr($f, 0, strlen("data/")) === "data/") { - $meta['media'][$i] = "./note/getmedia?note=".$path."&media=".$f; + $i=0; + try{ + foreach($node->get('data')->getDirectoryListing() as $in){ + if(substr($in->getName(), 0, strlen("preview")) === "preview"){ + $meta['previews'][$i] = "./note/getmedia?note=".$path."&media=data/".$in->getName(); + $i++; + } else { + $meta['media'][$i] = "./note/getmedia?note=".$path."&media=data/".$in->getName(); + } + } + } + catch(\OCP\Files\NotFoundException$e){ } } - catch(\PhpZip\Exception\ZipNotFoundEntry $e){ - + catch(\OCP\Files\NotFoundException $e){ + } - } catch(\PhpZip\Exception\ZipNotFoundEntry $e){ - $meta['shorttext'] = ""; + } + else{ + $tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip"); + file_put_contents($tmppath, $node->fopen("r")); + $zipFile = new \PhpZip\ZipFile(); + $zipFile->openFromStream(fopen($tmppath, "r")); //issue with encryption when open directly + unexpectedly faster to copy before Oo' + $meta['lastmodfile'] = $node->getMTime(); + try{ + $meta['metadata'] = json_decode($zipFile->getEntryContents("metadata.json")); + } catch(\PhpZip\Exception\ZipNotFoundEntry $e){ + + } + try{ + + $meta['shorttext'] = self::getShortTextFromHTML($zipFile->getEntryContents("index.html")); + $meta['media'] = array(); + $meta['previews'] = array(); + + $i=0; + try{ + foreach($zipFile->getListFiles() as $f){ + if(substr($f, 0, strlen("data/preview")) === "data/preview"){ + $meta['previews'][$i] = "./note/getmedia?note=".$path."&media=".$f; + $i++; + } else if(substr($f, 0, strlen("data/")) === "data/") { + $meta['media'][$i] = "./note/getmedia?note=".$path."&media=".$f; + } + + } + } + catch(\PhpZip\Exception\ZipNotFoundEntry $e){ + + } + } catch(\PhpZip\Exception\ZipNotFoundEntry $e){ + $meta['shorttext'] = ""; + + } + unlink($tmppath); } - unlink($tmppath); return $meta; } |