- 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.
35 lines
733 B
JavaScript
35 lines
733 B
JavaScript
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;
|