WIP
This commit is contained in:
parent
49ca3e1c36
commit
1b2ba6eb95
|
@ -6,9 +6,13 @@ type BookmarkDto* = object
|
|||
name*: string
|
||||
url*: string
|
||||
imageUrl*: string
|
||||
removed*: bool
|
||||
deletedAt*: int
|
||||
|
||||
proc toBookmarkDto*(jsonObj: JsonNode): BookmarkDto =
|
||||
result = BookmarkDto()
|
||||
discard jsonObj.getProp("name", result.name)
|
||||
discard jsonObj.getProp("url", result.url)
|
||||
discard jsonObj.getProp("imageUrl", result.imageUrl)
|
||||
discard jsonObj.getProp("removed", result.removed)
|
||||
discard jsonObj.getProp("deletedAt", result.deletedAt)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import Tables, json, sequtils, strformat, chronicles
|
||||
import Tables, json, sequtils, strformat, chronicles, strutils
|
||||
import result
|
||||
include ../../common/json_utils
|
||||
import ./dto/bookmark as bookmark_dto
|
||||
import ../../../backend/backend
|
||||
import ../../../backend/browser
|
||||
|
||||
export bookmark_dto
|
||||
|
||||
|
@ -26,6 +27,7 @@ proc init*(self: Service) =
|
|||
try:
|
||||
let response = backend.getBookmarks()
|
||||
for bookmark in response.result.getElems().mapIt(it.toBookmarkDto()):
|
||||
if not bookmark.removed:
|
||||
self.bookmarks[bookmark.url] = bookmark
|
||||
|
||||
except Exception as e:
|
||||
|
@ -37,12 +39,15 @@ proc getBookmarks*(self: Service): seq[BookmarkDto] =
|
|||
|
||||
proc storeBookmark*(self: Service, url, name: string): R =
|
||||
try:
|
||||
let response = backend.storeBookmark(backend.Bookmark(name: name, url: url)).result
|
||||
self.bookmarks[url] = BookmarkDto()
|
||||
self.bookmarks[url].url = url
|
||||
self.bookmarks[url].name = name
|
||||
discard response.getProp("imageUrl", self.bookmarks[url].imageUrl)
|
||||
result.ok self.bookmarks[url]
|
||||
if not url.isEmptyOrWhitespace:
|
||||
let response = browser.addBookmark(backend.Bookmark(name: name, url: url)).result
|
||||
self.bookmarks[url] = BookmarkDto()
|
||||
self.bookmarks[url].url = url
|
||||
self.bookmarks[url].name = name
|
||||
discard response.getProp("imageUrl", self.bookmarks[url].imageUrl)
|
||||
discard response.getProp("removed", self.bookmarks[url].removed)
|
||||
discard response.getProp("deletedAt", self.bookmarks[url].deletedAt)
|
||||
result.ok self.bookmarks[url]
|
||||
except Exception as e:
|
||||
let errDescription = e.msg
|
||||
error "error: ", errDescription
|
||||
|
@ -52,7 +57,7 @@ proc deleteBookmark*(self: Service, url: string): bool =
|
|||
try:
|
||||
if not self.bookmarks.hasKey(url):
|
||||
return
|
||||
discard backend.deleteBookmark(url)
|
||||
discard browser.removeBookmark(url).result
|
||||
self.bookmarks.del(url)
|
||||
except Exception as e:
|
||||
let errDescription = e.msg
|
||||
|
|
|
@ -16,6 +16,9 @@ type
|
|||
Bookmark* = ref object of RootObj
|
||||
name* {.serializedFieldName("name").}: string
|
||||
url* {.serializedFieldName("url").}: string
|
||||
imageUrl* {.serializedFieldName("imageUrl").}: string
|
||||
removed* {.serializedFieldName("removed").}: bool
|
||||
deletedAt* {.serializedFieldName("deletedAt").}: int
|
||||
|
||||
Permission* = ref object of RootObj
|
||||
dapp* {.serializedFieldName("dapp").}: string
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import json, strutils
|
||||
import core, utils
|
||||
import response_type
|
||||
import ./backend
|
||||
|
||||
export response_type
|
||||
|
||||
|
||||
proc addBookmark*(bookmark: backend.Bookmark): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("addBookmark".prefix, %*[{
|
||||
"url": bookmark.url,
|
||||
"name": bookmark.name,
|
||||
"imageUrl": bookmark.imageUrl,
|
||||
"removed": bookmark.removed,
|
||||
"deletedAt": bookmark.deletedAt
|
||||
}])
|
||||
|
||||
proc removeBookmark*(url: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("removeBookmark".prefix, %*[url])
|
Loading…
Reference in New Issue