From d6b18199a09a9a39975d54c533b1c95ca72c9f7d Mon Sep 17 00:00:00 2001 From: txperl Date: Sat, 31 Dec 2022 20:34:51 +0800 Subject: [PATCH] fix(app): modify details and documents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 可能的程序关闭后线程未退出问题 - 修复 可能的登录状态持久化问题 - 完善 README 文档 - 完善 GitHub Actions 步骤 - 微调 前端样式 - 移除 Rate Limit 和 Cache 拓展 --- .github/workflows/pkg.yml | 29 +++--- README.md | 10 +- README_EN.md | 10 +- README_JA.md | 8 +- app/config/switch.yml | 20 ---- app/lib/core/biu.py | 10 +- app/lib/ins/cache.py | 98 ------------------- app/pre/rate_limit.py | 36 ------- usr/static/multiverse/assets/css/n.css | 2 +- .../multiverse/assets/js/biu/actions.js | 36 +++---- usr/templates/multiverse/index.html | 7 +- 11 files changed, 43 insertions(+), 223 deletions(-) delete mode 100644 app/lib/ins/cache.py delete mode 100644 app/pre/rate_limit.py diff --git a/.github/workflows/pkg.yml b/.github/workflows/pkg.yml index cce1797..f0e4872 100644 --- a/.github/workflows/pkg.yml +++ b/.github/workflows/pkg.yml @@ -29,23 +29,22 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - # os: [windows-2019, windows-2019, macos-10.15, ubuntu-18.04] include: - - os: windows-2019 + - os: windows-2022 version: win_x64 pythonArch: 'x64' - - os: windows-2019 + - os: windows-2022 version: win_x86 pythonArch: 'x86' - - os: macos-10.15 + - os: macos-11 version: mac pythonArch: 'x64' - - os: ubuntu-18.04 + - os: ubuntu-20.04 version: ubuntu_x64 pythonArch: 'x64' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Classify files, prepare to be packaged run: | @@ -59,10 +58,10 @@ jobs: cp ./LICENSE ./.pkg/public/ cp ./README.md ./.pkg/public/ - - name: Setup Python 3.7 - uses: actions/setup-python@v2.2.2 + - name: Setup Python + uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: 3.8 architecture: ${{ matrix.pythonArch }} - name: Install Requirements @@ -76,21 +75,21 @@ jobs: python ./py-pkger.py auto - name: Compress to ZIP (win) - if: ${{ matrix.os == 'windows-2019' }} + if: ${{ matrix.version == 'win_x64' || matrix.version == 'win_x86' }} run: | cd ./.pkg/dist/ mv ./main.exe ./PixivBiu.exe Compress-Archive * ../../${{ matrix.version }}.zip - - name: Compress to ZIP (mac) - if: ${{ matrix.os == 'macos-10.15' || matrix.os == 'ubuntu-18.04' }} + - name: Compress to ZIP (unix-like) + if: ${{ matrix.version == 'mac' || matrix.version == 'ubuntu_x64' }} run: | cd ./.pkg/dist/ mv ./main ./PixivBiu zip -r ../../${{ matrix.version }}.zip * - name: Upload to Artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: pixivbiuArt path: ./${{ matrix.version }}.zip @@ -99,10 +98,10 @@ jobs: needs: [build-on-platform] runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Download from Artifact - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: pixivbiuArt diff --git a/README.md b/README.md index de615d7..81c74f1 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,8 @@ PixivBiu 是一款不错的 Pixiv **辅助**工具。 * Pixiv 搜索,可免会员按收藏数、人气、日期排序 * 下载原始图片,包括插画、漫画、动图 * 多种下载模式,单、多线程模式以及 aria2 支持 -* 筛选图片的宽高、宽高比、类型、时间、标签等 * 获取用户的作品、收藏夹、关注列表、推荐等 -* 获取排行榜,包括今日、本周、本月、指定日期等 -* 收藏作品、关注等 +* 筛选图片的宽高、类型、标签等 ## 使用 @@ -21,7 +19,7 @@ PixivBiu 是一款不错的 Pixiv **辅助**工具。 * 安装依赖,执行 `pip install -r requirements.txt` + [Flask](https://github.com/pallets/flask)、[requests](https://github.com/psf/requests)、[PyYAML](https://github.com/yaml/pyyaml)、[Pillow](https://github.com/python-pillow/Pillow)、[PixivPy](https://github.com/upbit/pixivpy)、[PySocks](https://github.com/Anorov/PySocks) -* 修改 `./config.yml` 相关配置选项,具体可参考[默认配置文件](./app/config/biu_default.yml) +* 修改 `./config.yml` 相关配置项,具体可参考[默认配置文件](./app/config/biu_default.yml) * 执行 `python main.py` * 访问运行地址,默认为 `http://127.0.0.1:4001/` @@ -37,10 +35,6 @@ PixivBiu 是一款不错的 Pixiv **辅助**工具。 - [Docker_Buildx_PixivBiu](https://github.com/zzcabc/Docker_Buildx_PixivBiu) by [zzcabc](https://github.com/zzcabc) -## 文档 - -目前已有**使用、API**类文档,如有需要请访问[这里](https://biu.tls.moe/)。 - ## 贡献维护 如果你想参与此项目的开发,欢迎查看[开发文档](https://biu.tls.moe/#/develop/quickin)。 diff --git a/README_EN.md b/README_EN.md index 35f3484..c07eb63 100644 --- a/README_EN.md +++ b/README_EN.md @@ -10,10 +10,8 @@ PixivBiu is a nice Pixiv **assistant** tool. * Pixiv searching, sort by favorites, popularity and date without membership * Download original images, including illustrations, comics and motion pictures * Multiple download modes, single and multi-threaded mode and aria2 support -* Filter image width, height, scale, type, time and tags -* Get user's works, favorites, followers, recommendations -* Get rankings, including today, week, month, and specific date -* Favorite works and followers +* Get user's works, favorites, followers, recommendations and etc. +* Filter image width, height, type, tags and etc. ## Usage @@ -37,10 +35,6 @@ They can be downloaded in [GitHub Releases](https://github.com/txperl/PixivBiu/r - [Docker_Buildx_PixivBiu](https://github.com/zzcabc/Docker_Buildx_PixivBiu) by [zzcabc](https://github.com/zzcabc) -## Document - -Currently, there are only **usage and API** documents, please visit [here](https://biu.tls.moe/) if you need it. - ## Contribution If you want to participate in the development of this project, you are welcome to check [development document](https://biu.tls.moe/#/develop/quickin). diff --git a/README_JA.md b/README_JA.md index 93505af..aa5e04b 100644 --- a/README_JA.md +++ b/README_JA.md @@ -10,10 +10,8 @@ PixivBiuはPixivのための**補助的な**ツールです。 * お気に入り数(会員の除外可)順や人気順でのPixiv検索 * イラスト/漫画/うごイラを含む画像のオリジナル画質でのダウンロード * シングル/マルチスレッドや [aria2](https://github.com/aria2/aria2) などでのダウンロード -* 画像の幅、高さ、アスペクト比、タイプ、時間、ラベルなどをフィルタリングします * 指定したユーザの投稿作品/ブックマーク/フォロワー/関連するおすすめなどの取得 -* 当日/週間/月間/特定の日付別などでのランキングの取得 -* ブックマークやフォロー中のユーザなどの取得 +* 画像の幅、高さ、タイプ、ラベルなどをフィルタリングします ## 使い方 @@ -37,10 +35,6 @@ Windows 版と macOS 版が利用可能ですが、もし必要であれば自 - [Docker_Buildx_PixivBiu](https://github.com/zzcabc/Docker_Buildx_PixivBiu) by [zzcabc](https://github.com/zzcabc) -## ドキュメント - -現在,**使い方とAPI**のドキュメントのみがあります,必要に応じて[こちら](https://biu.tls.moe/)をご参照ください。 - ## 貢献 もしこのプロジェクトの開発に参加したいのであれば、お気軽に[開発ドキュメント(中文)](https://biu.tls.moe/#/develop/quickin)をご参照ください。 diff --git a/app/config/switch.yml b/app/config/switch.yml index 335afa8..346a7e0 100644 --- a/app/config/switch.yml +++ b/app/config/switch.yml @@ -1,32 +1,12 @@ # 开启或停用模块 # true 为开启,false 为停用 OnOff: - ins: - cache.py: false pre: - rate_limit.py: false - # rate limit 预处理,开启后请修改下方相关配置 verify_referrer.py: false # 简单防盗链预处理,开启后请修改下方相关配置 # 预处理安全相关 Security: - # rate limit 相关设置 - rateLimit: - maxRequests: 30 - # 一个 timeSecond 内同一 IP 允许的最大请求数 - - timeSeconds: 60 - # 时间周期,单位为秒 - - allowOrigin: - # 以下 IP 可无视上述规则 - - 127.0.0.1 - - banOrigin: - # 以下 IP 会被拒绝请求 - - null - # 防盗链相关设置 onlyReferrer: type: ban diff --git a/app/lib/core/biu.py b/app/lib/core/biu.py index 9d8b670..a9f1809 100644 --- a/app/lib/core/biu.py +++ b/app/lib/core/biu.py @@ -1,3 +1,4 @@ +import atexit import os import platform import sys @@ -14,7 +15,7 @@ @interRoot.bind("biu", "LIB_CORE") class CoreBiu(interRoot): def __init__(self): - self.ver = 206001 + self.ver = 206010 self.place = "local" self.sysPlc = platform.system() self.api_route = "direct" @@ -32,10 +33,8 @@ def __init__(self): self.STATUS = {"rate_search": {}, "rate_download": {}} self.auto() - def __del__(self): - self.pool_srh.shutdown(False) - def auto(self): + atexit.register(self.__before_exit) self.__load_config() # 加载配置项 self.__pre_check() # 运行前检测 self.proxy = self.__get_system_proxy() # 加载代理地址 @@ -48,6 +47,9 @@ def auto(self): self.__show_ready_info() # 展示初始化完成信息 return self + def __before_exit(self): + self.pool_srh.shutdown(False) + def __load_config(self): """ 加载 pixivbiu 的全局配置项。 diff --git a/app/lib/ins/cache.py b/app/lib/ins/cache.py deleted file mode 100644 index 1b20e06..0000000 --- a/app/lib/ins/cache.py +++ /dev/null @@ -1,98 +0,0 @@ -import base64 -import pickle -import threading -import time - -from altfe.interface.root import interRoot - - -@interRoot.bind("cache", "LIB_INS") -class InsCache(object): - def __init__(self): - self._check_time = 5 - self._cache = {} - self.lock = threading.Lock() - self.auto() - - def auto(self): - t = threading.Timer(0, self.__check) - t.setDaemon(True) - t.start() - print("[cache] running") - - def set(self, key: str, value, expire=600, reset=True): - self.lock.acquire() - try: - assert key != "" - if key in self._cache and reset is not True: - return True - self._cache[key] = {} - if not isinstance(value, bytes): - self._cache[key]["bytes"] = 0 - value = pickle.dumps(value) - else: - self._cache[key]["bytes"] = 1 - self._cache[key]["value"] = base64.b64encode(value).decode("utf-8") - self._cache[key]["ttl"] = ( - str(999999999) if expire == 0 else str(int(time.time()) + int(expire)) - ) - self._cache[key]["visnum"] = 0 - except: - return None - finally: - self.lock.release() - return True - - def get(self, key: str, itype="value", forceIncrement=False): - try: - assert key != "" and key in self._cache - if itype == "value": - value = base64.b64decode(str(self._cache[key][itype]).encode("utf-8")) - if not self._cache[key]["bytes"]: - value = pickle.loads(value) - self._cache[key]["visnum"] += 1 - else: - value = self._cache[key][itype] - if forceIncrement: - self._cache[key]["visnum"] += 1 - return value - except: - return None - - def delete(self, key): - self.lock.acquire() - try: - if isinstance(key, dict): - for x in key: - assert x != "" and x in self._cache - self._cache.pop(x) - elif isinstance(key, str): - assert key != "" and key in self._cache - self._cache.pop(key) - else: - return False - except: - return False - finally: - self.lock.release() - return True - - def clear(self): - self.lock.acquire() - self._cache = {} - self.lock.release() - - def __check(self): - try: - tim = int(time.time()) - for key in self._cache: - try: - if tim > int(self._cache[key]["ttl"]): - self.delete(key) - except: - continue - except: - pass - t = threading.Timer(self._check_time, self.__check) - t.setDaemon(True) - t.start() diff --git a/app/pre/rate_limit.py b/app/pre/rate_limit.py deleted file mode 100644 index f910b8b..0000000 --- a/app/pre/rate_limit.py +++ /dev/null @@ -1,36 +0,0 @@ -from flask import request - -from altfe.interface.root import interRoot - - -@interRoot.bind("rateLimit", "PRE") -class pre_rate_limit(interRoot): - """ - 预处理部分,负责 rate limit 管理。 - """ - - def __init__(self): - self.conf = self.loadConfig(self.getENV("rootPathFrozen") + "app/config/switch.yml") - self.maxRequests = self.conf["Security"]["rateLimit"]["maxRequests"] - self.timeSeconds = self.conf["Security"]["rateLimit"]["timeSeconds"] - self.allowOrigin = self.conf["Security"]["rateLimit"]["allowOrigin"] - self.banOrigin = self.conf["Security"]["rateLimit"]["banOrigin"] - if self.allowOrigin is None: - self.allowOrigin = [] - if self.banOrigin is None: - self.banOrigin = [] - - def run(self, cmd): - ip = request.environ.get("HTTP_X_FORWARDED_FOR") - if request.environ.get("HTTP_X_FORWARDED_FOR") is None: - ip = request.environ["REMOTE_ADDR"] - if ip is None or ip in self.banOrigin: - return False - if ip in self.allowOrigin: - return True - visNum = self.INS.cache.get(f"__rt_{ip}", "visnum", True) - if visNum is None: - self.INS.cache.set(f"__rt_{ip}", "", expire=self.timeSeconds) - elif visNum > self.maxRequests: - return False - return True diff --git a/usr/static/multiverse/assets/css/n.css b/usr/static/multiverse/assets/css/n.css index 46bb872..4a8c9ac 100644 --- a/usr/static/multiverse/assets/css/n.css +++ b/usr/static/multiverse/assets/css/n.css @@ -207,6 +207,7 @@ .poptrox-popup .caption { position: fixed; background-image: none; + text-shadow: 0 0 15px #000; } .poptrox-popup:before { @@ -215,7 +216,6 @@ .poptrox-popup .nav-previous, .poptrox-popup .nav-next { - position: fixed; display: block !important; filter: drop-shadow(0 0 3px rgb(0, 0, 0)); } diff --git a/usr/static/multiverse/assets/js/biu/actions.js b/usr/static/multiverse/assets/js/biu/actions.js index 72f210d..a05ea11 100644 --- a/usr/static/multiverse/assets/js/biu/actions.js +++ b/usr/static/multiverse/assets/js/biu/actions.js @@ -300,36 +300,28 @@ function getOneWork(id) { }); } -function doBookmark(id, action = 'add') { - let des, de, icon, tURL; - if (action === 'add') { - tURL = "api/biu/do/mark/"; - icon = '💘'; - de = 'javascript: doBookmark(' + id + ', \'del\');'; - des = '取消收藏'; - } else { - tURL = "api/biu/do/unmark/"; - icon = '💗'; - de = 'javascript: doBookmark(' + id + ', \'add\');'; - des = '收藏'; - } +function doBookmark(wid) { + const RS = { + add: { url: "api/biu/do/mark/", icon: "💘", des: "取消收藏" }, + del: { url: "api/biu/do/unmark/", icon: "💗", des: "收藏" }, + }; + const action = $(`#marks_${wid} b hicon`).html() === "💘" ? "del" : "add"; $.ajax({ type: "GET", - url: tURL, + url: RS[action].url, data: { - 'workID': id, - 'publicity': tmpSearchSettings['pixivbiu_actionType'] === 'private' ? 'private' : 'public' + "workID": wid, + "publicity": tmpSearchSettings["pixivbiu_actionType"] === "private" ? "private" : "public" }, - success: function (rep) { + success: rep => { rep = jQuery.parseJSON(JSON.stringify(rep)); if (rep.code) { - $('#marks_' + id + ' b hicon').html(icon); - $('#marks_' + id + ' b').tooltipster('content', des); - $('#marks_' + id).attr('href', de); + $(`#marks_${wid} b hicon`).html(RS[action].icon); + $(`#marks_${wid} b`).tooltipster("content", RS[action].des); } }, - error: function (e) { - console.log(e); + error: err => { + console.log(err); } }); } diff --git a/usr/templates/multiverse/index.html b/usr/templates/multiverse/index.html index 1acfd75..7da9214 100644 --- a/usr/templates/multiverse/index.html +++ b/usr/templates/multiverse/index.html @@ -576,9 +576,9 @@

其他

// 收藏按钮 if (data[i]['is_bookmarked']) { - extra += '💘 ' + bookedNum + ''; + extra += `💘 ${bookedNum}`; } else { - extra += '💗 ' + bookedNum + ''; + extra += `💗 ${bookedNum}`; } // 下载归类用的文件夹名称 @@ -601,8 +601,7 @@

其他

extra += '' + typeName[data[i]['type']] + ''; // 图片预览内容 - var extraText = '🔍 作者插画 🔍 漫画 下载'; - + var extraText = '🔍 作者插画 🔍 漫画 ⏬ 下载'; if (data[i]['all']['meta_pages'].length > 0) { extraText = '👀 查看 ' + extraText; }