Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CarnetApp/CarnetNextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhie <phie@phie.ovh>2020-04-17 22:40:13 +0300
committerPhie <phie@phie.ovh>2020-04-17 22:40:13 +0300
commit6cc8c48e2c23c75ca0fc5f0a244e47a8124c2c8b (patch)
tree5ba7a7cfbb4b1128f6746c998f2363b692fef7a7
parent4fd06bf8a152247581b756c6e443d21ee6d139f9 (diff)
implement import api
-rwxr-xr-xappinfo/routes.php5
-rwxr-xr-xlib/Controller/NoteController.php62
-rwxr-xr-xlib/Controller/PageController.php17
3 files changed, 77 insertions, 7 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 8a613fb..2bf80fd 100755
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -13,6 +13,8 @@ return [
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#writer', 'url' => '/writer', 'verb' => 'GET'],
+ ['name' => 'page#importer', 'url' => '/importer', 'verb' => 'GET'],
+
['name' => 'page#settings', 'url' => '/settings', 'verb' => 'GET'],
['name' => 'note#getNotePath', 'url' => '/settings/note_path', 'verb' => 'GET'],
['name' => 'note#setNotePath', 'url' => '/settings/note_path', 'verb' => 'POST'],
@@ -63,5 +65,8 @@ return [
['name' => 'note#getOpusEncoderJavascript', 'url' => '/recorder/encoderWorker.min.js', 'verb' => 'GET' ],
['name' => 'note#getOpusDecoderJavascript', 'url' => '/recorder/decoderWorker.min.js', 'verb' => 'GET' ],
+
+ ['name' => 'note#importNote', 'url' => '/note/import', 'verb' => 'POST'],
+
]
]; \ No newline at end of file
diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php
index 7a6ed5e..5037061 100755
--- a/lib/Controller/NoteController.php
+++ b/lib/Controller/NoteController.php
@@ -1180,13 +1180,6 @@ public function getOpusEncoder(){
return new RedirectResponse("../../../../../index.php/apps/files/ajax/download.php?files=".$this->getNotePath());
}
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- */
- public function importNote(){
-
- }
/**
@@ -1275,5 +1268,60 @@ public function getOpusEncoder(){
}
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ */
+ public function importNote($path, $metadata, $add_to_recent, $is_pinned){
+ $notePath = (empty($path)?"":($path."/")).$_FILES['media']['name'][0];
+ $fileIn = fopen($_FILES['media']['tmp_name'][0],"r");
+ if (!$fileIn) {
+ throw new Exception('Media doesn\'t exist');
+ } else {
+ if(empty($path)){
+ $folder = $this->CarnetFolder;
+ }
+ else{
+ try {
+ $folder = $this->CarnetFolder->get($path);
+ } catch(\OCP\Files\NotFoundException $e) {
+ $folder = $this->CarnetFolder->newFolder($path);
+ }
+ }
+
+ $note = $folder->newFile($_FILES['media']['name'][0]);
+ $note->putContent($fileIn);
+ $meta = json_decode($metadata);
+ $kbactions = array();
+ foreach($meta->keywords as $keyword){
+ $kbaction = array();
+ $kbaction["action"] = "add";
+ $kbaction["time"] = $meta->creation_date;
+ $kbaction["keyword"] = $keyword;
+ $kbaction["path"] = $notePath;
+
+ array_push($kbactions,$kbaction);
+ }
+ $this->internalPostKeywordsActions($kbactions);
+ $add_to_recent = $_POST['add_to_recent'];
+ if($add_to_recent){
+ $dbactions = array();
+ $dbaction = array();
+ $dbaction["action"] = "add";
+ $dbaction["time"] = $meta->creation_date;
+ $dbaction["path"] = $notePath;
+ array_push($dbactions,$dbaction);
+ if($is_pinned == "true"){
+ $dbaction = array();
+ $dbaction["action"] = "pin";
+ $dbaction["time"] = $meta->creation_date;
+ $dbaction["path"] = $notePath;
+ array_push($dbactions,$dbaction);
+ }
+
+ $this->internalPostActions($dbactions);
+ }
+ }
+ }
}
?>
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 69ce4d4..75dee1f 100755
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -73,6 +73,23 @@ class PageController extends Controller {
$response = new TemplateResponse($this->appName,"settings", $parameters);
if($this->config->getAppValue('carnet', 'carnetDisplayFullscreen', 'no') === "yes")
$response->renderAs("blank");
+ $policy = new ContentSecurityPolicy();
+ $policy->addAllowedFrameDomain('\'self\'');
+ $response->setContentSecurityPolicy($policy); // allow iframe
+ return $response;
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ */
+ public function importer() {
+ $parameters = [
+ 'app_version' => App::getAppInfo($this->appName)['version'],
+ ];
+ $response = new TemplateResponse($this->appName,"importer", $parameters);
+ $response->renderAs("blank");
+
return $response;
}