Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: responseUrl json path parsing broken / uploader compat #107

Closed
6days9weeks opened this issue Jan 8, 2025 · 3 comments
Closed

bug: responseUrl json path parsing broken / uploader compat #107

6days9weeks opened this issue Jan 8, 2025 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@6days9weeks
Copy link

6days9weeks commented Jan 8, 2025

Describe the bug
I'm trying to upload files to my https://github.com/9001/copyparty server with ishare. The file uploads to the server perfectly but when ishare copies the responseUrl to my clipboard it doesn't replaced it like it's set to. According to the readme arrays are supported, my server returns a json like {"files": [{"url:"url"}]}. I've tried setting responseUrl to {files[0].url} or {{files[0].url}} or files[0].url or {{files.url}}, I'm not sure what I'm doing wrong here.

To Reproduce
Steps to reproduce the behavior:

  1. Setup copyparty
  2. Setup customer uploader with file form f and responseUrl to {{files[0].url}}
  3. Upload any image
  4. It copies url encode of the property we set and not the url from json.

Expected behavior
It should get the url from the first item of files key in the provided json.
Screenshots
If applicable, add screenshots to help explain your problem.
image
image
Desktop (please complete the following information):

  • OS: MacOS 15.2
  • Version 4.1.5
@9001
Copy link

9001 commented Jan 9, 2025

it appears the regex in tagPlaceholders is too strict, not allowing . to appear anywhere in the json path.

with the following hack...

diff --git a/ishare/Http/Custom.swift b/ishare/Http/Custom.swift
index 40473e7..d8d5488 100644
--- a/ishare/Http/Custom.swift
+++ b/ishare/Http/Custom.swift
@@ -149 +149 @@ private func tagPlaceholders(in url: String) -> (taggedUrl: String, tags: [(Stri
-    let pattern = "\\{\\{([a-zA-Z0-9_]+(\\[[0-9]+\\])?)\\}\\}"
+    let pattern = "\\{\\{(.*)\\}\\}"

...the following iscu works for me:

{
  "name": "copyparty",
  "requestURL": "http://127.0.0.1:3923/screenshots/?j",
  "headers": { 
    "pw": "your_password_here"
  },
  "fileFormName": "f",
  "responseURL": "{{files[0].url}}"
}

but I think there might be a second bug as well; when I also include the properties to enable upload deletion,

{
  "deletionURL": "{{files[0].url}}",
  "deleteRequestType": "DELETE"
}

...then I get The data couldn’t be read because it isn’t in the correct format.

note that I haven't had a chance to test upload deletion through ishare, but I believe it should work if you run copyparty with the -e2d option.

btw, the next version of copyparty (~4 days) will support specifying "accept": "json" in the headers section, as an alternative to the ?j suffix to the requestURL, since that could be a source for confusion.

@castdrian castdrian added the bug Something isn't working label Jan 9, 2025
@castdrian castdrian changed the title responseUrl not working? bug: responseUrl json path parsing broken / uploader Jan 9, 2025
@castdrian castdrian changed the title bug: responseUrl json path parsing broken / uploader bug: responseUrl json path parsing broken / uploader compat Jan 9, 2025
@castdrian
Copy link
Owner

castdrian commented Jan 9, 2025

The regex approach has been particularly unclean, I’ve been intending to replace it eventually, hotfix with a pattern change as suggested above will probably resolve this for the time being, as for the parsing error, that I can’t repro, if you’ve had any version prior to v2 installed (which is unlikely) it might be worth trying to wipe the app and all of its data dirs (including icloud data)

@9001
Copy link

9001 commented Jan 9, 2025

hotfix with a pattern change as suggested above will probably resolve this for the time being

just in case someone configures a value which contains multiple templated values, then perhaps let pattern = "\\{\\{([^}]+)\\}\\}"

...but I'll leave the exact fix to you 👍

if you’ve had any version prior to v2 installed (which is unlikely)

indeed, i first discovered your project just now (it's really cool btw!)

but it appears i am unable to import any iscu which includes either "deleteRequestType":"DELETE" or "deleteRequestType":"delete", for example https://github.com/castdrian/ishare/blob/main/examples/chibisafe.iscu

it fails here: let uploader = try decoder.decode(CustomUploader.self, from: data)

if this works for you, then it will be interesting to learn what the difference is between our systems. I am testing this on an m1 mbp running macos 15.2 and xcode 16.1 (16B40).

9001 added a commit to 9001/copyparty that referenced this issue Jan 11, 2025
also includes a slight tweak to the json upload info:

when exactly one file is uploaded, the json-response has a
new top-level property, `fileurl` -- this is just a copy of
`files[0].url` as a workaround for castdrian/ishare#107
("only toplevel json properties can be referenced")
@castdrian castdrian added this to the 4.2.0 milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants