rr- / szurubooru

Image board engine, Danbooru-style.
GNU General Public License v3.0
704 stars 178 forks source link

Deleted thumbnail data #467

Closed Anbosuki closed 2 years ago

Anbosuki commented 2 years ago

Hello, I have a problem. I have deleted the generated-thumbnail folder in my data folder. I didn't realize that the thumbnail names are stored in the database, which, come to think of it, only makes sense. Is there any way to reset the thumbnails in the database? Sorry for the stupid problem -_-

TiredSysOp commented 2 years ago

I don't know if the admin script can help, the command was created to fix filenames after a change in the server secret. I do not know how to regenerate thumbs or if the server does this automatically. But might sort out the database end?

https://github.com/rr-/szurubooru/blob/master/doc/INSTALL.md#additional-features

446 "similar" issue

szuru-admin --reset-filenames

I'm certain the other regulars and maintainers will have a better idea than me

Anbosuki commented 2 years ago

I also tried the script, but it did not work. After looking at the database structure and the file names, I found out that the thumbnails are generated during the upload. After a little trial and error, I wrote a script that regenerates the thumbnails.

I think the issue can thus be closed if no one else wants to add anything.

But anyway thanks for the answer ^^

Also, keep up the good work, I think your project is in some respects even better than the other well-known Boorus and is in no way inferior to them :)

noirscape commented 2 years ago

I wrote a script that regenerates the thumbnails.

Could you turn this script into an admin command and make it a pull request? I'm sure it'd help a lot of other people.

Anbosuki commented 2 years ago

Sure, I just need to convert the bash script to a python script. I will do it this weekend.

Manni1000 commented 2 years ago

hi how did u look into the database structure and where can i find the file for that?

Anbosuki commented 2 years ago

@Manni1000 Hi, you need to connect to the sql docker container. From within there you can connect to the database using psql commands. After connected to the db change the user to the user defined in the .env file. After that just check out the psql documentation. Short tip: when executing a sql query put an ; at it's end, otherweise it won't execute.

neobooru commented 2 years ago

For what it's worth, this is the script that I used a while ago to regenerate my thumbnails. Not sure whether I wrote it myself or got it from somewhere. When placed in the server directory it seems to work fine.

When using docker I suspect that you'd either have to attach to a running instance and create it in there, or add it to your server folder and then rebuild the server image.

#!/usr/bin/env python3

from szurubooru import db, model, errors
from szurubooru.func import files, images
from szurubooru.func import posts

def main():
    post_list = (db.session
        .query(model.Post)
        .all())

    for post in post_list:
        print('Generating tumbnail for post %d ...' % post.post_id, end='\r')

        try:
            posts.generate_post_thumbnail(post)
        except Exception:
            pass

if __name__ == '__main__':
    main()
Anbosuki commented 2 years ago

I added the command to the admin script as well. But since I never used docker-compose before, I couldn't figure out how to run the local command instead of the command from the latest version of the docker image. Would be nice if someone could give me a little advise.

neobooru commented 2 years ago

The easiest (but technically speaking not the best) way to do this would be this:

# 1. Start the szurubooru docker-compose instance by running `docker-compose up -d` in the project root.
docker-compose up -d

# 2. Find the container id of the server instance using `docker ps`
docker ps
# This should give you something like this
#> CONTAINER ID   IMAGE                      COMMAND                  CREATED         STATUS         PORTS                    NAMES
#> 6f97fe086611   szurubooru/client:latest   "/docker-entrypoint.…"   7 minutes ago   Up 7 minutes   0.0.0.0:8080->80/tcp     szurubooru-client-1
#> 7825e90d62ea   szurubooru/server:latest   "/opt/app/docker-sta…"   7 minutes ago   Up 7 minutes   6666/tcp                 szurubooru-server-1
#> 065ae59bac2a   postgres:11-alpine         "docker-entrypoint.s…"   7 minutes ago   Up 7 minutes   0.0.0.0:5432->5432/tcp   szurubooru-sql-1
#
# Copy the container id for the szurubooru/server:latest image, in this case it is 7825e90d62ea

# 3. Now connect to the server container and start a shell, make sure to replace the container id (7825e90d62ea) with your own.
docker exec -it 7825e90d62ea /bin/sh
# You should automatically be in the correct directory (/opt/app)
# This can be verified by running `pwd`, and if needed you can use `cd /opt/app` to go to the correct directory.

# 4. Download my generate-thumbs script
wget https://gist.githubusercontent.com/neobooru/d540ac861ea1deae6065f0fdf26c1421/raw/4df1b56046392000f531e9110b5d29a4b4ff2b3b/generate-thumbs.py

# 5. Run generate-thumb.py
python3 generate-thumbs.py

# And that should be it.
sgsunder commented 2 years ago

Added this scriptlet to the szuru-admin script.

This can be run with the following command: docker-compose run server ./szuru-admin --regenerate-thumbnails