mirror of https://github.com/JoeBiellik/paste
Add paste expiry
parent
5271bd812b
commit
3f3feab55e
@ -1,19 +1,12 @@
|
|||||||
var mongoose = require('mongoose');
|
var mongoose = require('mongoose');
|
||||||
var shortId = require('short-mongo-id');
|
var shortid = require('shortid');
|
||||||
|
|
||||||
var paste = new mongoose.Schema({
|
var paste = new mongoose.Schema({
|
||||||
|
_id: { type: String, unique: true, default: shortid.generate },
|
||||||
paste: { type: String },
|
paste: { type: String },
|
||||||
link: { type: String }
|
expiresAt: { type: Date, expires: 0, default: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7) }
|
||||||
}, {
|
}, {
|
||||||
timestamps: true
|
timestamps: true
|
||||||
});
|
});
|
||||||
|
|
||||||
paste.pre('save', function(next) {
|
|
||||||
if (this.isNew) {
|
|
||||||
this.link = shortId(this._id);
|
|
||||||
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = mongoose.model('Paste', paste);
|
module.exports = mongoose.model('Paste', paste);
|
||||||
|
Loading…
Reference in New Issue