From a3120a7398dc490b5dbed3bdfe4231fc31b868c2 Mon Sep 17 00:00:00 2001 From: hect0x7 <93357912+hect0x7@users.noreply.github.com> Date: Sun, 29 Oct 2023 21:37:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=82=AE=E4=BB=B6=E7=9B=B8?= =?UTF-8?q?=E5=85=B3secrets=EF=BC=8C=E4=BC=98=E5=8C=96Actions=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/download.yml | 10 ++++++++++ .github/workflows/download_dispatch.yml | 11 ++++++++++- assets/option/option_workflow_download.yml | 20 +++++++++++++++++--- src/jmcomic/jm_plugin.py | 12 +++++++++--- src/jmcomic/jm_toolkit.py | 2 +- usage/workflow_download.py | 14 -------------- 6 files changed, 47 insertions(+), 22 deletions(-) diff --git a/.github/workflows/download.yml b/.github/workflows/download.yml index 704e3337..5abd7b38 100644 --- a/.github/workflows/download.yml +++ b/.github/workflows/download.yml @@ -12,8 +12,18 @@ jobs: crawler: runs-on: ubuntu-latest env: + # 登录相关secrets JM_USERNAME: ${{ secrets.JM_USERNAME }} JM_PASSWORD: ${{ secrets.JM_PASSWORD }} + + # 邮件相关secrets + EMAIL_FROM: ${{ secrets.EMAIL_FROM }} + EMAIL_TO: ${{ secrets.EMAIL_TO }} + EMAIL_PASS: ${{ secrets.EMAIL_PASS }} + EMAIL_TITLE: ${{ secrets.EMAIL_TITLE }} + EMAIL_CONTENT: ${{ secrets.EMAIL_CONTENT }} + + # 固定值 JM_DOWNLOAD_DIR: /home/runner/work/jmcomic/download/ ZIP_NAME: '本子.tar.gz' UPLOAD_NAME: '下载完成的本子' diff --git a/.github/workflows/download_dispatch.yml b/.github/workflows/download_dispatch.yml index 1277af34..9e37c01b 100644 --- a/.github/workflows/download_dispatch.yml +++ b/.github/workflows/download_dispatch.yml @@ -68,9 +68,18 @@ jobs: ZIP_NAME: ${{ github.event.inputs.ZIP_NAME }} UPLOAD_NAME: ${{ github.event.inputs.UPLOAD_NAME }} IMAGE_SUFFIX: ${{ github.event.inputs.IMAGE_SUFFIX }} - # secrets + + # 登录相关secrets JM_USERNAME: ${{ secrets.JM_USERNAME }} JM_PASSWORD: ${{ secrets.JM_PASSWORD }} + + # 邮件相关secrets + EMAIL_FROM: ${{ secrets.EMAIL_FROM }} + EMAIL_TO: ${{ secrets.EMAIL_TO }} + EMAIL_PASS: ${{ secrets.EMAIL_PASS }} + EMAIL_TITLE: ${{ secrets.EMAIL_TITLE }} + EMAIL_CONTENT: ${{ secrets.EMAIL_CONTENT }} + # 固定值 JM_DOWNLOAD_DIR: /home/runner/work/jmcomic/download/ diff --git a/assets/option/option_workflow_download.yml b/assets/option/option_workflow_download.yml index 4bdbc023..c91d89bd 100644 --- a/assets/option/option_workflow_download.yml +++ b/assets/option/option_workflow_download.yml @@ -5,7 +5,7 @@ dir_rule: client: domain: - html: [jmcomic1.me, jmcomic.me] + html: [ jmcomic1.me, jmcomic.me ] # 插件配置 plugins: @@ -15,7 +15,21 @@ plugins: interval: 0.5 # 间隔时间 enable_warning: false # 不告警 - - plugin: client_proxy + - plugin: client_proxy # 提高移动端的请求效率的插件 kwargs: proxy_client_key: cl_proxy_future - whitelist: [ api, ] \ No newline at end of file + whitelist: [ api, ] + + - plugin: login # 登录插件 + kwargs: + username: ${JM_USERNAME} + password: ${JM_PASSWORD} + + after_album: # 下载完成以后 + - plugin: send_qq_email # 发送邮件,如果未配置下面的前3个环境变量则不会发送。 + kwargs: + msg_from: ${EMAIL_FROM} + msg_to: ${EMAIL_TO} + password: ${EMAIL_PASS} + title: ${EMAIL_TITLE} + content: ${EMAIL_CONTENT} \ No newline at end of file diff --git a/src/jmcomic/jm_plugin.py b/src/jmcomic/jm_plugin.py index 5e3cdad9..dd192504 100644 --- a/src/jmcomic/jm_plugin.py +++ b/src/jmcomic/jm_plugin.py @@ -40,9 +40,12 @@ class JmLoginPlugin(JmOptionPlugin): """ plugin_key = 'login' - def invoke(self, username, password) -> None: - assert isinstance(username, str), '用户名必须是str' - assert isinstance(password, str), '密码必须是str' + def invoke(self, + username: str, + password: str, + ) -> None: + if not (username and password): + return client = self.option.new_jm_client() client.login(username, password) @@ -400,6 +403,9 @@ def invoke(self, album=None, downloader=None, ) -> None: + if not (msg_from and msg_to and password): + self.debug('发送邮件的相关参数为空,不处理') + return from common import EmailConfig econfig = EmailConfig(msg_from, msg_to, password) epostman = econfig.create_email_postman() diff --git a/src/jmcomic/jm_toolkit.py b/src/jmcomic/jm_toolkit.py index 5128669a..a6e6321a 100644 --- a/src/jmcomic/jm_toolkit.py +++ b/src/jmcomic/jm_toolkit.py @@ -203,7 +203,7 @@ def match_os_env(cls, match: Match) -> str: name = match[1] value = os.getenv(name, None) assert value is not None, f"未配置环境变量: {name}" - return os.path.abspath(value) + return value dsl_replacer = DSLReplacer() diff --git a/usage/workflow_download.py b/usage/workflow_download.py index 044aec1f..30c56043 100644 --- a/usage/workflow_download.py +++ b/usage/workflow_download.py @@ -70,20 +70,6 @@ def cover_option_config(option: JmOption): option.download.image.suffix = fix_suffix(suffix) -def login_if_configured(option): - # 检查环境变量中是否有禁漫的用户名和密码,如果有则登录 - # 禁漫的大部分本子,下载是不需要登录的,少部分敏感题材需要登录 - # 如果你希望以登录状态下载本子,你需要自己配置一下GitHub Actions的 `secrets` - # 配置的方式很简单,网页上点一点就可以了 - # 具体做法请去看官方教程:https://docs.github.com/en/actions/security-guides/encrypted-secrets - # 萌新注意!!!如果你想 `开源` 你的禁漫帐号,你也可以直接把账号密码写到下面的代码😅 - username = get_env('JM_USERNAME', None) - password = get_env('JM_PASSWORD', None) - if username is not None and password is not None: - # 调用login插件 - JmLoginPlugin(option).invoke(username, password) - - def log_before_raise(): jm_download_dir = get_env('JM_DOWNLOAD_DIR', workspace()) mkdir_if_not_exists(jm_download_dir)