Skip to content

Commit

Permalink
Merge branch 'new-client'
Browse files Browse the repository at this point in the history
  • Loading branch information
PhieF committed Aug 13, 2023
2 parents 0ab1600 + b5d6f06 commit e694e88
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 34 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Version 0.25.0

Introducing new Markdown Editor 🎉
available for now only as an option in settings, still not complete, but will become the default option in the future
Built with tiptap editor and tiptap-markdown extension from https://github.com/aguingand/tiptap-markdown


Multiple fixes
better packaging for the whole client

# Version 0.24.0 - 0.24.1

Option to create note as folder (beta for dev)
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,45 @@ What is Carnet ?
You can help with translations on the dedicated platform

[weblate](https://weblate.lostpod.me)


## Development

Carnet For Nextcloud is divided into two parts:

- The server part (this repo)
- And the client part [here](../CarnetWebClient)


### Prepare your environment

To start developping Carnet, you will need a working Nextcloud install

Then, from your favorite dev folder:

Create a carnet folder where all the dev for server and clients will happen:

```
mkdir carnet
cd carnet
```

Follow instructions on building [CarnetWebClient](../CarnetWebClient)

Link it to templates inside the nextcloud app

```
git clone https://github.com/CarnetApp/CarnetNextcloud
current=`pwd`
cd CarnetNextcloud
ln -s "$current"/CarnetWebClient/dist templates/CarnetWebClient
```
This should create a link called CarnetWebClient to the dist folder of CarnetWebClient, inside templates

Then create a link to your nextcloud installation (replace nextcloud-install-folder with appropriate path)

```
ln -s "$current"/CarnetNextcloud nextcloud-install-folder/apps/carnet
```

Then activate is within nextcloud interface !
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Mac, with sync capabilities
- Statistics : words/sentences/characters
- Sync with ownCloud/NextCloud
- Online editor as a ownCloud/NextCloud App]]></description>
<version>0.24.7</version>
<version>0.25.0</version>
<licence>agpl</licence>
<author mail="[email protected]" >Phie</author>
<namespace>Carnet</namespace>
Expand All @@ -33,7 +33,7 @@ Mac, with sync capabilities
<filesystem/>
</types>
<dependencies>
<nextcloud min-version="13" max-version="26"/>
<nextcloud min-version="13" max-version="27"/>
<owncloud min-version="10" max-version="10"/>

</dependencies>
Expand Down
7 changes: 4 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
['name' => 'note#deleteNote', 'url' => '/notes', 'verb' => 'DELETE'],
['name' => 'note#search', 'url' => '/notes/search', 'verb' => 'GET'],
['name' => 'note#getSearchCache', 'url' => '/notes/getSearchCache', 'verb' => 'GET'],
['name' => 'note#getUbuntuFont', 'url' => '/templates/CarnetElectron/fonts/ubuntu.woff2', 'verb' => 'GET' ],
['name' => 'note#getMaterialFont', 'url' => '/templates/CarnetElectron/fonts/material-icons.woff2', 'verb' => 'GET' ],
['name' => 'note#getUbuntuFont', 'url' => '/templates/CarnetWebClient/fonts/ubuntu.woff2', 'verb' => 'GET' ],
['name' => 'note#getMaterialFont', 'url' => '/templates/CarnetWebClient/fonts/material-icons.woff2', 'verb' => 'GET' ],
['name' => 'note#getChangelog', 'url' => '/settings/changelog', 'verb' => 'GET' ],
['name' => 'note#getLangJson', 'url' => '/settings/lang/json', 'verb' => 'GET' ],
['name' => 'note#getUISettings', 'url' => '/settings/ui', 'verb' => 'GET' ],
Expand All @@ -76,7 +76,8 @@

['name' => 'note#setShouldUseFolderNotes', 'url' => '/settings/note_folder', 'verb' => 'POST' ],
['name' => 'note#shouldUseFolderNotes', 'url' => '/settings/note_folder', 'verb' => 'GET' ],

