Library phase 3: change feed and folder export for Locus (GPX) and OsmAnd (favourites + tracks zip)
This commit is contained in:
1 parent
cca985d2b9
commit
59447c56f2
8 files changed
+305
-3
No files matched your search
@@ -662,6 +662,46 @@ module Maptool
|
||||
halt 404
|
||||
end
|
||||
|
||||
# The sync feed (Library#changes): everything after ?since=<rev>.
|
||||
# Login-only, like the other exports.
|
||||
get "/api/library/changes" do
|
||||
require_login!
|
||||
json LIBRARY.changes(params[:since])
|
||||
rescue Library::InvalidValue
|
||||
halt 400, json(error: "since must be a number")
|
||||
end
|
||||
|
||||
# A folder (?folder=a/b, "" = top level) for an app: ?flavor=locus is
|
||||
# one GPX, ?flavor=osmand a zip of favourites.gpx + tracks/.
|
||||
get "/api/library/export" do
|
||||
require_login!
|
||||
folder = params[:folder].to_s
|
||||
name = folder.split("/").last || "MapTool"
|
||||
case params[:flavor]
|
||||
when "locus"
|
||||
content_type "application/gpx+xml" # before attachment, which doesn't know .gpx
|
||||
attachment "#{name}.gpx"
|
||||
LIBRARY.export_gpx(folder)
|
||||
when "osmand"
|
||||
files = LIBRARY.export_osmand(folder)
|
||||
halt 404, json(error: "nothing to export") if files.empty?
|
||||
content_type "application/zip"
|
||||
attachment "#{name}-osmand.zip"
|
||||
Zip::OutputStream.write_buffer do |zip|
|
||||
files.each do |path, gpx|
|
||||
zip.put_next_entry(path)
|
||||
zip.write(gpx)
|
||||
end
|
||||
end.string
|
||||
else
|
||||
halt 400, json(error: "flavor must be locus or osmand")
|
||||
end
|
||||
rescue Library::InvalidPath
|
||||
halt 400, json(error: "invalid folder")
|
||||
rescue Library::NotFound
|
||||
halt 404
|
||||
end
|
||||
|
||||
post "/api/library/move" do
|
||||
require_login!
|
||||
key = LIBRARY.move_node(params[:key].to_s, params[:to_folder].to_s)
|
||||
|
||||
Reference in new issue
Block a user