Skip to content

Commit

Permalink
metadata save for folder
Browse files Browse the repository at this point in the history
  • Loading branch information
PhieF committed Jul 31, 2024
1 parent 4fe5754 commit 878096d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ function () use ($container, $appName) {
'name' => 'Carnet'
];
}
);
);

?>
46 changes: 28 additions & 18 deletions lib/Controller/NoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,29 +554,39 @@ public function createNote(){
* @NoCSRFRequired
*/
public function updateMetadata($path, $metadata){

$tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip");
$tmppath2 = tempnam(sys_get_temp_dir(), uniqid().".zip");
if(!file_put_contents($tmppath, $this->CarnetFolder->get($path)->fopen("r")))
return;

$zipFile = new \PhpZip\ZipFile();
$zipFile->openFromStream(fopen($tmppath, "r")); //issue with encryption when open directly + unexpectedly faster to copy before Oo'
$zipFile->addFromString("metadata.json", $metadata, \PhpZip\ZipFile::METHOD_DEFLATED);
$zipFile->saveAsFile($tmppath2);
$tmph = fopen($tmppath2, "r");
if($tmph){

if(NoteUtils::isFolderNote($path, $this->CarnetFolder)){
try{
$file = $this->CarnetFolder->get($path);
$file->putContent($tmph);
$noteNode = $this->CarnetFolder->get($path);
$file = $noteNode->get("metadata.json");
$file->putContent($metadata);

} catch(\OCP\Files\NotFoundException $e) {
}
fclose($tmph);
} else
throw new Exception('Unable to create Zip');
unlink($tmppath);
unlink($tmppath2);
} else {
$tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip");
$tmppath2 = tempnam(sys_get_temp_dir(), uniqid().".zip");
if(!file_put_contents($tmppath, $this->CarnetFolder->get($path)->fopen("r")))
return;

$zipFile = new \PhpZip\ZipFile();
$zipFile->openFromStream(fopen($tmppath, "r")); //issue with encryption when open directly + unexpectedly faster to copy before Oo'
$zipFile->addFromString("metadata.json", $metadata, \PhpZip\ZipFile::METHOD_DEFLATED);
$zipFile->saveAsFile($tmppath2);
$tmph = fopen($tmppath2, "r");
if($tmph){
try{
$file = $this->CarnetFolder->get($path);
$file->putContent($tmph);
} catch(\OCP\Files\NotFoundException $e) {
}
fclose($tmph);
} else
throw new Exception('Unable to create Zip');
unlink($tmppath);
unlink($tmppath2);
}
}


Expand Down
5 changes: 5 additions & 0 deletions lib/Misc/NoteUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public static function getShortText($text){ //not optimized at alllll....
return mb_substr($text, 0, 150);
}

public static function isFolderNote($path, $carnetFolder){
$node = $carnetFolder->get($path);
return $node->getType() === "dir" && self::isNote($path);
}

public static function isNote($path){
return self::endsWith($path, ".sqd");
}
Expand Down

0 comments on commit 878096d

Please sign in to comment.