Binaryify / NeteaseCloudMusicApi

网易云音乐 Node.js API service
https://gitlab.com/Binaryify/neteasecloudmusicapi
30.29k stars 15.78k forks source link

compatibility with Deno #1801

Closed groovejames closed 1 year ago

groovejames commented 1 year ago

This PR adds compatibility with Deno. It allows at least the API to be imported into a Deno application (not the server part based on express, though).

For the Deno compatibility I had to change the following things:

  1. In crypto.js: replace crypto.publicEncrypt(..., RSA_NO_PADDING) which alas is not available in Deno. I replaced it with a custom RSA implementation which does the same.
  2. The RSA publicKey in crypto.js changed to have a line-length of 64 chars. Deno (or rather, it's Rust-based backend) doesn't like long-lined public keys, which is not a standard anyways.
  3. I extract the modulus and exponent from the RSA public key using crypto.createPublicKey(key).export({ format: 'jwk' }). This function is available in Node.js 16.x or higher. Therefore the requirements for this PR rise from Node.js 12.x to 16.x. I hope this is ok. If you don't agree I can find another alternative.
  4. I added a new dependency bigint-mod-arith for the RSA modPow() function. This is pretty uncritical.

I carefully checked that the changed crypto functions produce exactly the same binary data as before.

I tested with Node.js 16.x, 20.x and Deno. Everything seems to work as usual, so if you agree I think this can be integrated into the master branch. :)

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
netease-cloud-music-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 14, 2023 5:16pm
groovejames commented 1 year ago

Nevermind, I'll close this. I just realized that there's a lot more to do to achieve Deno compatibility. I'll might come back later.