Skip to content

Commit

Permalink
changed hardcoded values into config
Browse files Browse the repository at this point in the history
used `contentdb` instead of `content`
  • Loading branch information
sh-zam committed Jan 31, 2019
1 parent a00aa59 commit 305576d
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/contentdb
/third-party
/log
/packages
/themes
14 changes: 7 additions & 7 deletions base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ log.trace("[loading] libraries")

lua_math.randomseed(os.time())

tera.instance = tera.new(torchbear.settings.templates_path or "templates/**/*")
tera.instance = tera.new(_G.templates)

log.level = torchbear.settings.log_level or "info"

fs.create_dir("log")
log.outfile = "log/lighttouch"
fs.create_dir(_G.log_dir)
log.outfile = _G.log_dir.."/lighttouch"

-- Get home-store uuid
local home_store = fs.read_file("home-store.txt")
local home_store = fs.read_file(_G.home_store)
if not home_store then
home_store = uuid.v4()
log.info("No home content store found. Creating new one with uuid " .. home_store)
local file = io.open("home-store.txt", "w")
local file = io.open(_G.home_store, "w")
if not file then
log.error("Could not open home-store.txt")
end
file:write(home_store)
file:close()
fs.create_dir("content/" .. home_store, true)
fs.create_dir(_G.content .. home_store, true)
end
contentdb.home = home_store

if torchbear.settings.theme then
theme_loader.load_themes("themes/", torchbear.settings.theme)
theme_loader.load_themes(_G.themes_dir, _G.main_theme)
end

local incoming_request_event = events["incoming_request_received"]
Expand Down
10 changes: 10 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- config
_G.app_path = fs.canonicalize(arg[1]:match(".+/")) .. "/"
_G.db_path = app_path.."/contentdb/"
_G.templates = app_path..(torchbear.settings.templates_path or "templates/**/*")
_G.log_dir = app_path.."log"
_G.content = app_path.."content/"
_G.home_store = app_path.."home-store.txt"
_G.main_theme = torchbear.settings.theme
_G.themes_dir = app_path.."themes/"
--
4 changes: 3 additions & 1 deletion init.lua
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env torchbear
-- Lighttouch · Torchbear App

require "config"

-- this config must be before requires
local address = torchbear.settings.address or "localhost"
local port = torchbear.settings.port or "3000"
package.path = package.path..";lighttouch-base/?.lua;"
package.path = package.path..";" .. _G.app_path.."?.lua;"
--

require "mod"
Expand Down
6 changes: 3 additions & 3 deletions keys/connect_profile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ function keys.connect_profile (data)
local profile_uuid = data.uuid
result.profile = profile_uuid

