diff --git a/Blogger/dialogs.ts b/Blogger/dialogs.ts
index f0167dc..d661ec3 100644
--- a/Blogger/dialogs.ts
+++ b/Blogger/dialogs.ts
@@ -87,7 +87,7 @@ namespace OS {
-\s
+\
`;
// This dialog is use for cv section editing
diff --git a/Docify/README.md b/Docify/README.md
index 5dd2277..666b1ca 100644
--- a/Docify/README.md
+++ b/Docify/README.md
@@ -2,6 +2,7 @@
Simple PDF document manager
## Change logs
+- v0.1.0-b: use libsqlite for database handling
- v0.0.9-b: Adapt to support AntOS 2.0.x
- v0.0.8-b: Allow upload files directly from the app
- v0.0.7-a: Change category and icon
diff --git a/Docify/api/api.lua b/Docify/api/api.lua
index 9fb4241..54c172f 100644
--- a/Docify/api/api.lua
+++ b/Docify/api/api.lua
@@ -1,12 +1,10 @@
local arg = ...
ulib = require("ulib")
-sqlite = modules.sqlite()
vfs = require("vfs")
local handle = {}
local docpath = nil
-local dbpath = nil
local result = function(data)
return {
@@ -31,7 +29,7 @@ local mkdirp =function(p)
return true, nil
end
-local merge_files = function(data)
+handle.merge_files = function(data)
local firstfile = data.file[1]
local fpath = docpath.."/"..data.cid
local r, e = mkdirp(fpath)
@@ -57,14 +55,14 @@ local merge_files = function(data)
end
end
-- move the thumb file to the cache folder
- local thumb = docpath.."/cache/"..std.sha1(firstfile:gsub(docpath, ""))..".png"
- local desthumb = docpath.."/cache/"..std.sha1(fpath:gsub(docpath, ""))..".png"
+ local thumb = docpath.."/cache/"..enc.sha1(firstfile:gsub(docpath, ""))..".png"
+ local desthumb = docpath.."/cache/"..enc.sha1(fpath:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.move(thumb, desthumb)
end
-- remove all other thumb files
for i,v in ipairs(data.file) do
- thumb = docpath.."/cache/"..std.sha1(v:gsub(docpath, ""))..".png"
+ thumb = docpath.."/cache/"..enc.sha1(v:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.delete(thumb)
end
@@ -76,166 +74,15 @@ local merge_files = function(data)
return result(fpath)
end
-handle.init = function(args)
-
- local r, e = mkdirp(docpath)
- if not r then return e end
-
- r, e = mkdirp(docpath.."/unclassified")
- if not r then return e end
-
- r, e = mkdirp(docpath.."/cache")
- if not r then return e end
-
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to initialized database "..dbpath)
- end
- local sql
- -- check if table exists
- if sqlite.hasTable(db, "categories") == 0 then
- -- create the table
- sql = [[
- CREATE TABLE "categories" (
- "id" INTEGER,
- "name" TEXT NOT NULL,
- PRIMARY KEY("id" AUTOINCREMENT)
- );
- ]]
- if sqlite.query(db, sql) ~= 1 then
- sqlite.dbclose(db)
- return error("Unable to create table categories")
- end
- -- insert unknown category
- sql = [[
- INSERT INTO categories("id","name") VALUES (0,'Uncategoried');
- ]]
- if sqlite.query(db, sql) ~= 1 then
- sqlite.dbclose(db)
- return error("Unable to create default category")
- end
- end
-
- if sqlite.hasTable(db, "owners") == 0 then
- -- create the table
- sql = [[
- CREATE TABLE "owners" (
- "id" INTEGER,
- "name" TEXT NOT NULL,
- PRIMARY KEY("id" AUTOINCREMENT)
- );
- ]]
- if sqlite.query(db, sql) ~= 1 then
- sqlite.dbclose(db)
- return error("Unable to create table owners")
- end
- -- insert unknown category
- sql = [[
- INSERT INTO owners("id","name") VALUES (0,'None');
- ]]
- if sqlite.query(db, sql) ~= 1 then
- sqlite.dbclose(db)
- return error("Unable to create default None owner")
- end
- end
-
- if sqlite.hasTable(db, "docs") == 0 then
- -- create the table
- sql = [[
- CREATE TABLE "docs" (
- "id" INTEGER,
- "name" TEXT NOT NULL,
- "ctime" INTEGER,
- "day" INTEGER,
- "month" INTEGER,
- "year" INTEGER,
- "cid" INTEGER DEFAULT 0,
- "oid" INTEGER DEFAULT 0,
- "file" TEXT NOT NULL,
- "tags" TEXT,
- "note" TEXT,
- "mtime" INTEGER,
- FOREIGN KEY("oid") REFERENCES "owners"("id") ON DELETE SET DEFAULT ON UPDATE NO ACTION,
- FOREIGN KEY("cid") REFERENCES "categories"("id") ON DELETE SET DEFAULT ON UPDATE NO ACTION,
- PRIMARY KEY("id" AUTOINCREMENT)
- );
- ]]
- if sqlite.query(db, sql) ~= 1 then
- sqlite.dbclose(db)
- return error("Unable to create table docs")
- end
- end
- sqlite.dbclose(db)
- return result("Docify initialized")
-end
-
-handle.select = function(param)
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local r = sqlite.select(db, param.table, "*", param.cond)
- sqlite.dbclose(db)
- if r == nil then
- return error("Unable to select data from "..param.table)
- else
- return result(r)
- end
-end
-
-handle.fetch = function(table)
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local r = sqlite.select(db, table, "*", "1=1")
- sqlite.dbclose(db)
- if r == nil then
- return error("Unable to fetch data from "..table)
- else
- return result(r)
- end
-end
-
-handle.insert = function(param)
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local keys = {}
- local values = {}
- for k,v in pairs(param.data) do
- if k ~= "id" then
- table.insert(keys,k)
- if type(v) == "number" then
- table.insert(values, v)
- elseif type(v) == "boolean" then
- table.insert( values, v and 1 or 0 )
- else
- local t = "\""..v:gsub('"', '""').."\""
- table.insert(values,t)
- end
- end
- end
- local sql = "INSERT INTO "..param.table.." ("..table.concat(keys,',')..') VALUES ('
- sql = sql..table.concat(values,',')..');'
- local r = sqlite.query(db, sql)
- sqlite.dbclose(db)
- if r == nil then
- return error("Unable to insert data to "..param.table)
- else
- return result("Data inserted")
- end
-end
-
handle.preview = function(path)
-- convert -resize 300x500 noel.pdf[0] thumb.png
- local name = std.sha1(path:gsub(docpath,""))..".png"
+ local name = enc.sha1(path:gsub(docpath,""))..".png"
-- try to find the thumb
local tpath = docpath.."/cache/"..name
if not vfs.exists(tpath) then
-- regenerate thumb
local cmd = "convert -resize 250x500 \""..vfs.ospath(path).."\"[0] "..vfs.ospath(tpath)
+ LOG_ERROR(cmd)
os.execute(cmd)
end
@@ -248,57 +95,12 @@ handle.preview = function(path)
end
end
-handle.get_doc = function(id)
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local r = sqlite.select(db, "docs", "*", "id = "..id)
- if r == nil or #r == 0 then
- sqlite.dbclose(db)
- return error("Unable to select data from "..param.table)
- else
- r = r[1]
- local ret, meta = vfs.fileinfo(r.file)
- if ret then
- r.fileinfo = meta
- end
- local o = sqlite.select(db, "owners", "*", "id = "..r.oid)
- sqlite.dbclose(db)
- if o == nil or #o == 0 then
- return result(r)
- else
- o = o[1]
- r.owner = o.name
- if r.ctime then
- r.ctime = os.date("%d/%m/%Y %H:%M:%S", r.ctime)
- end
-
- if r.mtime then
- r.mtime = os.date("%d/%m/%Y %H:%M:%S", r.mtime)
- end
- local edate = ""
- return result(r)
- end
- end
-end
-
handle.deletedoc = function(param)
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local sql = "DELETE FROM docs WHERE id="..param.id..";"
- local ret = sqlite.query(db, sql) == 1
- sqlite.dbclose(db)
- if not ret then
- return error("Unable to delete doc meta-data from database")
- end
-- move file to unclassified
- local newfile = docpath.."/unclassified/"..std.basename(param.file)
+ local newfile = docpath.."/unclassified/"..utils.basename(param.file)
vfs.move(param.file, newfile)
-- delete thumb file
- local thumb = docpath.."/cache/"..std.sha1(param.file:gsub(docpath,""))..".png"
+ local thumb = docpath.."/cache/"..enc.sha1(param.file:gsub(docpath,""))..".png"
if vfs.exists(thumb) then
vfs.delete(thumb)
end
@@ -306,20 +108,20 @@ handle.deletedoc = function(param)
end
handle.updatedoc = function(param)
- local r = merge_files(param.data)
+ local r = handle.merge_files(param.data)
if r.error then return r end
if param.rm then
-- move ve the old file to unclassified
- local newfile = docpath.."/unclassified/"..std.basename(param.rm)
+ local newfile = docpath.."/unclassified/"..utils.basename(param.rm)
local cmd = "rm -f "..vfs.ospath(param.rm)
os.execute(cmd)
--if vfs.exists(param.rm) then
-- vfs.move(param.rm, newfile)
--end
-- move the thumb file if needed
- local thumb = docpath.."/cache/"..std.sha1(param.rm:gsub(docpath,""))..".png"
- local newwthumb = docpath.."/cache/"..std.sha1(newfile:gsub(docpath, ""))..".png"
+ local thumb = docpath.."/cache/"..enc.sha1(param.rm:gsub(docpath,""))..".png"
+ local newwthumb = docpath.."/cache/"..enc.sha1(newfile:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.move(thumb, newwthumb)
end
@@ -327,107 +129,16 @@ handle.updatedoc = function(param)
param.data.file = r.result
print(r.result)
param.data.mtime = os.time(os.date("!*t"))
- return handle.update({
- table = "docs",
- data = param.data
- })
+ return result(param.data)
+ --return handle.update({
+ -- table = "docs",
+ -- data = param.data
+ --})
end
-
-handle.insertdoc = function(data)
- local r = merge_files(data)
- if r.error then return r end
- -- save data
- data.file = r.result
- data.ctime = os.time(os.date("!*t"))
- data.mtime = os.time(os.date("!*t"))
- local ret = handle.insert({
- table = "docs",
- data = data
- })
- return ret
-end
-
-handle.update = function(param)
- if not param.data.id or param.data.id == 0 then
- return error("Record id is 0 or not found")
- end
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local lst = {}
- for k,v in pairs(param.data) do
- if(type(v)== "number") then
- table.insert(lst,k.."="..v)
- elseif type(v) == "boolean" then
- table.insert( lst, k.."="..(v and 1 or 0) )
- else
- table.insert(lst,k.."=\""..v:gsub('"', '""').."\"")
- end
- end
-
- local sql = "UPDATE "..param.table.." SET "..table.concat(lst,",").." WHERE id="..param.data.id..";"
- local r = sqlite.query(db, sql)
- sqlite.dbclose(db)
- if r == nil then
- return error("Unable to update data to "..param.table)
- else
- return result("Data Updated")
- end
-end
-
-handle.delete = function(param)
- if param.id == 0 then
- return error("Record with id = 0 cannot be deleted")
- end
-
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local sql = "DELETE FROM "..param.table.." WHERE id="..param.id..";"
- local r = sqlite.query(db, sql)
- sqlite.dbclose(db)
- if r == nil then
- return error("Unable to delete data from "..param.table)
- else
- return result("Data deleted")
- end
-end
-
-handle.printdoc = function(opt)
- local cmd = "lp "
- if opt.printer and opt.printer ~= "" then
- cmd = cmd .. " -d "..opt.printer
- end
- if opt.side == 0 then
- cmd = cmd.. " -o sides=one-sided"
- elseif opt.side == 1 then
- cmd = cmd.. " -o sides=two-sided-long-edge"
- elseif opt.side == 2 then
- cmd = cmd .. " -o sides=two-sided-short-edge"
- end
- -- orientation landscape
- if opt.orientation == 1 then
- cmd = cmd.." -o orientation-requested=5"
- end
-
- if opt.range == 1 then
- cmd = cmd.." -P "..opt.pages
- end
-
- cmd = cmd.. " "..vfs.ospath(opt.file)
- print(cmd)
- os.execute(cmd)
- return result("A print job has been posted on server. Check if it successes")
-end
-
-
if arg.action and handle[arg.action] then
-- check if the database exits
docpath = arg.docpath
- dbpath = docpath.."/docify.db"
return handle[arg.action](arg.args)
else
diff --git a/Docify/assets/scheme.html b/Docify/assets/scheme.html
index 6b98f30..f3e98cd 100644
--- a/Docify/assets/scheme.html
+++ b/Docify/assets/scheme.html
@@ -25,7 +25,6 @@
-
diff --git a/Docify/build.json b/Docify/build.json
index 27525e2..ae3e803 100644
--- a/Docify/build.json
+++ b/Docify/build.json
@@ -13,17 +13,35 @@
}
]
},
- "coffee": {
+ "locale": {
+ "require": ["locale"],
+ "jobs": [
+ {
+ "name":"locale-gen",
+ "data": {
+ "src": "",
+ "exclude": ["build/", "api/", "css/", "coffees/"],
+ "locale": "en_GB",
+ "dest": "package.json"
+ }
+ }
+ ]
+ },
+ "ts": {
"require": [
- "coffee"
+ "ts"
],
"jobs": [
{
- "name": "coffee-compile",
+ "name": "ts-import",
+ "data": ["sdk://core/ts/core.d.ts", "sdk://core/ts/jquery.d.ts","sdk://core/ts/antos.d.ts"]
+ },
+ {
+ "name": "ts-compile",
"data": {
"src": [
- "coffees/dialogs.coffee",
- "coffees/main.coffee"
+ "ts/dialogs.ts",
+ "ts/main.ts"
],
"dest": "build/debug/main.js"
}
@@ -65,7 +83,7 @@
],
"depend": [
"init",
- "coffee",
+ "ts",
"uglify",
"copy"
],
@@ -78,6 +96,14 @@
}
}
]
+ },
+
+ "debug": {
+ "depend": [
+ "init",
+ "ts",
+ "copy"
+ ]
}
}
}
\ No newline at end of file
diff --git a/Docify/build/debug/README.md b/Docify/build/debug/README.md
index 5dd2277..666b1ca 100644
--- a/Docify/build/debug/README.md
+++ b/Docify/build/debug/README.md
@@ -2,6 +2,7 @@
Simple PDF document manager
## Change logs
+- v0.1.0-b: use libsqlite for database handling
- v0.0.9-b: Adapt to support AntOS 2.0.x
- v0.0.8-b: Allow upload files directly from the app
- v0.0.7-a: Change category and icon
diff --git a/Docify/build/debug/api.lua b/Docify/build/debug/api.lua
index 9fb4241..54c172f 100644
--- a/Docify/build/debug/api.lua
+++ b/Docify/build/debug/api.lua
@@ -1,12 +1,10 @@
local arg = ...
ulib = require("ulib")
-sqlite = modules.sqlite()
vfs = require("vfs")
local handle = {}
local docpath = nil
-local dbpath = nil
local result = function(data)
return {
@@ -31,7 +29,7 @@ local mkdirp =function(p)
return true, nil
end
-local merge_files = function(data)
+handle.merge_files = function(data)
local firstfile = data.file[1]
local fpath = docpath.."/"..data.cid
local r, e = mkdirp(fpath)
@@ -57,14 +55,14 @@ local merge_files = function(data)
end
end
-- move the thumb file to the cache folder
- local thumb = docpath.."/cache/"..std.sha1(firstfile:gsub(docpath, ""))..".png"
- local desthumb = docpath.."/cache/"..std.sha1(fpath:gsub(docpath, ""))..".png"
+ local thumb = docpath.."/cache/"..enc.sha1(firstfile:gsub(docpath, ""))..".png"
+ local desthumb = docpath.."/cache/"..enc.sha1(fpath:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.move(thumb, desthumb)
end
-- remove all other thumb files
for i,v in ipairs(data.file) do
- thumb = docpath.."/cache/"..std.sha1(v:gsub(docpath, ""))..".png"
+ thumb = docpath.."/cache/"..enc.sha1(v:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.delete(thumb)
end
@@ -76,166 +74,15 @@ local merge_files = function(data)
return result(fpath)
end
-handle.init = function(args)
-
- local r, e = mkdirp(docpath)
- if not r then return e end
-
- r, e = mkdirp(docpath.."/unclassified")
- if not r then return e end
-
- r, e = mkdirp(docpath.."/cache")
- if not r then return e end
-
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to initialized database "..dbpath)
- end
- local sql
- -- check if table exists
- if sqlite.hasTable(db, "categories") == 0 then
- -- create the table
- sql = [[
- CREATE TABLE "categories" (
- "id" INTEGER,
- "name" TEXT NOT NULL,
- PRIMARY KEY("id" AUTOINCREMENT)
- );
- ]]
- if sqlite.query(db, sql) ~= 1 then
- sqlite.dbclose(db)
- return error("Unable to create table categories")
- end
- -- insert unknown category
- sql = [[
- INSERT INTO categories("id","name") VALUES (0,'Uncategoried');
- ]]
- if sqlite.query(db, sql) ~= 1 then
- sqlite.dbclose(db)
- return error("Unable to create default category")
- end
- end
-
- if sqlite.hasTable(db, "owners") == 0 then
- -- create the table
- sql = [[
- CREATE TABLE "owners" (
- "id" INTEGER,
- "name" TEXT NOT NULL,
- PRIMARY KEY("id" AUTOINCREMENT)
- );
- ]]
- if sqlite.query(db, sql) ~= 1 then
- sqlite.dbclose(db)
- return error("Unable to create table owners")
- end
- -- insert unknown category
- sql = [[
- INSERT INTO owners("id","name") VALUES (0,'None');
- ]]
- if sqlite.query(db, sql) ~= 1 then
- sqlite.dbclose(db)
- return error("Unable to create default None owner")
- end
- end
-
- if sqlite.hasTable(db, "docs") == 0 then
- -- create the table
- sql = [[
- CREATE TABLE "docs" (
- "id" INTEGER,
- "name" TEXT NOT NULL,
- "ctime" INTEGER,
- "day" INTEGER,
- "month" INTEGER,
- "year" INTEGER,
- "cid" INTEGER DEFAULT 0,
- "oid" INTEGER DEFAULT 0,
- "file" TEXT NOT NULL,
- "tags" TEXT,
- "note" TEXT,
- "mtime" INTEGER,
- FOREIGN KEY("oid") REFERENCES "owners"("id") ON DELETE SET DEFAULT ON UPDATE NO ACTION,
- FOREIGN KEY("cid") REFERENCES "categories"("id") ON DELETE SET DEFAULT ON UPDATE NO ACTION,
- PRIMARY KEY("id" AUTOINCREMENT)
- );
- ]]
- if sqlite.query(db, sql) ~= 1 then
- sqlite.dbclose(db)
- return error("Unable to create table docs")
- end
- end
- sqlite.dbclose(db)
- return result("Docify initialized")
-end
-
-handle.select = function(param)
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local r = sqlite.select(db, param.table, "*", param.cond)
- sqlite.dbclose(db)
- if r == nil then
- return error("Unable to select data from "..param.table)
- else
- return result(r)
- end
-end
-
-handle.fetch = function(table)
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local r = sqlite.select(db, table, "*", "1=1")
- sqlite.dbclose(db)
- if r == nil then
- return error("Unable to fetch data from "..table)
- else
- return result(r)
- end
-end
-
-handle.insert = function(param)
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local keys = {}
- local values = {}
- for k,v in pairs(param.data) do
- if k ~= "id" then
- table.insert(keys,k)
- if type(v) == "number" then
- table.insert(values, v)
- elseif type(v) == "boolean" then
- table.insert( values, v and 1 or 0 )
- else
- local t = "\""..v:gsub('"', '""').."\""
- table.insert(values,t)
- end
- end
- end
- local sql = "INSERT INTO "..param.table.." ("..table.concat(keys,',')..') VALUES ('
- sql = sql..table.concat(values,',')..');'
- local r = sqlite.query(db, sql)
- sqlite.dbclose(db)
- if r == nil then
- return error("Unable to insert data to "..param.table)
- else
- return result("Data inserted")
- end
-end
-
handle.preview = function(path)
-- convert -resize 300x500 noel.pdf[0] thumb.png
- local name = std.sha1(path:gsub(docpath,""))..".png"
+ local name = enc.sha1(path:gsub(docpath,""))..".png"
-- try to find the thumb
local tpath = docpath.."/cache/"..name
if not vfs.exists(tpath) then
-- regenerate thumb
local cmd = "convert -resize 250x500 \""..vfs.ospath(path).."\"[0] "..vfs.ospath(tpath)
+ LOG_ERROR(cmd)
os.execute(cmd)
end
@@ -248,57 +95,12 @@ handle.preview = function(path)
end
end
-handle.get_doc = function(id)
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local r = sqlite.select(db, "docs", "*", "id = "..id)
- if r == nil or #r == 0 then
- sqlite.dbclose(db)
- return error("Unable to select data from "..param.table)
- else
- r = r[1]
- local ret, meta = vfs.fileinfo(r.file)
- if ret then
- r.fileinfo = meta
- end
- local o = sqlite.select(db, "owners", "*", "id = "..r.oid)
- sqlite.dbclose(db)
- if o == nil or #o == 0 then
- return result(r)
- else
- o = o[1]
- r.owner = o.name
- if r.ctime then
- r.ctime = os.date("%d/%m/%Y %H:%M:%S", r.ctime)
- end
-
- if r.mtime then
- r.mtime = os.date("%d/%m/%Y %H:%M:%S", r.mtime)
- end
- local edate = ""
- return result(r)
- end
- end
-end
-
handle.deletedoc = function(param)
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local sql = "DELETE FROM docs WHERE id="..param.id..";"
- local ret = sqlite.query(db, sql) == 1
- sqlite.dbclose(db)
- if not ret then
- return error("Unable to delete doc meta-data from database")
- end
-- move file to unclassified
- local newfile = docpath.."/unclassified/"..std.basename(param.file)
+ local newfile = docpath.."/unclassified/"..utils.basename(param.file)
vfs.move(param.file, newfile)
-- delete thumb file
- local thumb = docpath.."/cache/"..std.sha1(param.file:gsub(docpath,""))..".png"
+ local thumb = docpath.."/cache/"..enc.sha1(param.file:gsub(docpath,""))..".png"
if vfs.exists(thumb) then
vfs.delete(thumb)
end
@@ -306,20 +108,20 @@ handle.deletedoc = function(param)
end
handle.updatedoc = function(param)
- local r = merge_files(param.data)
+ local r = handle.merge_files(param.data)
if r.error then return r end
if param.rm then
-- move ve the old file to unclassified
- local newfile = docpath.."/unclassified/"..std.basename(param.rm)
+ local newfile = docpath.."/unclassified/"..utils.basename(param.rm)
local cmd = "rm -f "..vfs.ospath(param.rm)
os.execute(cmd)
--if vfs.exists(param.rm) then
-- vfs.move(param.rm, newfile)
--end
-- move the thumb file if needed
- local thumb = docpath.."/cache/"..std.sha1(param.rm:gsub(docpath,""))..".png"
- local newwthumb = docpath.."/cache/"..std.sha1(newfile:gsub(docpath, ""))..".png"
+ local thumb = docpath.."/cache/"..enc.sha1(param.rm:gsub(docpath,""))..".png"
+ local newwthumb = docpath.."/cache/"..enc.sha1(newfile:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.move(thumb, newwthumb)
end
@@ -327,107 +129,16 @@ handle.updatedoc = function(param)
param.data.file = r.result
print(r.result)
param.data.mtime = os.time(os.date("!*t"))
- return handle.update({
- table = "docs",
- data = param.data
- })
+ return result(param.data)
+ --return handle.update({
+ -- table = "docs",
+ -- data = param.data
+ --})
end
-
-handle.insertdoc = function(data)
- local r = merge_files(data)
- if r.error then return r end
- -- save data
- data.file = r.result
- data.ctime = os.time(os.date("!*t"))
- data.mtime = os.time(os.date("!*t"))
- local ret = handle.insert({
- table = "docs",
- data = data
- })
- return ret
-end
-
-handle.update = function(param)
- if not param.data.id or param.data.id == 0 then
- return error("Record id is 0 or not found")
- end
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local lst = {}
- for k,v in pairs(param.data) do
- if(type(v)== "number") then
- table.insert(lst,k.."="..v)
- elseif type(v) == "boolean" then
- table.insert( lst, k.."="..(v and 1 or 0) )
- else
- table.insert(lst,k.."=\""..v:gsub('"', '""').."\"")
- end
- end
-
- local sql = "UPDATE "..param.table.." SET "..table.concat(lst,",").." WHERE id="..param.data.id..";"
- local r = sqlite.query(db, sql)
- sqlite.dbclose(db)
- if r == nil then
- return error("Unable to update data to "..param.table)
- else
- return result("Data Updated")
- end
-end
-
-handle.delete = function(param)
- if param.id == 0 then
- return error("Record with id = 0 cannot be deleted")
- end
-
- local db = sqlite._getdb(vfs.ospath(dbpath))
- if not db then
- return error("Unable to get database "..dbpath)
- end
- local sql = "DELETE FROM "..param.table.." WHERE id="..param.id..";"
- local r = sqlite.query(db, sql)
- sqlite.dbclose(db)
- if r == nil then
- return error("Unable to delete data from "..param.table)
- else
- return result("Data deleted")
- end
-end
-
-handle.printdoc = function(opt)
- local cmd = "lp "
- if opt.printer and opt.printer ~= "" then
- cmd = cmd .. " -d "..opt.printer
- end
- if opt.side == 0 then
- cmd = cmd.. " -o sides=one-sided"
- elseif opt.side == 1 then
- cmd = cmd.. " -o sides=two-sided-long-edge"
- elseif opt.side == 2 then
- cmd = cmd .. " -o sides=two-sided-short-edge"
- end
- -- orientation landscape
- if opt.orientation == 1 then
- cmd = cmd.." -o orientation-requested=5"
- end
-
- if opt.range == 1 then
- cmd = cmd.." -P "..opt.pages
- end
-
- cmd = cmd.. " "..vfs.ospath(opt.file)
- print(cmd)
- os.execute(cmd)
- return result("A print job has been posted on server. Check if it successes")
-end
-
-
if arg.action and handle[arg.action] then
-- check if the database exits
docpath = arg.docpath
- dbpath = docpath.."/docify.db"
return handle[arg.action](arg.args)
else
diff --git a/Docify/build/debug/main.js b/Docify/build/debug/main.js
index a43d741..b34f59c 100644
--- a/Docify/build/debug/main.js
+++ b/Docify/build/debug/main.js
@@ -1 +1 @@
-(function(){var t,i,a,r,n;(r=class t extends this.OS.GUI.BasicDialog{constructor(){super("OwnerDialog",t.scheme)}main(){return super.main(),this.oview=this.find("ownview"),this.oview.buttons=[{text:"",iconclass:"fa fa-plus-circle",onbtclick:t=>this.openDialog("PromptDialog",{title:__("Owner"),label:__("Name")}).then(t=>this.parent.exec("insert",{table:"owners",data:{name:t}}).then(t=>t.error?this.error(t.error):this.owner_refresh()).catch(t=>this.error(__("Unable to insert owner: {0}",t.toString()),t))).catch(t=>this.error(t.toString(),t))},{text:"",iconclass:"fa fa-minus-circle",onbtclick:t=>{var e;if(e=this.oview.selectedItem)return this.ask({text:__("Do you realy want to delete: `{0}`",e.data.text)}).then(t=>{if(t)return this.parent.exec("delete",{table:"owners",id:parseInt(e.data.id)}).then(t=>t.error?this.error(t.error):this.owner_refresh()).catch(t=>this.error(__("Unable delete category: {0}",t.toString()),t))})}},{text:"",iconclass:"fa fa-pencil-square-o",onbtclick:t=>{var e;if(e=this.oview.selectedItem)return this.openDialog("PromptDialog",{title:__("Owner"),label:__("Name"),value:e.data.name}).then(t=>this.parent.exec("update",{table:"owners",data:{id:parseInt(e.data.id),name:t}}).then(t=>t.error?this.error(t.error):this.owner_refresh()).catch(t=>this.error(__("Unable to update owner: {0}",t.toString()),t))).catch(t=>this.error(t.toString()))}}],this.owner_refresh()}owner_refresh(){return this.parent.exec("fetch","owners").then(t=>{var e,i,a,r;for(e=0,i=(a=t.result).length;ethis.error(__("Unable to fetch owners: {0}",t.toString()),e))}}).scheme="\n \n \n \n",(t=class t extends this.OS.GUI.BasicDialog{constructor(){super("DocDialog",t.scheme)}main(){var t,e,i,r,n,s,h,l;for(super.main(),this.flist=this.find("file-list"),this.dlist=this.find("dlist"),this.mlist=this.find("mlist"),this.ylist=this.find("ylist"),this.olist=this.find("olist"),this.setting=this.parent.setting,this.exec=this.parent.exec,this.preview=this.parent.preview,this.exec("fetch","owners").then(t=>{var e,i,a,r,n,s,h;if(t.error)return this.error(t.error);for(e=0,a=(n=t.result).length;ethis.error(__("Unable to fetch owner list: {0}",t.toString()),t)),this.dlist.push({text:"None",value:0}),h=0,t=i=1;i<=31;t=++i)this.dlist.push({text:""+t,value:t}),this.data&&parseInt(this.data.day)===t&&(h=t);for(this.dlist.selected=h,this.mlist.push({text:"None",value:0}),h=0,t=r=1;r<=12;t=++r)this.mlist.push({text:""+t,value:t}),this.data&&parseInt(this.data.month)===t&&(h=t);for(this.mlist.selected=h,this.ylist.push({text:"None",value:0}),this.ylist.selected=0,l=n=1960,s=(new Date).getFullYear();1960<=s?n<=s:n>=s;l=1960<=s?++n:--n)this.ylist.push({text:""+l,value:l,selected:this.data&&parseInt(this.data.year)===l});if(this.flist.buttons=[{text:"",iconclass:"fa fa-plus-circle",onbtclick:t=>this.openDialog(new a).then(t=>(t.text=t.filename,this.flist.push(t)))},{text:"",iconclass:"fa fa-minus-circle",onbtclick:t=>{var e;if(e=this.flist.selectedItem)return this.flist.delete(e)}}],this.flist.onlistselect=t=>this.parent.preview(t.data.item.data.path,this.find("preview-canvas")),this.find("btsave").onbtclick=t=>{var e,i;return(e={name:this.find("title").value.trim(),day:this.dlist.selectedItem.data.value,month:this.mlist.selectedItem.data.value,year:this.ylist.selectedItem.data.value,file:function(){var t,e,a,r;for(r=[],t=0,e=(a=this.flist.data).length;t0?(this.handle&&this.handle(e),this.quit()):this.notify(__("Please attach files to the entry")):this.notify(__("Please enter title"))},this.data)return this.find("title").value=this.data.name,this.find("note").value=this.data.note,this.find("tag").value=this.data.tags,(e=this.data.file.asFileHandle()).text=e.filename,this.flist.data=[e]}}).scheme='\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n