['name' => 'note#useMDEditor', 'url' => '/settings/use_md_editor', 'verb' => 'GET' ],
['name' => 'note#setUseMDEditor', 'url' => '/settings/use_md_editor', 'verb' => 'POST' ]

]
];
67 changes: 47 additions & 20 deletions lib/Controller/NoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private function getKeywordsDBFile(){
*/
public function getLangJson($lang){
if($lang !== ".." && $lang !== "../"){
$response = new StreamResponse(__DIR__.'/../../templates/CarnetElectron/i18n/'.$lang.".json");
$response = new StreamResponse(__DIR__.'/../../templates/CarnetWebClient/i18n/'.$lang.".json");
$response->addHeader("Content-Type", "application/json");
$response->cacheFor(604800);
return $response;
Expand All @@ -296,7 +296,7 @@ public function getLangJson($lang){
* @NoCSRFRequired
*/
public function getOpusDecoderJavascript(){
$response = new StreamResponse(__DIR__.'/../../templates/CarnetElectron/reader/libs/recorder/decoderWorker.min.js');
$response = new StreamResponse(__DIR__.'/../../templates/CarnetWebClient/reader/libs/recorder/decoderWorker.min.js');
$response->addHeader("Content-Type", "application/javascript");
return $response;
}
Expand All @@ -307,7 +307,7 @@ public function getOpusDecoderJavascript(){
* @NoCSRFRequired
*/
public function getOpusEncoderJavascript(){
$response = new StreamResponse(__DIR__.'/../../templates/CarnetElectron/reader/libs/recorder/encoderWorker.min.js');
$response = new StreamResponse(__DIR__.'/../../templates/CarnetWebClient/reader/libs/recorder/encoderWorker.min.js');
$response->addHeader("Content-Type", "application/javascript");
return $response;
}
Expand All @@ -320,7 +320,7 @@ public function getOpusEncoderJavascript(){
public function getOpusEncoder(){
echo"bla";
return;
$response = new StreamResponse(__DIR__.'/../../templates/CarnetElectron/reader/libs/recorder/encoderWorker.min.wasm');
$response = new StreamResponse(__DIR__.'/../../templates/CarnetWebClient/reader/libs/recorder/encoderWorker.min.wasm');
$response->addHeader("Content-Type", "application/wasm");
return $response;
}
Expand All @@ -332,7 +332,7 @@ public function getOpusEncoder(){
public function getUbuntuFont(){
$font = basename($_SERVER['REQUEST_URI']);
if($font !== ".." && $font !== "../")
return new StreamResponse(__DIR__.'/../../templates/CarnetElectron/fonts/'.basename($_SERVER['REQUEST_URI']));
return new StreamResponse(__DIR__.'/../../templates/CarnetWebClient/fonts/'.basename($_SERVER['REQUEST_URI']));
else
die();
}
Expand All @@ -344,7 +344,7 @@ public function getUbuntuFont(){
public function getMaterialFont(){
$font = basename($_SERVER['REQUEST_URI']);
if($font !== ".." && $font !== "../")
return new StreamResponse(__DIR__.'/../../templates/CarnetElectron/fonts/'.basename($_SERVER['REQUEST_URI']));
return new StreamResponse(__DIR__.'/../../templates/CarnetWebClient/fonts/'.basename($_SERVER['REQUEST_URI']));
else
die();
}
Expand Down Expand Up @@ -739,20 +739,22 @@ public function saveTextToOpenNote(){
$this->waitEndOfExtraction($id);
$cache = $this->getCacheFolder();
$folder = $cache->get("currentnote".$id);
$mainFile = $_POST['isMarkdown'] ? "note.md" : "index.html";
try{
$file = $folder->get("index.html");
$file = $folder->get($mainFile);
} catch(\OCP\Files\NotFoundException $e) {
$file = $folder->newFile("index.html");
$file = $folder->newFile($mainFile);
}
$file->putContent($_POST['html']);

try{
$file = $folder->get("metadata.json");
} catch(\OCP\Files\NotFoundException $e) {
$file = $folder->newFile("metadata.json");
}
$file->putContent($_POST['metadata']);
$path = $_POST['path'];
$mtime = $this->saveFiles($folder, array(0 => "index.html", 1 =>"metadata.json"), $_POST['path'], $id);
$mtime = $this->saveFiles($folder, array(0 => $mainFile, 1 =>"metadata.json"), $_POST['path'], $id);
if($mtime !== false){
//we need to refresh cache
$cache = new CacheManager($this->db, $this->CarnetFolder);
Expand Down Expand Up @@ -785,7 +787,7 @@ private function saveFiles($inFolder, $files, $path, $id){
return false;
}
} catch(\OCP\Files\NotFoundException $e) {
if($this->shouldUseFolderNotes()){
if($this->shouldUseFolderNotes() || $_POST['isMarkdown']){
return $this->saveOpenNoteAsDir($inFolder, $files, $path, $id);
} else {
$this->saveOpenNote($_POST['path'],$id);
Expand Down Expand Up @@ -905,6 +907,7 @@ public function deleteMediaFromOpenNote($id){
* @NoCSRFRequired
*/
public function addMediaToOpenNote($id){
$path = $_POST['path'];
$this->waitEndOfExtraction($id);
$cache = $this->getCacheFolder();
$folder = $cache->get("currentnote".$id);
Expand Down Expand Up @@ -999,7 +1002,7 @@ public function addMediaToOpenNote($id){
}
if(!isset($meta['media']))
$meta['media'] = array();
if(!in_array($meta['media'],$media))
if(!in_array($media, $meta['media']))
array_push($meta['media'],$media);
$cache->addToCache($path, $meta, $mtime, $text);

Expand Down Expand Up @@ -1158,7 +1161,14 @@ public function openNote(){
try{
$noteNode = $this->CarnetFolder->get($path);
if($noteNode->getType() === "dir"){
$data['html'] = $noteNode->get('index.html')->getContent();
if ($noteNode->nodeExists("note.md")){
$data['html'] = $noteNode->get("note.md")->getContent();
$data['isMarkdown'] = true;
}
else {
$data['html'] = $noteNode->get('index.html')->getContent();
$data['isMarkdown'] = false;
}
try{
$data['metadata'] = json_decode($noteNode->get('metadata.json')->getContent());
} catch(\OCP\Files\NotFoundException $e) {
Expand All @@ -1177,6 +1187,7 @@ public function openNote(){
}
} catch(\OCP\Files\NotFoundException $e) {
$data["error"] = "not found";
$data["isNew"] = true;
}

$data['id'] = $editUniqueID;
Expand Down Expand Up @@ -1293,6 +1304,22 @@ public function update($id, $title, $content) {
// empty for now
}

public function useMDEditor(){
return $this->Config->getUserValue($this->userId, $this->appName, "use_md_editor",0);
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function setUseMDEditor($useMD){
if($useMD === "false")
$useMD = 0;
else if($useMD === "true")
$useMD = 1 ;
return $this->Config->setUserValue($this->userId, $this->appName, "use_md_editor", $useMD);
}

public function shouldUseFolderNotes(){
return $this->Config->getUserValue($this->userId, $this->appName, "should_use_folder_notes",false);
}
Expand Down Expand Up @@ -1329,16 +1356,16 @@ public function downloadArchive(){
* @NoCSRFRequired
*/
public function getAppThemes(){
$root = $this->getCarnetElectronUrl()."/css/";
return json_decode('[{"name":"Carnet", "path":"'.$this->getCarnetElectronPath().'/css/carnet", "preview":"'.$root.'carnet/preview.png"}, {"name":"Dark", "path":"'.$this->getCarnetElectronPath().'/css/dark", "preview":"'.$root.'dark/preview.png"}, {"name":"Black", "path":"'.$this->getCarnetElectronPath().'/css/black", "preview":"'.$root.'black/preview.png"}]');
$root = $this->getCarnetWebClientUrl()."/css/";
return json_decode('[{"name":"Carnet", "path":"'.$this->getCarnetWebClientPath().'/css/carnet", "preview":"'.$root.'carnet/preview.png"}, {"name":"Dark", "path":"'.$this->getCarnetWebClientPath().'/css/dark", "preview":"'.$root.'dark/preview.png"}, {"name":"Black", "path":"'.$this->getCarnetWebClientPath().'/css/black", "preview":"'.$root.'black/preview.png"}]');
}

private function getCarnetElectronPath(){
return __DIR__.'/../../templates/CarnetElectron';
private function getCarnetWebClientPath(){
return __DIR__.'/../../templates/CarnetWebClient';
}

private function getCarnetElectronUrl(){
$root = \OCP\Util::linkToAbsolute($this->appName,"templates")."/CarnetElectron";
private function getCarnetWebClientUrl(){
$root = \OCP\Util::linkToAbsolute($this->appName,"templates")."/CarnetWebClient";
if(strpos($root,"http://") === 0 && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'){
//should be https...
$root = "https".substr($root,strlen("http"));
Expand All @@ -1357,8 +1384,8 @@ public function setAppTheme($url){
$browser = array();
$editor = array();
$settings = array();
if(strpos($url, $this->getCarnetElectronPath()) === 0){
$url = $this->getCarnetElectronUrl().substr($url, strlen($this->getCarnetElectronPath()), strlen($url));
if(strpos($url, $this->getCarnetWebClientPath()) === 0){
$url = $this->getCarnetWebClientUrl().substr($url, strlen($this->getCarnetWebClientPath()), strlen($url));
}
foreach($meta['browser'] as $css){
array_push($browser, $url."/".$css);
Expand Down
8 changes: 6 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function browser() {
'carnet_display_fullscreen' => $this->config->getAppValue('carnet', 'carnetDisplayFullscreen', 'no'),
'app_version' => OC_App::getAppInfo($this->appName)['version'],
];
$response = new TemplateResponse($this->appName,"browser",$parameters);
$response = new TemplateResponse($this->appName,"new_browser",$parameters);
$response->renderAs("blank");
$policy = new ContentSecurityPolicy();
$policy->addAllowedFrameDomain('\'self\'');
Expand Down Expand Up @@ -78,7 +78,11 @@ public function writer() {
$parameters = [
'app_version' => OC_App::getAppInfo($this->appName)['version'],
];
$response = new TemplateResponse($this->appName,"writer",$parameters);
if($this->config->getUserValue($this->userId, $this->appName, "use_md_editor",0)){
$response = new TemplateResponse($this->appName,"new_editor",$parameters);
}
else
$response = new TemplateResponse($this->appName,"writer",$parameters);
$policy = new ContentSecurityPolicy();
$policy->addAllowedMediaDomain('blob:');
$policy->addAllowedFrameDomain('\'self\'');
Expand Down
4 changes: 4 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ rm carnet-*-v*
cur=$(pwd)
cp . ../tmpcarnet/carnet -R
cd ../tmpcarnet/carnet/
echo "Copying CarnetWebClient"
sudo rm templates/CarnetWebClient
cp ../../CarnetWebClient/dist templates/CarnetWebClient -R
echo "Cleaning"
sudo rm .git -R
sudo rm templates/CarnetElectron/.git -R
sudo rm templates/CarnetElectron/node_modules/ -R
Expand Down
2 changes: 1 addition & 1 deletion templates/CarnetElectron
1 change: 1 addition & 0 deletions templates/CarnetWebClient
60 changes: 60 additions & 0 deletions templates/new_browser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
global $currentpath;
global $root;
global $fullscreen;
global $appVersion;
$fullscreen = "yes";
$appVersion = $_['app_version'];
$currentpath = __DIR__."/CarnetWebClient/";
$root = \OCP\Util::linkToAbsolute("carnet","templates");
$file = file_get_contents($currentpath."index.html");
$root = parse_url($root, PHP_URL_PATH);

$file = preg_replace_callback('/<link(.*?)href=\"(.*?\.css(?:\?.*?)?)"/s',function ($matches) {
global $currentpath;
global $appVersion;
return "<link".$matches[1]."href=\"".$matches[2]."?v=".$appVersion."\"";
}, $file);
$file = str_replace("href=\"","href=\"".$root."/CarnetWebClient/",$file);

$file = preg_replace_callback('/<script(.*?)src=\"(.*?\.js(?:\?.*?)?)"/s',function ($matches) {
global $currentpath;
global $fullscreen;
global $appVersion;

if($matches[2] === "libs/jquery.min.js" AND $fullscreen === "no")
return "<script ";
return "<script".$matches[1]."src=\"".$matches[2]."?v=".$appVersion."\"";
}, $file);
// token is needed to pass the csfr check
$file .= "<script src=\"libs/fullscreen.js?v=".$appVersion."\"></script>";

$file .= "<span style=\"display:none;\" id=\"token\">".$_['requesttoken']."</span>";
if($_['carnet_display_fullscreen']==="yes"){

$file = str_replace('</head>', "
<link rel=\"apple-touch-icon-precomposed\" href=\"".image_path('', 'favicon-touch.png')."\" />
<link rel=\"icon\" href=\"".image_path('', 'favicon.ico')."\">
<link rel=\"mask-icon\" sizes=\"any\" href=\"".image_path('', 'favicon-mask.svg')."\" color=\"".$theme->getColorPrimary()."\">
<link rel=\"manifest\" href=\"".image_path('', 'manifest.json')."\">
</head>", $file);
if($_['nc_version']>=16)
style("carnet","../templates/CarnetWebClient/compatibility/nextcloud/nc16");

}
else {
if($_['nc_version']>=14)
style("carnet","../templates/CarnetWebClient/compatibility/nextcloud/nc14-header");
}
$nonce = "";
if (method_exists(\OC::$server, "getContentSecurityPolicyNonceManager")){
$nonce = \OC::$server->getContentSecurityPolicyNonceManager()->getNonce();
}
else{
style("carnet","../templates/CarnetWebClient/compatibility/nextcloud/owncloud");
}

$file = str_replace("src=\"","defer nonce='".$nonce."' src=\"".$root."/CarnetWebClient/",$file);
echo $file;
echo "<span style=\"display:none;\" id=\"root-url\">".$root."/CarnetWebClient/</span>";
?>
Loading

0 comments on commit e694e88

Please sign in to comment.