yitsushi / go-misskey

Misskey Go SDK
GNU General Public License v3.0
48 stars 12 forks source link

files.CreateFromURL() causes a crash in the client library. #81

Closed itsalltoast closed 3 years ago

itsalltoast commented 3 years ago

Describe the bug The CreateFromURL() function in the Drive service module is causing a crash when it is used.

📝 To Reproduce Code sample:

client := misskey.NewClient("https://host","API KEY")
if file, err := client.Drive().File().CreateFromURL(&files.CreateFromURLOptions{
  URL: "https://path/to/some/image.jpg",
}); err != nil {
panic(err)
}
// do something with the file object

🙂 Expected behavior Client passes the create_from_url call to the Misskey API on the server.

☹️ Actual Behavior

panic: reflect: call of reflect.Value.NumField on ptr Value

goroutine 1 [running]:
reflect.flag.mustBe(...)
        /usr/local/go/src/reflect/value.go:221
reflect.Value.NumField(0x7e0240, 0xc000028080, 0x16, 0xc000046800)
        /usr/local/go/src/reflect/value.go:1369 +0xc5
github.com/yitsushi/go-misskey/core.parseMultipartFields(0x8a4a00, 0xc000028080, 0x20)
        /users/mick/.go/pkg/mod/github.com/yitsushi/go-misskey@v1.0.0/core/multipart.go:19 +0x125
github.com/yitsushi/go-misskey/core.(*MultipartRequest).ToBody(0xc0000ca020, 0x845f96, 0x20, 0x0, 0x8a47c0, 0xc00009a180, 0xc00001c1b0, 0x23, 0x23, 0x0)
        /users/mick/.go/pkg/mod/github.com/yitsushi/go-misskey@v1.0.0/core/multipart_request.go:38 +0x1a5
github.com/yitsushi/go-misskey.Client.sendRequest(0x83fe9c, 0x11, 0x845f96, 0x20, 0x8a4cc0, 0xc00009ad20, 0xc0000fe070, 0x8a9160, 0xc0000ca020, 0x7c3fa0, ...)
        /users/mick/.go/pkg/mod/github.com/yitsushi/go-misskey@v1.0.0/client.go:64 +0x82
github.com/yitsushi/go-misskey.(*Client).requestHandler(0xc0001117f0, 0x8a9160, 0xc0000ca020, 0x7c3fa0, 0xc0001fc000, 0x29f01, 0xc0000ca020)
        /users/mick/.go/pkg/mod/github.com/yitsushi/go-misskey@v1.0.0/services.go:21 +0x114
github.com/yitsushi/go-misskey/services/drive/files.(*Service).Create(0xc000111770, 0x83d9a7, 0xa, 0xc00056c3c0, 0x18, 0x0, 0xc000600000, 0x29ffa, 0x30000, 0x0, ...)
        /users/mick/.go/pkg/mod/github.com/yitsushi/go-misskey@v1.0.0/services/drive/files/create.go:25 +0x137
github.com/yitsushi/go-misskey/services/drive/files.(*Service).CreateFromURL(0xc000111770, 0xc000111828, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /users/mick/.go/pkg/mod/github.com/yitsushi/go-misskey@v1.0.0/services/drive/files/create_from_url.go:31 +0x17e
main.main()
        /users/mick/testbot/main.go:169 +0x3a5

📌 Additional context n/a

yitsushi commented 3 years ago

Fixed with #83 Changes can be used under the new tag/version: v1.0.1

yitsushi commented 3 years ago

Tested the changes locally on my own instance (slippy.xyz), if it does not work on your side, please reopen/comment this issue.