|
|
|
@ -13,9 +13,17 @@ require 'mysql2' |
|
|
|
|
require 'json' |
|
|
|
|
require 'sinatra' |
|
|
|
|
|
|
|
|
|
# allow dumping crashes in browser |
|
|
|
|
DEBUG = true |
|
|
|
|
# maximum number of parts returned |
|
|
|
|
PARTS_LIMIT = 100 |
|
|
|
|
# credentials for database |
|
|
|
|
CREDENTIALS = "credentials.json" |
|
|
|
|
# folder name for served pages |
|
|
|
|
PUBLIC = "public" |
|
|
|
|
# folder name for part attachments (in PUBLIC) |
|
|
|
|
ATTACHMENTS = "attachments" |
|
|
|
|
|
|
|
|
|
raise "database information #{CREDENTIALS} do not exist" unless File.file? CREDENTIALS |
|
|
|
|
|
|
|
|
|
# open server |
|
|
|
@ -109,6 +117,17 @@ def get_part_by_id(id) |
|
|
|
|
part["properties"][k] ||= v |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
# add attachments |
|
|
|
|
part["attachments"] = [] |
|
|
|
|
dir = PUBLIC + "/" + ATTACHMENTS + "/" + part["name"] |
|
|
|
|
Dir.entries(dir).each do |file| |
|
|
|
|
path = dir + "/" + file |
|
|
|
|
next unless File.file? path |
|
|
|
|
part["attachments"] << ATTACHMENTS + "/" + part["name"] + "/" + file |
|
|
|
|
end |
|
|
|
|
if parent then |
|
|
|
|
part["attachments"] += parent["attachments"] |
|
|
|
|
end |
|
|
|
|
# clean up |
|
|
|
|
delete = ["parent"] |
|
|
|
|
delete.each do |k| |
|
|
|
|