mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-07-13 06:04:26 +02:00
Docify: remove server side script, move all operation to client side
All checks were successful
gitea-sync/antosdk-apps/pipeline/head This commit looks good
All checks were successful
gitea-sync/antosdk-apps/pipeline/head This commit looks good
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
Simple PDF document manager
|
||||
|
||||
## Change logs
|
||||
- v0.1.1-b: move PDF merge and document thumbnail generation to client side, remove server side lua script
|
||||
- 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
|
||||
|
@ -1,146 +0,0 @@
|
||||
local arg = ...
|
||||
|
||||
ulib = require("ulib")
|
||||
vfs = require("vfs")
|
||||
|
||||
local handle = {}
|
||||
local docpath = nil
|
||||
|
||||
local result = function(data)
|
||||
return {
|
||||
error = false,
|
||||
result = data
|
||||
}
|
||||
end
|
||||
|
||||
local error = function(data)
|
||||
return {
|
||||
error = data,
|
||||
result = false
|
||||
}
|
||||
end
|
||||
|
||||
local mkdirp =function(p)
|
||||
if not vfs.exists(p) then
|
||||
if not vfs.mkdir(p) then
|
||||
return false, error("Unable to create directory: "..p)
|
||||
end
|
||||
end
|
||||
return true, nil
|
||||
end
|
||||
|
||||
handle.merge_files = function(data)
|
||||
local firstfile = data.file[1]
|
||||
local fpath = docpath.."/"..data.cid
|
||||
local r, e = mkdirp(fpath)
|
||||
if not r then return e end
|
||||
fpath = fpath.."/"..os.date("%d-%m-%Y_%H_%M_%S")..".pdf"
|
||||
-- concat the files
|
||||
if #data.file > 1 then
|
||||
local cmd = "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="..vfs.ospath(fpath)
|
||||
for i,v in ipairs(data.file) do
|
||||
cmd = cmd.." \""..vfs.ospath(v).."\""
|
||||
end
|
||||
os.execute(cmd)
|
||||
if not vfs.exists(fpath) then
|
||||
return error("Unable to merge PDF files")
|
||||
end
|
||||
cmd = "chmod 777 "..vfs.ospath(fpath)
|
||||
os.execute(cmd)
|
||||
else
|
||||
local cmd = "mv \""..vfs.ospath(firstfile).."\" \""..vfs.ospath(fpath).."\""
|
||||
os.execute(cmd)
|
||||
if not vfs.exists(fpath) then
|
||||
return error("Unable to move PDF file")
|
||||
end
|
||||
end
|
||||
-- move the thumb file to the cache folder
|
||||
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/"..enc.sha1(v:gsub(docpath, ""))..".png"
|
||||
if vfs.exists(thumb) then
|
||||
vfs.delete(thumb)
|
||||
end
|
||||
-- delete all files
|
||||
if vfs.exists(v) then
|
||||
vfs.delete(v)
|
||||
end
|
||||
end
|
||||
return result(fpath)
|
||||
end
|
||||
|
||||
handle.preview = function(path)
|
||||
-- convert -resize 300x500 noel.pdf[0] thumb.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
|
||||
|
||||
if vfs.exists(tpath) then
|
||||
local cmd = "chmod 777 "..vfs.ospath(tpath)
|
||||
os.execute(cmd)
|
||||
return result(tpath)
|
||||
else
|
||||
return error("do not exist")
|
||||
end
|
||||
end
|
||||
|
||||
handle.deletedoc = function(param)
|
||||
-- move file to unclassified
|
||||
local newfile = docpath.."/unclassified/"..utils.basename(param.file)
|
||||
vfs.move(param.file, newfile)
|
||||
-- delete thumb file
|
||||
local thumb = docpath.."/cache/"..enc.sha1(param.file:gsub(docpath,""))..".png"
|
||||
if vfs.exists(thumb) then
|
||||
vfs.delete(thumb)
|
||||
end
|
||||
return result("Document entry deleted")
|
||||
end
|
||||
|
||||
handle.updatedoc = function(param)
|
||||
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/"..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/"..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
|
||||
end
|
||||
param.data.file = r.result
|
||||
print(r.result)
|
||||
param.data.mtime = os.time(os.date("!*t"))
|
||||
return result(param.data)
|
||||
--return handle.update({
|
||||
-- table = "docs",
|
||||
-- data = param.data
|
||||
--})
|
||||
end
|
||||
|
||||
if arg.action and handle[arg.action] then
|
||||
-- check if the database exits
|
||||
docpath = arg.docpath
|
||||
|
||||
return handle[arg.action](arg.args)
|
||||
else
|
||||
return error("Invalid action parameter")
|
||||
end
|
@ -1,4 +1,3 @@
|
||||
|
||||
afx-app-window[data-id = "Docify"] .header .label-text
|
||||
{
|
||||
font-weight: bold;
|
||||
|
File diff suppressed because one or more lines are too long
@ -7,14 +7,16 @@
|
||||
"author": "Dany LE",
|
||||
"email": "mrsang@iohub.dev"
|
||||
},
|
||||
"version": "0.1.0-b",
|
||||
"version": "0.1.1-b",
|
||||
"category": "Office",
|
||||
"iconclass": "bi bi-collection-fill",
|
||||
"mimes": [
|
||||
"none"
|
||||
],
|
||||
"dependencies": [
|
||||
"SQLiteDB@0.1.0-a"
|
||||
"SQLiteDB@0.1.0-a",
|
||||
"libpdfjs@2.6.347-r",
|
||||
"PDFLib@1.17.1"
|
||||
],
|
||||
"locale": {},
|
||||
"locales": {
|
||||
|
@ -20,6 +20,7 @@
|
||||
<afx-vbox>
|
||||
<div data-id = "preview-container">
|
||||
<canvas data-id="preview-canvas"></canvas>
|
||||
<canvas data-id="tmp-canvas" style="display:none;"></canvas>
|
||||
</div>
|
||||
<afx-grid-view data-id="docgrid"></afx-grid-view>
|
||||
<div style="text-align: right;" data-height="35" >
|
||||
|
Reference in New Issue
Block a user