Kovah / LinkAce

LinkAce is a self-hosted archive to collect links of your favorite websites.
https://www.linkace.org
GNU General Public License v3.0
2.5k stars 159 forks source link

Can't add URL via API with a list by ID #774

Closed m0nhawk closed 2 months ago

m0nhawk commented 3 months ago

Bug Description

The Array of integers doesn't work for /api/v1/links.

How to reproduce

  1. Create list with id 1 (on new instance).
  2. Submit JSON via API.
    {
    "url": "https://duckduckgo.com",
    "lists": [
    1
    ],
    "is_private": true
    }
  3. See that the URL doesn't have list.

String or list of strings works, only list of integers doesn't.

Expected behavior

URL has a list.

Logs

No response

Screenshots

No response

LinkAce version

v1.14.1

Setup Method

Docker

Operating System

Linux (Ubuntu, CentOS,...)

Client details

No response

Kovah commented 2 months ago

I will check this again after upgrading the demo to version 1.14.1, but it's working with version 1.14.0.

curl --request POST \
  --url https://demo.linkace.org/api/v1/links \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer s9anum7ODLsxbMQCr4WnYSahCEZViFEB' \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "https://duckduckgo.com",
    "lists": [
      1
    ],
    "is_private": true
  }'

See https://demo.linkace.org/lists/1 then.

Kovah commented 2 months ago

Tested this with the latest version, looks fine. Could you please retry this with your LinkAce?

m0nhawk commented 2 months ago

That's interesting...

I checked the demo, it works there.

After that I tried both simple and advanced Docker setup, with both 1.14.0 and 1.14.1 - and it didn't work for me.

I narrowed it down to this line so far:

https://github.com/Kovah/LinkAce/blob/ccd3f4411afb51c7e1556afb7ce4fbf722082f75/app/Repositories/LinkRepository.php#L208

If I replace it with $newEntry = LinkList::find($entry); - it works, but obviously it won't work for tags now.

I don't know Laravel, so can't really understand how it can work in you Demo deployment vs clean Docker setup (I have deployed separate deployment for testing).

m0nhawk commented 2 months ago

I narrowed it down further:

If there is no tag with the same id as a list - it will fail to add a list.

For example, if list has id 1 and there is a tag with id 1 - it will succeed, but if I remove the tag - it will stop working (adding correct list).

m0nhawk commented 2 months ago

I can reproduce it on demo instance.

I have removed tag with id 3 (maps) and now it fails to add the correct list.

Instead it shows this for this link:

Screenshot from 2024-05-02 03-48-48

Kovah commented 2 months ago

Thanks for the find! Indeed the code is simply incorrect. I fixed it and will have a look at other issues. If there's nothing else, a release goes out today.

m0nhawk commented 2 months ago

Thank you for fix and release. :+1: