decoder.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {getOriginalJs, jsDecoder} from '../libs/drpyS.js';
  2. import {readFileSync, writeFileSync, existsSync} from 'fs';
  3. import path from "path";
  4. // 检测命令行参数
  5. const args = process.argv.slice(2);
  6. if (args.length > 0) {
  7. // 如果有参数,读取文件并打印内容
  8. const filePath = args[0]; // 第一个参数作为文件路径
  9. let content = readFileSync(filePath, 'utf8');
  10. console.log(`文件 ${filePath} 的内容长度为:${content.length}`);
  11. writeFileSync(filePath.replace(/\.gz$/, '.ugz'), jsDecoder.ungzip(content), 'utf-8');
  12. }
  13. // 仅仅支持json post 如: {"code":"xxx"}
  14. export default (fastify, options, done) => {
  15. // 注册 POST 路由
  16. fastify.post('/decoder', async (request, reply) => {
  17. const {auth_code, code} = request.body;
  18. if (!code || !auth_code) {
  19. return reply.status(400).send({error: 'Missing required parameters: code and auth_code'});
  20. }
  21. // 检查文本大小
  22. const textSize = Buffer.byteLength(code, 'utf8'); // 获取 UTF-8 编码的字节大小
  23. if (textSize > options.MAX_TEXT_SIZE) {
  24. return reply
  25. .status(400)
  26. .send({error: `Text content exceeds the maximum size of ${options.MAX_TEXT_SIZE / 1024} KB`});
  27. }
  28. const authFilePath = path.join(options.rootDir, 'public/nomedia.txt');
  29. // 检查文件是否存在
  30. if (!existsSync(authFilePath)) {
  31. return reply.status(404).send({error: 'public/nomedia.txt file not found'});
  32. }
  33. try {
  34. const local_auto_code = readFileSync(authFilePath, 'utf-8').trim();
  35. const auth_codes = jsDecoder.aes_decrypt(local_auto_code).trim().split('\n');
  36. // console.log('auth_codes:',auth_codes);
  37. // console.log('auth_code:', auth_code);
  38. if (!auth_codes.includes(auth_code)) {
  39. return reply.status(200).send({error: 'your auth_code is not correct'});
  40. }
  41. } catch (error) {
  42. return reply.status(200).send({error: error.message});
  43. }
  44. try {
  45. let result = getOriginalJs(code);
  46. reply.send({success: true, result});
  47. } catch (error) {
  48. reply.status(500).send({error: error.message});
  49. }
  50. });
  51. done();
  52. };