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:
35
server/models/UserGeneration.js
Normal file
35
server/models/UserGeneration.js
Normal 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;
|
||||
Reference in New Issue
Block a user