diff --git a/app/services/user.js b/app/services/user.js index b64dcc7..d1d6575 100644 --- a/app/services/user.js +++ b/app/services/user.js @@ -925,6 +925,7 @@ class UserService extends SiteService { csrfToken: csrfTokenService, otpAuth: otpAuthService, page: pageService, + post: postService, sticker: stickerService, userNotification: userNotificationService, } = this.dtp.services; @@ -952,6 +953,7 @@ class UserService extends SiteService { ); await pageService.removeForAuthor(user); + await postService.removeForAuthor(user); await chatService.removeForUser(user); await commentService.removeForAuthor(user); diff --git a/app/workers/reeeper/job/archive-user-local.js b/app/workers/reeeper/job/archive-user-local.js index 42a967c..6f92f66 100644 --- a/app/workers/reeeper/job/archive-user-local.js +++ b/app/workers/reeeper/job/archive-user-local.js @@ -97,6 +97,11 @@ class ArchiveUserLocalJob extends SiteWorkerProcess { await this.archiveUserStickers(job); await this.archiveUserImages(job); + /* + * Archive DTP Sites specific content + */ + await this.archiveUserPosts(job); + /* * Create the .zip file archive, upload it to storage, and create the * UserArchive record. @@ -309,6 +314,33 @@ class ArchiveUserLocalJob extends SiteWorkerProcess { }); } + async archiveUserPosts (job) { + const Post = mongoose.model('Post'); + + job.data.postPath = path.join(job.data.workPath, 'posts'); + await fs.promises.mkdir(job.data.postPath, { recursive: true }); + + this.log.info('archiving user blog posts', { + user: { + _id: job.data.user._id, + username: job.data.user.username, + }, + }); + + await Post + .find({ author: job.data.user._id }) + .cursor() + .eachAsync(async (post) => { + const postFilename = path.join(job.data.postPath, `post-${post._id}.json`); + try { + await fs.promises.writeFile(postFilename, JSON.stringify(post, null, 2)); + } catch (error) { + this.log.error('failed to write user blog post file', { postFilename, error }); + // fall through + } + }); + } + async createArchiveFile (job) { const { minio: minioService } = this.dtp.services; try {