Added Markdown support
This commit is contained in:
parent
9bd4833e4b
commit
9bb203066c
29 changed files with 9771 additions and 220 deletions
58
node.go
58
node.go
|
|
@ -23,9 +23,10 @@ type Node struct {
|
|||
Level int
|
||||
|
||||
ContentEncrypted string `db:"content_encrypted" json:"-"`
|
||||
Markdown bool
|
||||
}
|
||||
|
||||
func NodeTree(userID, startNodeID int) (nodes []Node, err error) {// {{{
|
||||
func NodeTree(userID, startNodeID int) (nodes []Node, err error) { // {{{
|
||||
var rows *sqlx.Rows
|
||||
rows, err = service.Db.Conn.Queryx(`
|
||||
WITH RECURSIVE nodetree AS (
|
||||
|
|
@ -89,8 +90,8 @@ func NodeTree(userID, startNodeID int) (nodes []Node, err error) {// {{{
|
|||
}
|
||||
|
||||
return
|
||||
}// }}}
|
||||
func RootNode(userID int) (node Node, err error) {// {{{
|
||||
} // }}}
|
||||
func RootNode(userID int) (node Node, err error) { // {{{
|
||||
var rows *sqlx.Rows
|
||||
rows, err = service.Db.Conn.Queryx(`
|
||||
SELECT
|
||||
|
|
@ -114,8 +115,8 @@ func RootNode(userID int) (node Node, err error) {// {{{
|
|||
node.UserID = userID
|
||||
node.Complete = true
|
||||
node.Children = []Node{}
|
||||
node.Crumbs = []Node{}
|
||||
node.Files = []File{}
|
||||
node.Crumbs = []Node{}
|
||||
node.Files = []File{}
|
||||
for rows.Next() {
|
||||
row := Node{}
|
||||
if err = rows.StructScan(&row); err != nil {
|
||||
|
|
@ -131,8 +132,8 @@ func RootNode(userID int) (node Node, err error) {// {{{
|
|||
}
|
||||
|
||||
return
|
||||
}// }}}
|
||||
func RetrieveNode(userID, nodeID int) (node Node, err error) {// {{{
|
||||
} // }}}
|
||||
func RetrieveNode(userID, nodeID int) (node Node, err error) { // {{{
|
||||
if nodeID == 0 {
|
||||
return RootNode(userID)
|
||||
}
|
||||
|
|
@ -148,6 +149,7 @@ func RetrieveNode(userID, nodeID int) (node Node, err error) {// {{{
|
|||
name,
|
||||
content,
|
||||
content_encrypted,
|
||||
markdown,
|
||||
0 AS level
|
||||
FROM node
|
||||
WHERE
|
||||
|
|
@ -164,6 +166,7 @@ func RetrieveNode(userID, nodeID int) (node Node, err error) {// {{{
|
|||
n.name,
|
||||
'' AS content,
|
||||
'' AS content_encrypted,
|
||||
false AS markdown,
|
||||
r.level + 1 AS level
|
||||
FROM node n
|
||||
INNER JOIN recurse r ON n.parent_id = r.id AND r.level = 0
|
||||
|
|
@ -195,12 +198,13 @@ func RetrieveNode(userID, nodeID int) (node Node, err error) {// {{{
|
|||
}
|
||||
|
||||
if row.Level == 0 {
|
||||
node.ID = row.ID
|
||||
node.UserID = row.UserID
|
||||
node.ParentID = row.ParentID
|
||||
node.ID = row.ID
|
||||
node.UserID = row.UserID
|
||||
node.ParentID = row.ParentID
|
||||
node.CryptoKeyID = row.CryptoKeyID
|
||||
node.Name = row.Name
|
||||
node.Complete = true
|
||||
node.Name = row.Name
|
||||
node.Complete = true
|
||||
node.Markdown = row.Markdown
|
||||
|
||||
if node.CryptoKeyID > 0 {
|
||||
node.Content = row.ContentEncrypted
|
||||
|
|
@ -224,8 +228,8 @@ func RetrieveNode(userID, nodeID int) (node Node, err error) {// {{{
|
|||
node.Files, err = Files(userID, node.ID, 0)
|
||||
|
||||
return
|
||||
}// }}}
|
||||
func NodeCrumbs(nodeID int) (nodes []Node, err error) {// {{{
|
||||
} // }}}
|
||||
func NodeCrumbs(nodeID int) (nodes []Node, err error) { // {{{
|
||||
var rows *sqlx.Rows
|
||||
rows, err = service.Db.Conn.Queryx(`
|
||||
WITH RECURSIVE nodes AS (
|
||||
|
|
@ -252,7 +256,7 @@ func NodeCrumbs(nodeID int) (nodes []Node, err error) {// {{{
|
|||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
|
||||
nodes = []Node{}
|
||||
for rows.Next() {
|
||||
node := Node{}
|
||||
|
|
@ -262,8 +266,8 @@ func NodeCrumbs(nodeID int) (nodes []Node, err error) {// {{{
|
|||
nodes = append(nodes, node)
|
||||
}
|
||||
return
|
||||
}// }}}
|
||||
func CreateNode(userID, parentID int, name string) (node Node, err error) {// {{{
|
||||
} // }}}
|
||||
func CreateNode(userID, parentID int, name string) (node Node, err error) { // {{{
|
||||
var rows *sqlx.Rows
|
||||
|
||||
rows, err = service.Db.Conn.Queryx(`
|
||||
|
|
@ -297,14 +301,15 @@ func CreateNode(userID, parentID int, name string) (node Node, err error) {// {{
|
|||
|
||||
node.Crumbs, err = NodeCrumbs(node.ID)
|
||||
return
|
||||
}// }}}
|
||||
func UpdateNode(userID, nodeID int, content string, cryptoKeyID int) (err error) {// {{{
|
||||
} // }}}
|
||||
func UpdateNode(userID, nodeID int, content string, cryptoKeyID int, markdown bool) (err error) { // {{{
|
||||
if cryptoKeyID > 0 {
|
||||
_, err = service.Db.Conn.Exec(`
|
||||
UPDATE node
|
||||
SET
|
||||
content = '',
|
||||
content_encrypted = $1,
|
||||
markdown = $5,
|
||||
crypto_key_id = CASE $2::int
|
||||
WHEN 0 THEN NULL
|
||||
ELSE $2
|
||||
|
|
@ -317,6 +322,7 @@ func UpdateNode(userID, nodeID int, content string, cryptoKeyID int) (err error)
|
|||
cryptoKeyID,
|
||||
nodeID,
|
||||
userID,
|
||||
markdown,
|
||||
)
|
||||
} else {
|
||||
_, err = service.Db.Conn.Exec(`
|
||||
|
|
@ -340,8 +346,8 @@ func UpdateNode(userID, nodeID int, content string, cryptoKeyID int) (err error)
|
|||
}
|
||||
|
||||
return
|
||||
}// }}}
|
||||
func RenameNode(userID, nodeID int, name string) (err error) {// {{{
|
||||
} // }}}
|
||||
func RenameNode(userID, nodeID int, name string) (err error) { // {{{
|
||||
_, err = service.Db.Conn.Exec(`
|
||||
UPDATE node SET name = $1 WHERE user_id = $2 AND id = $3
|
||||
`,
|
||||
|
|
@ -350,8 +356,8 @@ func RenameNode(userID, nodeID int, name string) (err error) {// {{{
|
|||
nodeID,
|
||||
)
|
||||
return
|
||||
}// }}}
|
||||
func DeleteNode(userID, nodeID int) (err error) {// {{{
|
||||
} // }}}
|
||||
func DeleteNode(userID, nodeID int) (err error) { // {{{
|
||||
_, err = service.Db.Conn.Exec(`
|
||||
WITH RECURSIVE nodetree AS (
|
||||
SELECT
|
||||
|
|
@ -375,8 +381,8 @@ func DeleteNode(userID, nodeID int) (err error) {// {{{
|
|||
nodeID,
|
||||
)
|
||||
return
|
||||
}// }}}
|
||||
func SearchNodes(userID int, search string) (nodes []Node, err error) {// {{{
|
||||
} // }}}
|
||||
func SearchNodes(userID int, search string) (nodes []Node, err error) { // {{{
|
||||
nodes = []Node{}
|
||||
var rows *sqlx.Rows
|
||||
rows, err = service.Db.Conn.Queryx(`
|
||||
|
|
@ -412,6 +418,6 @@ func SearchNodes(userID int, search string) (nodes []Node, err error) {// {{{
|
|||
}
|
||||
|
||||
return
|
||||
}// }}}
|
||||
} // }}}
|
||||
|
||||
// vim: foldmethod=marker
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue