Browse Source

change import/export format from json to txt

main
familyfriendlymikey 3 years ago
parent
commit
8d2458d1cf
  1. 65
      app/client.imba

65
app/client.imba

@ -65,9 +65,9 @@ tag app
"instagram `in instagram.com" "instagram `in instagram.com"
"localhost `3000 http://localhost:3000" "localhost `3000 http://localhost:3000"
] ]
for link in initial_links for link_text in initial_links
try try
add_link link add_link link_text
catch e catch e
err "adding link", e err "adding link", e
@ -196,9 +196,9 @@ tag app
def create_link_from_text text def create_link_from_text text
text = text.trim! text = text.trim!
throw "text is empty" if text is '' throw "Text is empty." if text is ''
let split_text = text.split(/\s+/) let split_text = text.split(/\s+/)
throw "no url provided" if split_text.length < 2 throw "No url provided." if split_text.length < 2
let url = split_text.pop! let url = split_text.pop!
let host let host
{ href:url, host } = parse_url url { href:url, host } = parse_url url
@ -261,7 +261,7 @@ tag app
let new_link = await create_link_from_text new_link_text let new_link = await create_link_from_text new_link_text
new_link.frequency = old_link.frequency new_link.frequency = old_link.frequency
let result = await db.links.update old_link.id, new_link let result = await db.links.update old_link.id, new_link
throw "link id not found" if result is 0 throw "Link id not found." if result is 0
await reload_db! await reload_db!
imba.commit! imba.commit!
p omit(old_link, "icon") p omit(old_link, "icon")
@ -336,7 +336,7 @@ tag app
link.is_pinned = !link.is_pinned link.is_pinned = !link.is_pinned
try try
let result = await db.links.update link.id, link let result = await db.links.update link.id, link
throw "link id not found" if result is 0 throw "Link id not found." if result is 0
catch e catch e
return err "pinning link", e return err "pinning link", e
await reload_db! await reload_db!
@ -401,40 +401,53 @@ tag app
selection_index = 0 selection_index = 0
sort_links! sort_links!
def name_exists new_name
state.links.some! do |{name}| new_name is name
def handle_click_import e def handle_click_import e
loading = yes def handle_import
let id_exists = do |newid| let errors = []
state.links.some! do |{id}| newid is id
let filter = do |table, value, key|
table is 'links' and not id_exists value.id
try try
await reload_db! let text = await e.target.files[0].text!
await db.import(e.target.files[0], { filter }) var links = text.split "\n"
await reload_db! catch e
return err "importing db", e
for link_text in links
try
let link = await create_link_from_text link_text
if name_exists link.name
throw "Name already exists, add manually if you don't mind duplicates."
add_link link_text
catch e catch e
err "importing db", e errors.push "{link_text}\n{e}"
if errors.length > 0
err "importing some links", errors.join("\n\n")
loading = yes
await handle_import!
settings_active = no settings_active = no
loading = no loading = no
get math_result
try
let result = Number(eval_math state.query)
throw _ if isNaN result
result
catch
no
def handle_click_export def handle_click_export
loading = yes loading = yes
await reload_db!
let links = state.links.map do |link|
construct_link_text link
let datetime = new Date!.toString!.split(" ") let datetime = new Date!.toString!.split(" ")
let date = datetime.slice(1, 4).join("-").toLowerCase! let date = datetime.slice(1, 4).join("-").toLowerCase!
let time = datetime[4].split(":").join("-") let time = datetime[4].split(":").join("-")
let filename = "fuzzyhome_v{version}_{date}_{time}.json" let filename = "fuzzyhome_v{version}_{date}_{time}.txt"
const blob = await db.export({ prettyJson: yes }) download(links.join("\n"), filename, "text/plain")
download(blob, filename, "application/json")
settings_active = no settings_active = no
loading = no loading = no
get math_result
try
let result = Number(eval_math state.query)
throw _ if isNaN result
result
catch
no
def handle_click_github def handle_click_github
global.location.href = "https://github.com/familyfriendlymikey/fuzzyhome" global.location.href = "https://github.com/familyfriendlymikey/fuzzyhome"

Loading…
Cancel
Save