twikoojs / twikoo-cloudflare

9 stars 11 forks source link

Broken function of IM message and image upload #5

Closed flashlab closed 3 months ago

flashlab commented 3 months ago

Here are two limitations not mentioned in the document:

  1. The image uploading feature seems not working. I recieved KN.writeFileSync is not a function error in the log. So maybe local file system is not supported in cf worker.
  2. The IM notification function also has problem. Here is the log when I properly setup telegram options.
    {
      "message": [
        "[PUSHOO] Got error:",
        "r is not a function"
      ],
      "level": "error",
      "timestamp": 1718336107667
    },
    {
      "message": [
        "6/14/2024, 3:35:07 AM Twikoo:",
        "即时消息通知结果:",
        {
          "error": {}
        }
      ],
      "level": "info",
      "timestamp": 1718336107667
    }

    I'm not sure if it's a bug or another limitation. If possible, i'd like IM notification works in cf, Thank you guys.

Tao-VanJS commented 3 months ago

The image uploading feature seems not working. I recieved KN.writeFileSync is not a function error in the log. So maybe local file system is not supported in cf worker.

I updated the README.md file to mention it in the "Known limitations" section

The IM notification function also has problem. Here is the log when I properly setup telegram options.

For this part, I'm not sure. I think it's likely that pushoo is not compatible with Cloudflare workers. Could you let me know how did you set up the config so that I can reproduce the error to see if it's a bug or limitation?

flashlab commented 3 months ago

Could you let me know how did you set up the config so that I can reproduce the error to see if it's a bug or limitation?

Firstly, I displaced SendGrid patch to aliyun DirectMail becuase the former one is not registrable in China. https://github.com/flashlab/twikoo-cloudflare/commit/3548f6de0da777d0ab4655593c2eed4d64691bca Then I setup twikoo in front ui, modified fields includes SITE_NAME, SITE_URL, BLOGGER_NICK, BLOGGER_EMAIL, COMMENT_PLACEHOLDER, HIDE_ADMIN_CRYPT, SHOW_IMAGE, IMAGE_CDN, IMAGE_CDN_TOKEN, PUSHOO_CHANNEL[telegram], PUSHOO_TOKEN[nnn:xxxx#nnn], SENDER_EMAIL, SENDER_NAME, SMTP_SERVICE, SMTP_USER, SMTP_PASS

Then, I posted under one of the article with email other than admin's, no notification were happened and recieved error log above in cf web panel. And I'm sure my telegram token is working.

Tao-VanJS commented 3 months ago

I displaced SendGrid patch to aliyun DirectMail

Does the Aliyun DirectMail integration work?

I don't have a telegram account thus I can't test telegram integration on my end. I dug the source code a little bit, and found the error was from this line:

https://github.com/imaegoo/pushoo/blob/a0b3c86eed125846ff3c22369909ff5deffde3fa/src/index.ts#L530

You can patch the code there to get more information such as stack trace.

Also the code deployed to Cloudflare is minified thus the error message might not be that readable. You might consider to reproduce the problem locally via npx wrangler dev.

ChaiByte commented 3 months ago

I think it's likely that pushoo is not compatible with Cloudflare workers.

Yes, Pushoo.js depends on axio that needs NodeJS runtime.

See Runtime APIs for more details.

Tao-VanJS commented 3 months ago

Thanks @ChaiByte for the information!

I updated the "Known limitations" section of README to mention the limitation.

flashlab commented 3 months ago

I test with wecom api, and recived this error log:

{
      "message": [
        "获取企业微信 access token 失败,请检查 token",
        "TypeError: r is not a function"
      ],
      "level": "error",
      "timestamp": 1718344724049
    },
    {
      "message": [
        "[PUSHOO] Send to <wecom> result:",
        {}
      ],
      "level": "debug",
      "timestamp": 1718344724049
    }

So @ChaiByte explained the issue, If I want to enable IM on cf worker, maybe another patch is needed. If pushoo can use fetch instead of axio, maybe the problem will gone.

Does the Aliyun DirectMail integration work?

@Tao-VanJS original mail service donot have aliyun DirectMail, I patched it from scratch.

ChaiByte commented 3 months ago

If I want to enable IM on cf worker, maybe another patch is needed.

Yes, you can replace all axios API with Cloudflare Workers' Fetch API and test whether it works or not. A project named like pushoo-cf-worker to make pushoo.js totally work with Cloudflare workers is possible.