content.write_file(profile_uuid, profile_uuid, {
contentdb.write_file(profile_uuid, profile_uuid, {
type = "profile",
name = data.name
})

if data.sign_public_key then
local sign_pub_id = uuid.v4()

content.write_file(profile_uuid, uuid.v4(), {
contentdb.write_file(profile_uuid, uuid.v4(), {
type = "key",
kind = "sign_public",
}, data.sign_public_key)
Expand All @@ -24,7 +24,7 @@ function keys.connect_profile (data)
if data.place then
local place_id = uuid.v4()

content.write_file(profile_uuid, uuid.v4(), {
contentdb.write_file(profile_uuid, uuid.v4(), {
type = "place",
host = data.place,
})
Expand Down
2 changes: 1 addition & 1 deletion keys/get_private_key.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function keys.get_private_key ()
local priv_key = content.walk_documents(content.home,
local priv_key = contentdb.walk_documents(contentdb.home,
function (file_uuid, header, body)
if header.model == "key"
and header.kind == "sign_private"
Expand Down
2 changes: 1 addition & 1 deletion keys/get_profile.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function keys.get_profile (profile)
return content.walk_documents(profile or content.home,
return contentdb.walk_documents(profile or contentdb.home,
function (file_uuid, header, body)
if header.model == "profile" then
return file_uuid, header.name
Expand Down
4 changes: 2 additions & 2 deletions keys/get_profile_data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ function keys.get_profile_data ()
local uuid, name = keys.get_profile()
log.debug("UUID: " .. tostring(uuid))

data.sign_public_key = content.walk_documents(uuid,
data.sign_public_key = contentdb.walk_documents(uuid,
function (file_uuid, header, body)
if header.model == "key"
and header.kind == "sign_private"
then return body end
end
)

data.place = content.walk_documents(uuid,
data.place = contentdb.walk_documents(uuid,
function (file_uuid, header, body)
if header.model == "place" then
return header.host
Expand Down
2 changes: 1 addition & 1 deletion keys/verify_http_signature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function keys.verify_http_signature (message)
log.debug("keyId " .. keyId)
log.debug("signature" .. signature)

local pub_key = content.walk_documents(keyId,
local pub_key = contentdb.walk_documents(keyId,
function (file_uuid, header, body)
if header.model == "key" and header.kind == "sign_public" then
return body
Expand Down
4 changes: 2 additions & 2 deletions keys/witness_document.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function keys.witness_document (document_id)
local profile_uuid = get_profile()
if not profile_uuid then return nil, "Profile not found" end

local fields, body, store = content.read_document(document_id)
local fields, body, store = contentdb.read_document(document_id)
if not fields then return nil, "Document not found" end

local priv_key = keys.get_private_key()
Expand Down Expand Up @@ -32,7 +32,7 @@ function keys.witness_document (document_id)
signature = signature
}

content.write_file("home", witness_id, witness_fields, "")
contentdb.write_file("home", witness_id, witness_fields, "")

return witness_id
end
4 changes: 2 additions & 2 deletions loaders/actions/custom_require.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function actions_loader.custom_require(name)
if string.match( name, "actions") then
package.preload[name] = function(modulename)
local created_file = io.open("module.lua", "w+")
local modulepath = string.gsub(modulename, "%.", "/")
local created_file = io.open("module.lua", "w+")
local modulepath = _G.app_path .. string.gsub(modulename, "%.", "/")
local path = "/"
local filename = string.gsub(path, "%?", modulepath)
local file = io.open(filename, "rb")
Expand Down
4 changes: 2 additions & 2 deletions loaders/package.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-- Foreach package in packages path, get a list of every component from
-- events.txt, disabled_actions.txt, rules/, and actions/
-- then run each loader
_G.packages_path = "packages" -- directory where packages are stored
_G.packages_path = fs.sanitize(_G.app_path.."/packages/") -- directory where packages are stored
-- Split packages path to more easily determine current package name
local packages_path_modules = _G.packages_path:split( "/" )
-- Count packages so to process the loop in the correct number of iterations?
local packages_path_length = #packages_path_modules
-- Add the packages to the Lua search path, so that each package's components
-- can be required using its name as if it was a Lua module, eg:
-- require "lighttouch-libs.actions.create_key"
package.path = package.path..";./packages/?.lua"
package.path = package.path.. packages_path .. "?.lua"

-- Foreach event, get its associated actions and the parameters needed for its actions
_G.events = { } -- events table
Expand Down
2 changes: 1 addition & 1 deletion loaders/rules/custom_require.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function rules_loader.custom_require(name)
if string.match( name, "rules") then
package.preload[name] = function(modulename)
local created_file = io.open("module.lua", "w+")
local modulepath = string.gsub(modulename, "%.", "/")
local modulepath = _G.app_path .. string.gsub(modulename, "%.", "/")
local path = "/"
local filename = string.gsub(path, "%?", modulepath)
local file = io.open(filename, "rb")
Expand Down
3 changes: 3 additions & 0 deletions mod.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

_G.log = require "third-party.log"
-- _G.inspect = require "third-party.inspect"
_G.luvent = require "third-party.Luvent"
Expand All @@ -13,6 +14,8 @@ require "third-party.get_all_files"
require "third-party.read_file"
require "third-party.read_lines"
require "third-party.path_separator"
require "third-party.join"
require "third-party.sanitize"
_G.contentdb = require "contentdb.mod"
_G.keys = require "keys.mod"
require "loaders.package"
Expand Down

0 comments on commit 305576d

Please sign in to comment.