diff --git a/DBooru_web.py b/DBooru_web.py index 3bcb081..8e1693d 100755 --- a/DBooru_web.py +++ b/DBooru_web.py @@ -26,7 +26,8 @@ from dermod import input_parser as ip from dermod import mime_types as mimes from dermod import predict -from dermod.helpers import Option, Module_Options, ThumbFile +from dermod.imgloader import Loader +from dermod.helpers import Option, Module_Options, ThumbFile, DBImage try: import PIL.Image as Image @@ -280,6 +281,30 @@ def first_run(): update_line("first_run", False) +@DBooru.route("/reload/", methods=["PATCH"]) +def image_reload(imgid): + if request.method != "PATCH": + return + image_data = DBImage(db.search_by_id(*reversed(imgid.split("_")))) + print(f"Reloading {image_data.prefix + image_data.no_p_fname}") + try: + os.remove(settings_file.images_path + "/" + image_data.prefix + image_data.no_p_fname) + except: + pass + l = Loader(image_data.link, image_data.prefix + image_data.no_p_fname) + l.start() + return Response(status=200) + +@DBooru.route("/remove/", methods=["DELETE"]) +def remove_image(imgid): + image_data = DBImage(db.search_by_id(*reversed(imgid.split("_")))) + db.remove_entry(image_data.id, image_data.prefix) + try: + os.remove(settings_file.images_path + "/" + image_data.prefix + image_data.no_p_fname) + except: + pass + return Response(status=200) + @DBooru.route("/json/search") def api_search(): page = request.args.get('page', default=1, type=int) diff --git a/README.md b/README.md index 01af0ec..f7afa33 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ - [Basic search rules](#basic-search-rules) - [Special tags](#special-tags) - [Syntax](#syntax) - - [Settings_file.py](#settingsfilepy) + - [Settings_file.py](#settings_filepy) - [/settings autogeneration](#settings-autogeneration) - [Keywords](#keywords) - [Examples](#examples-1) @@ -101,6 +101,7 @@ >- markupsafe >- click >- itsdangerous +>- termcolor > >Or you can just type `pip install --user -r requirements.txt` in terminal @@ -286,6 +287,8 @@ Enter this commands if prompt starts with `Search@DB>` | "/random" | GET | | Redirects to random image | Redirect (302) to /image/\* | | "/random/**tags** | GET | | Redirects to random image tagged with **tags** | Redirect (302) to /image/\* | | "/update" | GET | | Updates DB (Same as CLI: get images) | Returns 200 code when update started successfully or 409 in case when there's already update in progress | +| "/remove/**prefix_id**" | DELETE | | Used to remove image and its DB entry | | +| "/reload/**prefix_id**" | PATCH | | Triggers image redownloading | | | "/settings" | GET | | Settings page | HTML-page | | "/settings/\