From 4e41ddffa4cd5f89ae3f24ef322c6b7c9ff12dc8 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Tue, 23 Jul 2024 14:53:44 +0200 Subject: [PATCH 1/3] Bump `gphoto2` dependency to v0.11 --- shard.lock | 2 +- shard.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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..474a41a 100644 --- a/shard.yml +++ b/shard.yml @@ -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 From f7cf33807e4d2f4ae2e30d509432edd92e3d5f28 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Tue, 23 Jul 2024 14:54:25 +0200 Subject: [PATCH 2/3] Cleanup routes and helpers implementation --- src/ext/kemal_gphoto2.cr | 8 +++----- src/gphoto2/web/routes.cr | 37 ++++++++++++++----------------------- 2 files changed, 17 insertions(+), 28 deletions(-) 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 From c26319ec2fcd7e8ff28239b37ebdbc93f06ccc4d Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Tue, 23 Jul 2024 14:55:00 +0200 Subject: [PATCH 3/3] Bump to v1.1.1 --- shard.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shard.yml b/shard.yml index 474a41a..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