const DatabaseModel = require("./DatabaseModel.js").DatabaseModel; const mCrypto = require('../src/crypto.js'); function PasteContent(privId, type) { this.created = new Date(); this.apiKey = null; this.privId = privId; this.publicId = privId ? mCrypto.publicKey(privId) : null; this.type = type; this.expire = this.created; this.expired = false; this.data = null; this.renew(); } Object.setPrototypeOf(PasteContent.prototype, DatabaseModel.prototype); PasteContent.prototype.renew = function() { if (this.expired) return; this.expire = new Date(); this.expire.setMonth(this.expire.getMonth() + 6); } PasteContent.prototype.getTableName = function() { return "pasteContent"; } PasteContent.prototype.createOrUpdateBase = async function(dbHelper) { await dbHelper.runSql(`CREATE TABLE IF NOT EXISTS 'pasteContent' ( privId string not null PRIMARY KEY, publicId string not null, created datetime not null, expire datetime, type string not null, expired boolean not null, apiKey string, data string )`); } PasteContent.prototype.describe = function() { return { "privId": this.privId, "publicId": this.publicId, "created": this.created.getTime(), "expire": this.expire?.getTime(), "type": this.type, "apiKey": this.apiKey, "expired": this.expired, "data": this.data }; } PasteContent.prototype.fromDb = function(dbObj) { this.privId = dbObj['privId']; this.publicId = dbObj['publicId']; this.created = new Date(dbObj['created']); this.expire = dbObj['expire'] ? new Date(dbObj['expire']) : null; this.apiKey = dbObj['apiKey']; this.type = dbObj['type']; this.expired = dbObj['expired']; this.data = dbObj['data']; } module.exports.PasteContent = PasteContent;