perf: 支持部署证书到网宿CDN

This commit is contained in:
xiaojunnuo
2025-07-10 23:30:33 +08:00
parent 98da4e1791
commit c3da026b33
14 changed files with 594 additions and 5 deletions
@@ -0,0 +1,23 @@
import CryptoJS from 'crypto-js';
export class CryptoUtils {
private constructor() {}
/**
* hmac+sha256+hex
*/
public static sha256Hex(s: string): string {
const hash = CryptoJS.SHA256(s);
return hash.toString(CryptoJS.enc.Hex).toLowerCase();
}
/**
* hmac+sha256
*/
public static hmac256(secretKey: string, message: string): string {
const keyWordArray = CryptoJS.enc.Utf8.parse(secretKey);
const messageWordArray = CryptoJS.enc.Utf8.parse(message);
const hash = CryptoJS.HmacSHA256(messageWordArray, keyWordArray);
return hash.toString(CryptoJS.enc.Hex).toLowerCase();
}
}
@@ -0,0 +1,30 @@
import { HttpRequestMsg } from '../model/HttpRequestMsg.js'; // Assuming you have a TypeScript version of this
import { ApiAuthException } from '../exception/ApiAuthException.js'; // Assuming you have a TypeScript version of this
import axios, { AxiosError } from 'axios';
export class HttpUtils {
private constructor() { }
public static async call(requestMsg: HttpRequestMsg): Promise<string | null> {
var response;
try {
response = await axios({
method: requestMsg.method,
url: requestMsg.url,
headers: requestMsg.headers,
data: requestMsg.body
});
console.info("API invoke success. Response:", response.data);
return response.data;
} catch (error) {
if (error instanceof AxiosError) {
// Handle AxiosError specifically
console.error('API invoke failed. Response:', error.response.data);
return error.response.data;
} else {
// Handle other types of errors
console.error('API invoke failed.', error);
}
throw new ApiAuthException('API invoke failed.');
}
}
}