-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathdecoder.js
35 lines (31 loc) · 1.24 KB
/
decoder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {getOriginalJs} from '../libs/drpyS.js';
import {readFileSync, existsSync} from 'fs';
import path from "path";
// 仅仅支持json post 如: {"code":"xxx"}
export default (fastify, options, done) => {
// 注册 POST 路由
fastify.post('/decoder', async (request, reply) => {
const {auth_code, code} = request.body;
if (!code || !auth_code) {
return reply.status(400).send({error: 'Missing required parameters: code and auth_code'});
}
const authFilePath = path.join(options.rootDir, '.nomedia');
// 检查文件是否存在
if (!existsSync(authFilePath)) {
return reply.status(404).send({error: '.nomedia file not found'});
}
const local_auto_code = readFileSync(authFilePath, 'utf-8').trim();
console.log('local_auto_code:',local_auto_code);
console.log('auth_code:',auth_code);
if (auth_code !== local_auto_code) {
return reply.status(200).send({error: 'your auth_code is not correct'});
}
try {
let result = getOriginalJs(code);
reply.send({success: true, result});
} catch (error) {
reply.status(500).send({error: error.message});
}
});
done();
};