Skip to content

Commit

Permalink
refactor: 使用标准库 node:crypto 中的 md5
Browse files Browse the repository at this point in the history
  • Loading branch information
chesha1 committed Jun 18, 2024
1 parent e31308c commit c0df5b6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"wrangler": "^3.60.0"
},
"dependencies": {
"axios": "^1.7.2",
"crypto-js": "^4.2.0"
"axios": "^1.7.2"
}
}
5 changes: 3 additions & 2 deletions src/index-aws.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// aws lambda entrypoint
import MD5 from 'crypto-js/md5.js';

import crypto from 'node:crypto';
import { loginPayload, DailyTask } from './service.js';

export async function handler(event: Event) {
const userPayload: loginPayload = {
account_name: process.env.ACCOUNT_NAME as string,
passwd: MD5(process.env.PASSWORD as string).toString(),
passwd: crypto.createHash('md5').update(process.env.PASSWORD as string).digest('hex'),
source: 'phone',
};

Expand Down
4 changes: 2 additions & 2 deletions src/index-cf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Cloudflare Worker Entrypoint

import MD5 from 'crypto-js/md5';
import crypto from 'node:crypto';
import { loginPayload, DailyTask } from './service';

export interface Env {
Expand All @@ -12,7 +12,7 @@ export default {
async scheduled(event: Event, env: Env, ctx) {
const userPayload: loginPayload = {
account_name: env.ACCOUNT_NAME,
passwd: MD5(env.PASSWORD).toString(),
passwd: crypto.createHash('md5').update(env.PASSWORD).digest('hex'),
source: 'phone',
};

Expand Down
5 changes: 3 additions & 2 deletions src/index-huawei-cloud.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// huawei cloud FunctionGraph entrypoint
// use tsc --module CommonJS to compile to CommonJS
import MD5 from 'crypto-js/md5.js';

import crypto from 'node:crypto';
import { loginPayload, DailyTask } from './service.js';
import { Context } from 'vm';

export async function handler(event: Event, context: Context) {
const userPayload: loginPayload = {
account_name: context.getUserData('ACCOUNT_NAME') as string,
passwd: MD5(context.getUserData('PASSWORD') as string).toString(),
passwd: crypto.createHash('md5').update(context.getUserData('PASSWORD') as string).digest('hex'),
source: 'phone',
};

Expand Down
1 change: 1 addition & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "gf2-daily-helper"
main = "./src/index-cf.ts"
compatibility_date = "2024-06-08"
compatibility_flags = ["nodejs_compat"]

[triggers]
crons = ["5 21 * * *"]

0 comments on commit c0df5b6

Please sign in to comment.