diff --git a/shard.lock b/shard.lock index 92a1ed2..40fa994 100644 --- a/shard.lock +++ b/shard.lock @@ -22,7 +22,7 @@ shards: gphoto2: git: https://github.com/sija/gphoto2.cr.git - version: 0.10.2 + version: 0.11.0 kemal: git: https://github.com/kemalcr/kemal.git diff --git a/shard.yml b/shard.yml index 9e3e3c2..67f4cbc 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: gphoto2-web -version: 1.1.0 +version: 1.1.1 authors: - Sijawusz Pur Rahnama @@ -7,7 +7,7 @@ authors: dependencies: gphoto2: github: Sija/gphoto2.cr - version: ~> 0.10.2 + version: ~> 0.11.0 pool: github: ysbaddaden/pool version: ~> 0.3.0 diff --git a/src/ext/kemal_gphoto2.cr b/src/ext/kemal_gphoto2.cr index bc7aed5..cf51af8 100644 --- a/src/ext/kemal_gphoto2.cr +++ b/src/ext/kemal_gphoto2.cr @@ -81,10 +81,8 @@ end def send_file(env, file : GPhoto2::CameraFile, *, mime_type : String? = nil, disposition = nil) restore_headers_on_exception(env.response) do |response| if file.preview? - filename = GPhoto2::CameraFile::PREVIEW_FILENAME mime_type ||= "image/jpeg" else - filename = file.name # WARNING: Executes extra calls to underlying camera if info = file.info.file? if mtime = info.mtime @@ -94,19 +92,19 @@ def send_file(env, file : GPhoto2::CameraFile, *, mime_type : String? = nil, dis end end - ext = Path[filename].extension.downcase + ext = file.path.extension.downcase disposition ||= "inline" if ext.in?(BROWSER_SAFE_EXTENSIONS) send_file env, file.to_slice, mime_type: mime_type, - filename: filename, + filename: file.name, disposition: disposition end end # ameba:disable Metrics/CyclomaticComplexity def send_file(env, file : GPhoto2::CameraFile, *, format : ImageOutputFormat?, width : Int? = nil, height : Int? = nil, disposition = nil) - path = Path[file.path] + path = file.path path_format = ImageOutputFormat.from_path?(path) case format diff --git a/src/gphoto2/web/routes.cr b/src/gphoto2/web/routes.cr index 1601a3d..a572db5 100644 --- a/src/gphoto2/web/routes.cr +++ b/src/gphoto2/web/routes.cr @@ -35,8 +35,7 @@ get "/cameras/:id/preview" do |env| # NOTE: might be good to use queue here GPhoto2::Web.camera_by_id(id) do |camera| - file = camera.preview - send_file env, file + send_file env, camera.preview end end @@ -56,8 +55,7 @@ get "/cameras/:id/config" do |env| flat = env.params.query["flat"]? == "true" GPhoto2::Web.camera_by_id(id) do |camera| - config = flat ? camera.config : camera.window - send_json env, config + send_json env, flat ? camera.config : camera.window end end @@ -77,8 +75,7 @@ get "/cameras/:id/config/:widget" do |env| widget = env.params.url["widget"] GPhoto2::Web.camera_by_id(id) do |camera| - config = camera.config[widget] - send_json env, config + send_json env, camera.config[widget] end end @@ -99,8 +96,7 @@ get "/cameras/:id/fs" do |env| id = env.params.url["id"] GPhoto2::Web.camera_by_id(id) do |camera| - fs = camera.filesystem - send_json env, fs + send_json env, camera.filesystem end end @@ -109,8 +105,7 @@ get "/cameras/:id/fs/*path" do |env| path = env.params.url["path"] GPhoto2::Web.camera_by_id(id) do |camera| - fs = camera / path - send_json env, fs + send_json env, camera / path end end @@ -119,8 +114,9 @@ delete "/cameras/:id/fs/*path" do |env| path = env.params.url["path"] GPhoto2::Web.camera_by_id(id) do |camera| - fs = camera / path - fs.delete + camera + .filesystem(path) + .delete end send_204 env end @@ -130,7 +126,6 @@ end get "/cameras/:id/blob/*filepath" do |env| id = env.params.url["id"] filepath = env.params.url["filepath"] - path = Path.posix(filepath) query_params = env.params.query @@ -152,8 +147,7 @@ get "/cameras/:id/blob/*filepath" do |env| disposition = "attachment" if download GPhoto2::Web.camera_by_id(id) do |camera| - fs = camera / path.dirname - file = fs.open(path.basename) + file = camera.blob(filepath) env.response.headers["Vary"] = "Accept" @@ -177,12 +171,11 @@ end delete "/cameras/:id/blob/*filepath" do |env| id = env.params.url["id"] filepath = env.params.url["filepath"] - path = Path.posix(filepath) GPhoto2::Web.camera_by_id(id) do |camera| - fs = camera / path.dirname - file = fs.open(path.basename) - file.delete + camera + .blob(filepath) + .delete end send_204 env end @@ -193,8 +186,7 @@ get "/cameras/:id/zip" do |env| id = env.params.url["id"] GPhoto2::Web.camera_by_id(id) do |camera| - fs = camera.filesystem - send_folder_zip env, fs, + send_folder_zip env, camera.filesystem, archive_name: camera.model end end @@ -204,8 +196,7 @@ get "/cameras/:id/zip/*path" do |env| path = env.params.url["path"] GPhoto2::Web.camera_by_id(id) do |camera| - fs = camera / path - send_folder_zip env, fs + send_folder_zip env, camera / path end end