attachmentStoreStrategy.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import fs from 'fs';
  2. import FileStoreStrategy, {FileStoreStrategyFilesystem, FileStoreStrategyGridFs, FileStoreStrategyS3} from './fileStoreStrategy'
  3. const insertActivity = (fileObj, activityType) =>
  4. Activities.insert({
  5. userId: fileObj.userId,
  6. type: 'card',
  7. activityType,
  8. attachmentId: fileObj._id,
  9. attachmentName: fileObj.name,
  10. boardId: fileObj.meta.boardId,
  11. cardId: fileObj.meta.cardId,
  12. listId: fileObj.meta.listId,
  13. swimlaneId: fileObj.meta.swimlaneId,
  14. });
  15. /** Strategy to store attachments at GridFS (MongoDB) */
  16. export class AttachmentStoreStrategyGridFs extends FileStoreStrategyGridFs {
  17. /** constructor
  18. * @param gridFsBucket use this GridFS Bucket
  19. * @param fileObj the current file object
  20. * @param versionName the current version
  21. */
  22. constructor(gridFsBucket, fileObj, versionName) {
  23. super(gridFsBucket, fileObj, versionName);
  24. }
  25. /** after successfull upload */
  26. onAfterUpload() {
  27. super.onAfterUpload();
  28. // If the attachment doesn't have a source field or its source is different than import
  29. if (!this.fileObj.meta.source || this.fileObj.meta.source !== 'import') {
  30. // Add activity about adding the attachment
  31. insertActivity(this.fileObj, 'addAttachment');
  32. }
  33. }
  34. /** after file remove */
  35. onAfterRemove() {
  36. super.onAfterRemove();
  37. insertActivity(this.fileObj, 'deleteAttachment');
  38. }
  39. }
  40. /** Strategy to store attachments at filesystem */
  41. export class AttachmentStoreStrategyFilesystem extends FileStoreStrategyFilesystem {
  42. /** constructor
  43. * @param fileObj the current file object
  44. * @param versionName the current version
  45. */
  46. constructor(fileObj, versionName) {
  47. super(fileObj, versionName);
  48. }
  49. /** after successfull upload */
  50. onAfterUpload() {
  51. super.onAfterUpload();
  52. // If the attachment doesn't have a source field or its source is different than import
  53. if (!this.fileObj.meta.source || this.fileObj.meta.source !== 'import') {
  54. // Add activity about adding the attachment
  55. insertActivity(this.fileObj, 'addAttachment');
  56. }
  57. }
  58. /** after file remove */
  59. onAfterRemove() {
  60. super.onAfterRemove();
  61. insertActivity(this.fileObj, 'deleteAttachment');
  62. }
  63. }
  64. /** Strategy to store attachments at filesystem */
  65. export class AttachmentStoreStrategyS3 extends FileStoreStrategyS3 {
  66. /** constructor
  67. * @param s3Bucket use this S3 Bucket
  68. * @param fileObj the current file object
  69. * @param versionName the current version
  70. */
  71. constructor(s3Bucket, fileObj, versionName) {
  72. super(s3Bucket, fileObj, versionName);
  73. }
  74. /** after successfull upload */
  75. onAfterUpload() {
  76. super.onAfterUpload();
  77. // If the attachment doesn't have a source field or its source is different than import
  78. if (!this.fileObj.meta.source || this.fileObj.meta.source !== 'import') {
  79. // Add activity about adding the attachment
  80. insertActivity(this.fileObj, 'addAttachment');
  81. }
  82. }
  83. /** after file remove */
  84. onAfterRemove() {
  85. super.onAfterRemove();
  86. insertActivity(this.fileObj, 'deleteAttachment');
  87. }
  88. }