add dashbord and right colomn right page
This commit is contained in:
+26
-10
@@ -12,13 +12,13 @@
|
||||
import os
|
||||
import logging
|
||||
import parsecfg
|
||||
import db_sqlite
|
||||
import db_sqlite
|
||||
|
||||
import ../code/password_utils
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : Generate Database
|
||||
# PROC : Generate Database
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc generateDB*() =
|
||||
echo "Generating database"
|
||||
@@ -26,11 +26,11 @@ proc generateDB*() =
|
||||
# Load the connection details
|
||||
let
|
||||
dict = loadConfig("config/config.cfg")
|
||||
db_user = dict.getSectionValue("Database","user")
|
||||
db_pass = dict.getSectionValue("Database","pass")
|
||||
db_name = dict.getSectionValue("Database","name")
|
||||
db_host = dict.getSectionValue("Database","host")
|
||||
db_folder = dict.getSectionValue("Database","folder")
|
||||
db_user = dict.getSectionValue("Database", "user")
|
||||
db_pass = dict.getSectionValue("Database", "pass")
|
||||
db_name = dict.getSectionValue("Database", "name")
|
||||
db_host = dict.getSectionValue("Database", "host")
|
||||
db_folder = dict.getSectionValue("Database", "folder")
|
||||
dbexists = if fileExists(db_host): true else: false
|
||||
|
||||
if dbexists:
|
||||
@@ -41,7 +41,8 @@ proc generateDB*() =
|
||||
|
||||
# Open DB
|
||||
echo " - Opening database"
|
||||
var db = open(connection=db_host, user=db_user, password=db_pass, database=db_name)
|
||||
var db = open(connection = db_host, user = db_user, password = db_pass,
|
||||
database = db_name)
|
||||
|
||||
# Person table contains information about the
|
||||
# registrered users
|
||||
@@ -74,6 +75,20 @@ proc generateDB*() =
|
||||
);""")):
|
||||
echo " - Database: session table already exists"
|
||||
|
||||
# Sesion table contains information about the search
|
||||
#
|
||||
if not db.tryExec(sql("""
|
||||
create table if not exists search(
|
||||
id integer primary key,
|
||||
search_title varchar(300) not null,
|
||||
query varchar(300) not null,
|
||||
search_type varchar(100) not null,
|
||||
creation timestamp not null default (STRFTIME('%s', 'now')),
|
||||
lastModified timestamp not null default (STRFTIME('%s', 'now')),
|
||||
foreign key (userid) references person(id)
|
||||
);""")):
|
||||
echo " - Database: search table already exists"
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : Create Administrator User
|
||||
@@ -108,9 +123,10 @@ proc createAdminUser*(db: DbConn, args: seq[string]) =
|
||||
let password = makePassword(iPwd, salt)
|
||||
|
||||
# Insert user into database
|
||||
if insertID(db, sql"INSERT INTO person (name, email, password, salt, status) VALUES (?, ?, ?, ?, ?)", $iName, $iEmail, password, salt, "Admin") > 0:
|
||||
if insertID(db, sql"INSERT INTO person (name, email, password, salt, status) VALUES (?, ?, ?, ?, ?)",
|
||||
$iName, $iEmail, password, salt, "Admin") > 0:
|
||||
echo "Admin user added"
|
||||
else:
|
||||
error("Something went wrong")
|
||||
|
||||
info("Admin added.")
|
||||
info("Admin added.")
|
||||
|
||||
+202
-117
@@ -15,10 +15,13 @@ import std/json
|
||||
import httpcore
|
||||
import strutils
|
||||
import strformat
|
||||
import std/times
|
||||
import std/options
|
||||
import std/httpclient
|
||||
import std/asyncdispatch
|
||||
|
||||
import utils # Joplin utils procedures and types
|
||||
|
||||
from os import sleep
|
||||
from posix import read, write, fdatasync, close
|
||||
|
||||
@@ -37,16 +40,18 @@ type
|
||||
type
|
||||
joplin_tags* = object
|
||||
id*, parent_id*, title*: seq[string]
|
||||
created_time*, updated_time*, user_created_time*, user_updated_time*, is_shared*: seq[int]
|
||||
created_time*, updated_time*, user_created_time*, user_updated_time*,
|
||||
is_shared*: seq[int]
|
||||
req*: Request
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# TYPE : Setup joplin_notebooks data
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
type
|
||||
joplin_notebooks* = object
|
||||
joplin_notebooks* = object
|
||||
id*, parent_id*, title*, share_id*, icon*: seq[string]
|
||||
created_time*, updated_time*, user_created_time*, user_updated_time*, is_shared*: seq[int]
|
||||
created_time*, updated_time*, user_created_time*, user_updated_time*,
|
||||
is_shared*: seq[int]
|
||||
req*: Request
|
||||
|
||||
|
||||
@@ -54,10 +59,29 @@ type
|
||||
# TYPE : Setup joplin_notes data
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
type
|
||||
joplin_notes* = object
|
||||
id*, parent_id*, title*, body*, author*, source_url*, source*, source_application*, application_data*, share_id*, conflict_original_id*, body_html*, base_url*: seq[string]
|
||||
created_time*, updated_time*, is_conflict*, is_todo*, todo_due*, todo_completed*, user_created_time*, user_updated_time*, markup_language*, is_shared*: seq[int]
|
||||
latitude*, longitude*, altitude*, order*:seq[float]
|
||||
joplin_notes* = object
|
||||
id*, parent_id*, title*, body*, author*, source_url*, source*,
|
||||
source_application*, application_data*, share_id*,
|
||||
conflict_original_id*, body_html*, base_url*: seq[string]
|
||||
updated_time*, is_conflict*, is_todo*, todo_due*,
|
||||
todo_completed*, user_created_time*, user_updated_time*,
|
||||
markup_language*, is_shared*: seq[int]
|
||||
latitude*, longitude*, altitude*, order*: seq[float]
|
||||
created_time*: seq[string]
|
||||
req*: Request
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# TYPE : Setup joplin_note data
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
type
|
||||
joplin_note* = object
|
||||
id*, parent_id*, title*, body*, author*, source_url*, source*,
|
||||
source_application*, application_data*, conflict_original_id*,
|
||||
master_key_id*, share_id*, encryption_cipher_text * : string
|
||||
created_time*, updated_time*, user_created_time*, user_updated_time*,
|
||||
is_conflict*, is_todo*, todo_due*, todo_completed*, markup_language*,
|
||||
is_shared*, encryption_applied*: int
|
||||
latitude*, longitude*, altitude*, order*: float
|
||||
req*: Request
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
@@ -73,7 +97,7 @@ type
|
||||
# DURATION : duration variables
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
let
|
||||
resetDuration = initDuration(seconds=2)
|
||||
resetDuration = initDuration(seconds = 2)
|
||||
deciSecondDuration* = initDuration(milliseconds = 100)
|
||||
qtrsecondDuration* = initDuration(milliseconds = 250)
|
||||
|
||||
@@ -86,7 +110,7 @@ var
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : reset HTTP client
|
||||
# PROC : reset HTTP client
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc resetHttpClient() =
|
||||
if (getTime().utc - lastConnection) > resetDuration:
|
||||
@@ -99,13 +123,13 @@ proc resetHttpClient() =
|
||||
except:
|
||||
echo("Attempted to close clients. Probably do not exist.")
|
||||
echo("Current exception: ", getCurrentExceptionMsg())
|
||||
client = newHttpClient(timeout=500)
|
||||
client = newHttpClient(timeout = 500)
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==--==--==--==-==--==--==- #
|
||||
# PROC : use the joplin API ping to validate service availibility
|
||||
# --==--==--==--==--==--==--==--==--==--==--==--==--==-==--==--==- #
|
||||
proc ping_joplin*(token:string): Future[joplin_ping] {.async.} =
|
||||
|
||||
proc ping_joplin*(token: string): Future[joplin_ping] {.async.} =
|
||||
|
||||
var j_p: joplin_ping
|
||||
var client = newAsyncHttpClient()
|
||||
var url: string
|
||||
@@ -114,7 +138,7 @@ proc ping_joplin*(token:string): Future[joplin_ping] {.async.} =
|
||||
url = fmt"http://localhost:41184/ping?token={token}"
|
||||
var json = await client.getContent(url)
|
||||
j_p.ping_result.add(json)
|
||||
|
||||
|
||||
echo j_p.ping_result[0]
|
||||
|
||||
if j_p.ping_result[0] == "JoplinClipperServer":
|
||||
@@ -133,17 +157,17 @@ proc ping_joplin*(token:string): Future[joplin_ping] {.async.} =
|
||||
echo("Current Exception: ", getCurrentException().name)
|
||||
echo("Current Exception Msg: ", getCurrentExceptionMsg())
|
||||
echo("Sleeping for 1 seconds at: ", getTime().utc)
|
||||
j_p.ping_status = false
|
||||
j_p.ping_status = false
|
||||
return j_p
|
||||
# parse jason
|
||||
#let joplin_notes_Json = parseJson(json)
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : get all joplin NOTEBOOKS
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc get_joplin_notebooks*(token:string): Future[joplin_notebooks] {.async.} =
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : get all joplin NOTEBOOKS
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc get_joplin_notebooks*(token: string): Future[joplin_notebooks] {.async.} =
|
||||
|
||||
# Variables
|
||||
var j_nb: joplin_notebooks
|
||||
var has_more: bool = true
|
||||
@@ -151,15 +175,15 @@ proc get_joplin_notebooks*(token:string): Future[joplin_notebooks] {.async.} =
|
||||
var url: string
|
||||
var client = newAsyncHttpClient()
|
||||
var pingCheck: joplin_ping
|
||||
|
||||
|
||||
pingCheck = waitFor ping_joplin(token)
|
||||
|
||||
# check the joplin status befor query
|
||||
# check the joplin status befor query
|
||||
if pingCheck.ping_status:
|
||||
|
||||
# make sure to check all pages
|
||||
# make sure to check all pages
|
||||
while has_more == true:
|
||||
|
||||
|
||||
# request joplin API for notebooks
|
||||
url = fmt"http://localhost:41184/folders?page={page}&token={token}"
|
||||
echo("URL notebooks : ", url)
|
||||
@@ -168,10 +192,10 @@ proc get_joplin_notebooks*(token:string): Future[joplin_notebooks] {.async.} =
|
||||
# parse jason
|
||||
let joplin_notebooks_Json = parseJson(json)
|
||||
|
||||
# valider qu'il n'y a plus de page
|
||||
# valider qu'il n'y a plus de page
|
||||
if not joplin_notebooks_Json["has_more"].getBool:
|
||||
has_more = false
|
||||
|
||||
has_more = false
|
||||
|
||||
# store json info into an object
|
||||
var count: int = 1
|
||||
for nb in joplin_notebooks_Json["items"]:
|
||||
@@ -179,18 +203,18 @@ proc get_joplin_notebooks*(token:string): Future[joplin_notebooks] {.async.} =
|
||||
j_nb.parent_id.add(nb["parent_id"].getstr)
|
||||
j_nb.title.add(nb["title"].getstr)
|
||||
count += 1
|
||||
|
||||
|
||||
# aller à la page suivante
|
||||
page += 1
|
||||
page += 1
|
||||
|
||||
return j_nb
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : get all joplin NOTES
|
||||
# PROC : get all joplin NOTES
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc get_joplin_notes*(token:string): Future[joplin_notes] {.async.} =
|
||||
|
||||
proc get_joplin_notes*(token: string): Future[joplin_notes] {.async.} =
|
||||
|
||||
# Variables
|
||||
var j_notes: joplin_notes
|
||||
var has_more: bool = true
|
||||
@@ -200,43 +224,113 @@ proc get_joplin_notes*(token:string): Future[joplin_notes] {.async.} =
|
||||
var pingCheck: joplin_ping
|
||||
pingCheck = waitFor ping_joplin(token)
|
||||
|
||||
# check the joplin status befor query
|
||||
# check the joplin status befor query
|
||||
if pingCheck.ping_status:
|
||||
|
||||
# make sure to check all pages
|
||||
# make sure to check all pages
|
||||
while has_more == true:
|
||||
|
||||
|
||||
# request joplin API for Notes
|
||||
url = fmt"http://localhost:41184/notes?page={page}&token={token}"
|
||||
url = fmt"http://localhost:41184/notes?page={page}&fields=id,parent_id,title,created_time,updated_time&token={token}"
|
||||
echo("URL notes : ", url)
|
||||
var json = await client.getContent(url)
|
||||
|
||||
# parse jason
|
||||
let joplin_notes_Json = parseJson(json)
|
||||
|
||||
# valider qu'il n'y a plus de page
|
||||
# valider qu'il n'y a plus de page
|
||||
if not joplin_notes_Json["has_more"].getBool:
|
||||
has_more = false
|
||||
|
||||
has_more = false
|
||||
|
||||
#echo joplin_notes_Json
|
||||
|
||||
# store json info into an object
|
||||
var count: int = 1
|
||||
var epochTime: int
|
||||
var humanTime: Time
|
||||
for nb in joplin_notes_Json["items"]:
|
||||
j_notes.id.add(nb["id"].getstr)
|
||||
j_notes.parent_id.add(nb["parent_id"].getstr)
|
||||
j_notes.title.add(nb["title"].getstr)
|
||||
#epochTime = nb["created_time"].getInt
|
||||
#humanTime = fromUnix(convert(Milliseconds, Seconds, epochTime))
|
||||
|
||||
j_notes.created_time.add(convertEpochToHumanTime(nb[
|
||||
"created_time"].getInt))
|
||||
count += 1
|
||||
|
||||
|
||||
# aller à la page suivante
|
||||
page += 1
|
||||
page += 1
|
||||
|
||||
return j_notes
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : get joplin NOTE
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc get_joplin_note*(token: string, noteid: string): Future[
|
||||
joplin_note] {.async.} =
|
||||
|
||||
# Variables
|
||||
var j_note: joplin_note
|
||||
var has_more: bool = true
|
||||
var page: int = 1
|
||||
var url: string
|
||||
var client = newAsyncHttpClient()
|
||||
|
||||
# Check joplin connection availibility
|
||||
var pingCheck: joplin_ping
|
||||
pingCheck = waitFor ping_joplin(token)
|
||||
|
||||
|
||||
# Query for a selected note
|
||||
url = fmt"http://localhost:41184/notes/{noteid}?fields=id,parent_id,title,body,created_time,updated_time,is_conflict,latitude,longitude,altitude,author,source_url,is_todo,todo_due,todo_completed,source,source_application,application_data,order,user_created_time,user_updated_time,encryption_cipher_text,encryption_applied,markup_language,is_shared,share_id,conflict_original_id,master_key_id&token={token}"
|
||||
echo("URL notes : ", url)
|
||||
var jsonNote = await client.getContent(url)
|
||||
|
||||
# parse jason
|
||||
let joplin_note_Json = parseJson(jsonNote)
|
||||
|
||||
# get all informations for a selected note
|
||||
j_note.id = joplin_note_Json["id"].getstr
|
||||
j_note.parent_id = joplin_note_Json["parent_id"].getstr
|
||||
j_note.title = joplin_note_Json["title"].getstr
|
||||
j_note.body = joplin_note_Json["body"].getstr
|
||||
j_note.author = joplin_note_Json["author"].getstr
|
||||
j_note.source_url = joplin_note_Json["source_url"].getstr
|
||||
j_note.source = joplin_note_Json["source"].getstr
|
||||
j_note.source_application = joplin_note_Json["source_application"].getstr
|
||||
j_note.application_data = joplin_note_Json["application_data"].getstr
|
||||
j_note.share_id = joplin_note_Json["share_id"].getstr
|
||||
j_note.conflict_original_id = joplin_note_Json["conflict_original_id"].getstr
|
||||
j_note.created_time = joplin_note_Json["created_time"].getInt
|
||||
j_note.updated_time = joplin_note_Json["updated_time"].getInt
|
||||
j_note.is_conflict = joplin_note_Json["is_conflict"].getInt
|
||||
j_note.latitude = joplin_note_Json["latitude"].getFloat
|
||||
j_note.longitude = joplin_note_Json["longitude"].getFloat
|
||||
j_note.altitude = joplin_note_Json["altitude"].getFloat
|
||||
j_note.is_todo = joplin_note_Json["is_todo"].getInt
|
||||
j_note.todo_due = joplin_note_Json["todo_due"].getInt
|
||||
j_note.todo_completed = joplin_note_Json["todo_completed"].getInt
|
||||
j_note.order = joplin_note_Json["order"].getFloat
|
||||
j_note.user_created_time = joplin_note_Json["user_created_time"].getInt
|
||||
j_note.user_updated_time = joplin_note_Json["user_updated_time"].getInt
|
||||
j_note.encryption_cipher_text = joplin_note_Json[
|
||||
"encryption_cipher_text"].getstr
|
||||
j_note.encryption_applied = joplin_note_Json["encryption_applied"].getInt
|
||||
j_note.markup_language = joplin_note_Json["markup_language"].getInt
|
||||
j_note.is_shared = joplin_note_Json["is_shared"].getInt
|
||||
j_note.master_key_id = joplin_note_Json["master_key_id"].getstr
|
||||
|
||||
|
||||
echo j_note
|
||||
return j_note
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : get all joplin TAGS
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc get_joplin_tags*(token:string): Future[joplin_tags] {.async.} =
|
||||
|
||||
proc get_joplin_tags*(token: string): Future[joplin_tags] {.async.} =
|
||||
|
||||
# Variables
|
||||
var j_tags: joplin_tags
|
||||
var has_more: bool = true
|
||||
@@ -246,12 +340,12 @@ proc get_joplin_tags*(token:string): Future[joplin_tags] {.async.} =
|
||||
var pingCheck: joplin_ping
|
||||
pingCheck = waitFor ping_joplin(token)
|
||||
|
||||
# check the joplin status befor query
|
||||
# check the joplin status befor query
|
||||
if pingCheck.ping_status:
|
||||
|
||||
# make sure to check all pages
|
||||
# make sure to check all pages
|
||||
while has_more == true:
|
||||
|
||||
|
||||
# request joplin API for notebooks
|
||||
url = fmt"http://localhost:41184/tags?page={page}&token={token}"
|
||||
echo("URL tags : ", url)
|
||||
@@ -260,10 +354,10 @@ proc get_joplin_tags*(token:string): Future[joplin_tags] {.async.} =
|
||||
# parse jason
|
||||
let joplin_tags_Json = parseJson(json)
|
||||
|
||||
# valider qu'il n'y a plus de page
|
||||
# valider qu'il n'y a plus de page
|
||||
if not joplin_tags_Json["has_more"].getBool:
|
||||
has_more = false
|
||||
|
||||
has_more = false
|
||||
|
||||
# store json info into an object
|
||||
var count: int = 1
|
||||
for nb in joplin_tags_Json["items"]:
|
||||
@@ -271,9 +365,9 @@ proc get_joplin_tags*(token:string): Future[joplin_tags] {.async.} =
|
||||
j_tags.parent_id.add(nb["parent_id"].getstr)
|
||||
j_tags.title.add(nb["title"].getstr)
|
||||
count += 1
|
||||
|
||||
|
||||
# aller à la page suivante
|
||||
page += 1
|
||||
page += 1
|
||||
|
||||
return j_tags
|
||||
|
||||
@@ -287,42 +381,41 @@ proc get_joplin_cli_token*(): string =
|
||||
var result = execCmdEx("joplin config api.token")
|
||||
|
||||
if result.exitCode == 0:
|
||||
let param1 = result.output
|
||||
let flagSplit = param1.split(" = ")
|
||||
flagName = flagSplit[0]
|
||||
flagValue = flagSplit[1]
|
||||
|
||||
let param1 = result.output
|
||||
let flagSplit = param1.split(" = ")
|
||||
flagName = flagSplit[0]
|
||||
flagValue = flagSplit[1]
|
||||
|
||||
return flagValue
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : launch any program and get PID
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc launchProgram(app:string = "", workingPath:string = "", arguments:array[2, string]):int {.thread.} =
|
||||
|
||||
var p = startProcess(joinPath(workingPath,app), workingPath, arguments)
|
||||
let pid = p.processID()
|
||||
var outhdl = outputHandle(p)
|
||||
var inputhdl = inputHandle(p)
|
||||
var errhdl = errorHandle(p)
|
||||
return pid
|
||||
proc launchProgram(app: string = "", workingPath: string = "", arguments: array[
|
||||
2, string]): int {.thread.} =
|
||||
|
||||
var p = startProcess(joinPath(workingPath, app), workingPath, arguments)
|
||||
let pid = p.processID()
|
||||
var outhdl = outputHandle(p)
|
||||
var inputhdl = inputHandle(p)
|
||||
var errhdl = errorHandle(p)
|
||||
return pid
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : Start joplin cli
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc joplin_cli_start*():int {.thread.} =
|
||||
|
||||
let joplinProcessId = launchProgram("joplin","/usr/bin/",["server","start"])
|
||||
return joplinProcessId
|
||||
proc joplin_cli_start*(): int {.thread.} =
|
||||
|
||||
let joplinProcessId = launchProgram("joplin", "/usr/bin/", ["server", "start"])
|
||||
return joplinProcessId
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : stop Joplin Terminal
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc joplin_cli_stop*():int {.thread.} =
|
||||
let joplinProcessId = launchProgram("joplin","/usr/bin/",["server","stop"])
|
||||
return joplinProcessId
|
||||
|
||||
|
||||
proc joplin_cli_stop*(): int {.thread.} =
|
||||
let joplinProcessId = launchProgram("joplin", "/usr/bin/", ["server", "stop"])
|
||||
return joplinProcessId
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
@@ -333,53 +426,45 @@ proc joplin_cli_status*(): bool =
|
||||
var result = execCmdEx("joplin server status")
|
||||
|
||||
if result.exitCode == 0:
|
||||
if "Server is not running" in result.output :
|
||||
echo "Joplin Terminal cli status is down : ", result.output
|
||||
rc = false
|
||||
if "Server is not running" in result.output:
|
||||
echo "Joplin Terminal cli status is down : ", result.output
|
||||
rc = false
|
||||
else:
|
||||
echo "Joplin Terminal cli status is up : ", result.output
|
||||
rc = true
|
||||
echo "Joplin Terminal cli status is up : ", result.output
|
||||
rc = true
|
||||
else:
|
||||
echo "Error validate joplin terminal status : ", result.output
|
||||
echo "Error validate joplin terminal status : ", result.output
|
||||
return rc
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : start Joplin Terminal
|
||||
# PROC : start or stop Joplin Terminal
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# proc joplin_cli_start*(): bool =
|
||||
# var rc = false
|
||||
# startProcess("joplin","/usr/bin", @["server", "start"])
|
||||
# #var result = execCmdEx("ls -l /usr/bin/joplin")
|
||||
proc joplin_cli_start_stop*(): int =
|
||||
var isStart: int = 0
|
||||
var sleep_delay_frame: int = 50
|
||||
var sleep_max: int = 5000
|
||||
|
||||
# if joplin_cli_status() == true:
|
||||
# echo "Joplin Terminal started successfully : ",result.output
|
||||
# rc = true
|
||||
# else:
|
||||
# echo "Joplin Terminal didn't start : ",result.output
|
||||
# rc = false
|
||||
# return rc
|
||||
if joplin_cli_status() == false:
|
||||
isStart = joplin_cli_start()
|
||||
while joplin_cli_status() == false:
|
||||
sleep(sleep_delay_frame)
|
||||
echo "Joplin client Terminal started: ", isStart
|
||||
|
||||
else:
|
||||
echo "Joplin client Terminal is alredy started !"
|
||||
#if joplin_cli_status() == true:
|
||||
isStart = joplin_cli_stop()
|
||||
while joplin_cli_status() == true:
|
||||
sleep(sleep_delay_frame)
|
||||
echo "Joplin client Terminal stopped: ", isStart
|
||||
|
||||
return isStart
|
||||
|
||||
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : stop Joplin Terminal
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# proc joplin_cli_stop*(): bool =
|
||||
# var rc = false
|
||||
# var result = execCmdEx("joplin server stop")
|
||||
|
||||
# if result.exitCode == 0:
|
||||
# # echo result.output
|
||||
# rc = true
|
||||
# else:
|
||||
# rc = false
|
||||
# return rc
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC :
|
||||
# PROC :
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
|
||||
# proc get_joplin_tags_json*(token:string): Future[] {.async.} =
|
||||
@@ -389,7 +474,7 @@ proc joplin_cli_status*(): bool =
|
||||
# # url = fmt"http://localhost:41184/tags/{id}?fields=id,parent_id,title,created_time,updated_time,user_created_time,user_updated_time,is_shared&token={token}"
|
||||
|
||||
# # http://localhost:41184/tags?token=e5f6644fbf6a97ddc55648dae72b11caecda6c6642d8ce0d3b20129b89b196385737eb908923542c3343649ebbf865b55bda031ab4c3a16edc7723ef2ad77d8f
|
||||
|
||||
|
||||
# # Variables
|
||||
# var j_tags: joplin_tags
|
||||
# var has_more: bool = true
|
||||
@@ -398,14 +483,14 @@ proc joplin_cli_status*(): bool =
|
||||
# var client = newAsyncHttpClient()
|
||||
# var pingCheck: joplin_ping
|
||||
# pingCheck = waitFor ping_joplin(token)
|
||||
|
||||
|
||||
# # check the joplin status befor query
|
||||
|
||||
# # check the joplin status befor query
|
||||
# if pingCheck.ping_status:
|
||||
|
||||
# # make sure to check all pages
|
||||
# # make sure to check all pages
|
||||
# while has_more == true:
|
||||
|
||||
|
||||
# # request joplin API for notebooks
|
||||
# url = fmt"http://localhost:41184/tags?page={page}&token={token}"
|
||||
# echo("URL tags : ", url)
|
||||
@@ -414,10 +499,10 @@ proc joplin_cli_status*(): bool =
|
||||
# # parse jason
|
||||
# let joplin_tags_Json = parseJson(json)
|
||||
|
||||
# # valider qu'il n'y a plus de page
|
||||
# # valider qu'il n'y a plus de page
|
||||
# if not joplin_tags_Json["has_more"].getBool:
|
||||
# has_more = false
|
||||
|
||||
# has_more = false
|
||||
|
||||
# # store json info into an object
|
||||
# var count: int = 1
|
||||
# for nb in joplin_tags_Json["items"]:
|
||||
@@ -425,8 +510,8 @@ proc joplin_cli_status*(): bool =
|
||||
# echo nb["parent_id"].getstr
|
||||
# echo nb["title"].getstr
|
||||
# count += 1
|
||||
|
||||
|
||||
# # aller à la page suivante
|
||||
# page += 1
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ let useUrandom = urandom.open("/dev/urandom")
|
||||
## : Generate random salt. Uses cryptographically secure /dev/urandom
|
||||
## : on platforms where it is available, and Nim's random module in other cases.
|
||||
# --==--==--==--==--==--==--==--==--==--==--=--==--==--=--==--==--=--==--==-- #
|
||||
proc makeSalt*(): string =
|
||||
proc makeSalt*(): string =
|
||||
result = ""
|
||||
if useUrandom:
|
||||
var randomBytes: array[0..127, char]
|
||||
@@ -42,7 +42,7 @@ proc makeSalt*(): string =
|
||||
# PROC : Make session key
|
||||
## Creates a random key to be used to authorize a session.
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc makeSessionKey*(): string =
|
||||
proc makeSessionKey*(): string =
|
||||
let random = makeSalt()
|
||||
return bcrypt.hash(random, genSalt(8))
|
||||
|
||||
@@ -51,6 +51,6 @@ proc makeSessionKey*(): string =
|
||||
# PROC : make password
|
||||
## Creates an MD5 hash by combining password and salt
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc makePassword*(password, salt: string, comparingTo = ""): string =
|
||||
proc makePassword*(password, salt: string, comparingTo = ""): string =
|
||||
let bcryptSalt = if comparingTo != "": comparingTo else: genSalt(8)
|
||||
result = hash(getMD5(salt & getMD5(password)), bcryptSalt)
|
||||
result = hash(getMD5(salt & getMD5(password)), bcryptSalt)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
|
||||
# Bruno Charest
|
||||
# 2022-10-25
|
||||
#
|
||||
# __ DESCRIPTIONS __
|
||||
# utils : procedures generals utils
|
||||
#
|
||||
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
|
||||
|
||||
import std/times
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
|
||||
# PROC : Convert epoch millisecond time to human readable time
|
||||
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
|
||||
proc convertEpochToHumanTime*(epochTime: int): string =
|
||||
var humanTime: Time
|
||||
var dateTime: string
|
||||
humanTime = fromUnix(convert(Milliseconds, Seconds, epochTime))
|
||||
dateTime = format(humanTime, "yyyy-MM-dd' 'HH:mm")
|
||||
# echo dateTime
|
||||
return dateTime
|
||||
|
||||
+27
-12
@@ -11,23 +11,38 @@ import joplin_utils
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# TYPE : Selected Option for master web page
|
||||
# TYPE : Selected Option for master web page
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
type
|
||||
type
|
||||
selectedOption* = enum
|
||||
newNote="New Note", search="Search", shortcuts="Shortcuts", notes="Notes", notebooks="Notesbooks", tags="Tags"
|
||||
newNote = "New Note", search = "Search", shortcuts = "Shortcuts",
|
||||
notes = "Notes", notebooks = "Notesbooks", tags = "Tags",
|
||||
notes_selectednote = "Notes-SelectedNote", dashbord = "Dashboard"
|
||||
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# TYPE : Data Informations for Left Colomn
|
||||
# TYPE : Data Informations for Left Colomn
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
type ColomnLeftData* = ref object of RootObj
|
||||
j_status*: bool
|
||||
option*: selectedOption
|
||||
j_notes*: joplin_notes
|
||||
j_notebooks*: joplin_notebooks
|
||||
j_tags*: joplin_tags
|
||||
req*: Request
|
||||
j_status*: bool
|
||||
option*: selectedOption
|
||||
j_notes*: joplin_notes
|
||||
j_notes_nb*: int
|
||||
j_notebooks*: joplin_notebooks
|
||||
j_notebooks_nb*: int
|
||||
j_tags*: joplin_tags
|
||||
j_tags_nb*: int
|
||||
req*: Request
|
||||
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
# TYPE : Data Informations for Right Colomn
|
||||
# --==--==--==--==--==--==--==--==--==--==-- #
|
||||
type ColomnRightData* = ref object of RootObj
|
||||
j_status*: bool
|
||||
option*: selectedOption
|
||||
j_SelectedNote*: joplin_note
|
||||
j_notebooksNote*: joplin_notebooks
|
||||
j_tagsNote*: joplin_tags
|
||||
req*: Request
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user