From 7d39885ce389665760cadbf54d3ce7edf36c4754 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Mon, 19 Aug 2024 08:51:15 +0700 Subject: [PATCH] =?UTF-8?q?booru:=20save=20to=20=F0=9F=8C=B6=EF=B8=8F=20fo?= =?UTF-8?q?lder=20if=20nsfw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/ags/modules/sideleft/apis/booru.js | 11 +++++------ .config/ags/services/booru.js | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.config/ags/modules/sideleft/apis/booru.js b/.config/ags/modules/sideleft/apis/booru.js index 4cfc80372..7016cd4ab 100644 --- a/.config/ags/modules/sideleft/apis/booru.js +++ b/.config/ags/modules/sideleft/apis/booru.js @@ -187,7 +187,6 @@ const BooruPage = (taglist, serviceName = 'Booru') => { // Show // const downloadCommand = `wget -O '${imagePath}' '${data.preview_url}'`; const downloadCommand = `curl -L -o '${imagePath}' '${data.preview_url}'`; - // console.log(downloadCommand) if (!force && fileExists(imagePath)) showImage(); else Utils.timeout(delay, () => Utils.execAsync(['bash', '-c', downloadCommand]) .then(showImage) @@ -222,13 +221,13 @@ const BooruPage = (taglist, serviceName = 'Booru') => { name: 'Save image', icon: 'save', action: (self) => { - const currentTags = BooruService.queries.at(-1).realTagList.filter(tag => !tag.includes('rating:')); + const currentTags = BooruService.queries.at(-1).realTagList.filter(tag => !tag.includes('rating:')); const tagDirectory = currentTags.join('_'); - let fileExtension = data.file_ext || 'jpg'; - const saveCommand = `mkdir -p $(xdg-user-dir PICTURES)/homework/${tagDirectory} && curl -L -o $(xdg-user-dir PICTURES)/homework/${tagDirectory}/${data.md5}.${fileExtension} '${data.file_url}'`; + let fileExtension = data.file_ext || 'jpg'; + const saveCommand = `mkdir -p $(xdg-user-dir PICTURES)/homework/${data.is_nsfw ? '🌶️/' : ''}${tagDirectory} && curl -L -o $(xdg-user-dir PICTURES)/homework/${data.is_nsfw ? '🌶️/' : ''}${tagDirectory}/${data.md5}.${fileExtension} '${data.file_url}'`; execAsync(['bash', '-c', saveCommand]) - .then(() => self.label = 'done') - .catch(print); + .then(() => self.label = 'done') + .catch(print); }, }), ] diff --git a/.config/ags/services/booru.js b/.config/ags/services/booru.js index 35125b131..e620d8ce8 100644 --- a/.config/ags/services/booru.js +++ b/.config/ags/services/booru.js @@ -129,6 +129,8 @@ class BooruService extends Service { aspect_ratio: obj.width / obj.height, id: obj.id, tags: obj.tags, + rating: obj.rating, + is_nsfw: (obj.rating != 's'), md5: obj.md5, preview_url: obj.preview_url, preview_width: obj.preview_width,