|
|
@@ -32,6 +32,24 @@ module.exports = function(crowi) {
|
|
|
return fileUploader.generateUrl(this.filePath);
|
|
|
});
|
|
|
|
|
|
+ attachmentSchema.statics.findById = function(id) {
|
|
|
+ var Attachment = this;
|
|
|
+
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ Attachment.findOne({_id: id}, function(err, data) {
|
|
|
+ if (err) {
|
|
|
+ return reject(err);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data === null) {
|
|
|
+ return reject(new Error('Attachment not found'));
|
|
|
+ }
|
|
|
+ return resolve(data);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
attachmentSchema.statics.getListByPageId = function(id) {
|
|
|
var self = this;
|
|
|
|
|
|
@@ -104,5 +122,25 @@ module.exports = function(crowi) {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ attachmentSchema.statics.createCacheFileName = function(attachment) {
|
|
|
+ return crowi.cacheDir + 'attachment-' + attachment._id;
|
|
|
+ };
|
|
|
+
|
|
|
+ attachmentSchema.statics.findDeliveryFile = function(attachment) {
|
|
|
+ // find local
|
|
|
+ var fs = require('fs');
|
|
|
+ var deliveryFile = {
|
|
|
+ filename: '',
|
|
|
+ options: {
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': attachment.fileFormat,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ };
|
|
|
+ var cacheFileName = this.createCacheFileName(attachment);
|
|
|
+ // とちゅう
|
|
|
+ return deliveryFile;
|
|
|
+ };
|
|
|
+
|
|
|
return mongoose.model('Attachment', attachmentSchema);
|
|
|
};
|