feat: implement user generation tracking and GitHub star validation for license key generation

- Added UserGeneration model to track user license generation counts and statuses.
- Introduced validateStar utility to check if a user has starred the project on GitHub.
- Updated license key generation endpoint to validate user star status and manage generation limits.
- Refactored server.js to handle new user generation logic and improved error handling.
This commit is contained in:
cheng zhen
2025-01-03 15:52:53 +08:00
parent 3290e15fe2
commit 8a5db8e84e
6 changed files with 126 additions and 1183 deletions

View File

@@ -0,0 +1,35 @@
const mongoose = require('mongoose');
const { getNowChinaTimeString } = require('../utils/date');
const userGenerationSchema = new mongoose.Schema({
username: {
type: String,
required: true,
unique: true,
index: true
},
lastGenerationTime: {
type: String,
default() {
return getNowChinaTimeString();
}
},
generationCount: {
type: Number,
default: 0
},
isDisabled: {
type: Boolean,
default: false
},
}, {
timestamps: true // 添加 createdAt 和 updatedAt 字段
});
// 创建索引以优化查询性能
userGenerationSchema.index({ username: 1 });
const UserGeneration = mongoose.model('UserGeneration', userGenerationSchema);
module.exports = UserGeneration;