itizawa 5 лет назад
Родитель
Сommit
a566f0d623
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      src/server/models/attachment.js

+ 11 - 0
src/server/models/attachment.js

@@ -8,6 +8,7 @@ const path = require('path');
 const mongoose = require('mongoose');
 const uniqueValidator = require('mongoose-unique-validator');
 const mongoosePaginate = require('mongoose-paginate-v2');
+const { addSeconds } = require('date-fns');
 
 const ObjectId = mongoose.Schema.Types.ObjectId;
 
@@ -75,5 +76,15 @@ module.exports = function(crowi) {
     return this.externalUrlExpiredAt.getTime() > new Date().getTime();
   };
 
+  attachmentSchema.methods.cashExternalUrl = function(externalUrl) {
+    if (externalUrl == null) {
+      throw new Error('url is required.');
+    }
+    this.externalUrlCached = externalUrl;
+    this.externalUrlExpiredAt = addSeconds(new Date(), 120);
+
+    return this.save();
+  };
+
   return mongoose.model('Attachment', attachmentSchema);
 };