alvistar / immich-albums

Create immich albums from folder structure
MIT License
38 stars 7 forks source link

Exception when calling create_album: (404) #19

Open dmiljk opened 5 days ago

dmiljk commented 5 days ago

Hi,

I would appreciate if someone one push me in the right direction in order to figure out what I'm doing wrong. I've got the latest version of immich-albums, as well as versinon 1.106.4 of Immich server. I'm calling immich-albums with the command:

im --api-key xxxxxxxxxxxxxx --api-host http://192.168.115.2:2283/api --original-path "/mnt/qnap/Media/Markove fotografije" --replace-path "/external/Markove fotografije" .

I have masked the api-key above, obviously, but I'm using the api-key which I had previously generated on Immich server. The result I get is:

` Album Markove fotografije does not exist searching for: /external/Markove fotografije/.album not found: /external/Markove fotografije/.album Creating album Markove fotografije

Exception when calling create_album: (404) Reason: Not Found HTTP response headers: HTTPHeaderDict({'Server': 'openresty', 'Date': 'Thu, 27 Jun 2024 15:22:05 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '100', 'Connection': 'keep-alive', 'X-Powered-By': 'Express', 'x-immich-cid': 'rpt16pdn', 'ETag': '"64-uk9GwFOANWL25jGacOrQW0j712c"'}) HTTP response body: {"message":"Cannot POST /api/album","error":"Not Found","statusCode":404,"correlationId":"rpt16pdn"} `

The original-path is the path on file system which contains subfolders with the photos, and the replace-path is the volume as seen from inside the Immich server docker.

What am I missing?!

messyalex commented 2 days ago

It seems the API scheme of Immich has changed. According to the API docs the endpoint URL for album creation is now /albums not /album.

If I understood correctly, the repo's (alvistar/immich-albums) script uses the API scheme from this file /immich-albums/blob/main/immich-openapi-specs.json.

According to the Immich docs, the current version (applicable to your server) could be obtained from the Immich instance itself. I don't really know how, unfortunately.

immich-openapi-specs.json file, which is autogenerated by the server when running in development mode

It would be nice if README of this repo explained how to get the up-to-date file. Even better, if Immich docs did.

If you wanted to try it now (before the repo gets updated), here's what I did.

More elegant, unsuccessful, method

Since I don't know how to get it from the running Immich instance, I edited the immich-openapi-specs.json file manually (/album to /albums).

I tried to recreate the, updated, scheme. I worked inside a Docker Hub's python:latest container.

apt update
apt install npm default-jre # openapi-generator-cli seems to need the Java engine
npm install @openapitools/openapi-generator-cli -g

then inside the repo directory (following the command posted in this repo's README)

openapi-generator-cli generate -g python -o generated/openapi_client -i immich-openapi-specs.json -p packageVersion=1.105.1

and finally

poetry lock --no-update
poetry install # haven't issued this before regenerating the schema
poetry shell # haven't issued this before regenerating the schema

All the above commands exited successfully. but unfortunately the script (im.py) still used the old (/album) endpoint. I have insufficient knowledge about the tools the script uses so I don't know what I've missed.

Dirty hack, but worked

I manually edited the /album references to /albums by running:

sed 's/\/album/\/albums/g' -i generated/openapi_client/openapi_client/api/album_api.py

After this, running the repo's script created the albums from folders seemingly fine. Yet, I got pydantic warnings from Python.

For me it was enough to prove that creating albums from directories is feasible (using this repo's script). That's good enough for me during testing. I'll patiently wait for more knowledgeable people to update the repo (and hopefully write down the steps needed to update API scheme it uses).