Files

22 lines
615 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @fileoverview 生成 API KeyCLI
* @description 输出一个新的 `server.auth` Key,供写入 `config.yaml` 使用。
*
* 用法:`npm run genkey`
*/
import crypto from 'crypto';
/**
* 生成随机 API Key(用于 `config.yaml` 的 `server.auth`
* 格式:sk-{48位十六进制字符}
* @returns {string} API Key
*/
function generateApiKey() {
return 'sk-' + crypto.randomBytes(24).toString('hex');
}
console.log('>>> [GenAPIKey] 生成新的 API Key:');
console.log(generateApiKey());
console.log('\n>>> 请将此 Key 复制到 config.yaml 文件的 server.auth 字段中。');