MCPcopy Create free account
hub / github.com/async-labs/async / deleteFile

Method deleteFile

api/server/models/Message.ts:433–457  ·  view source on GitHub ↗
({ userId, messageId, fileUrl })

Source from the content-addressed store, hash-verified

431 }
432
433 public static async deleteFile({ userId, messageId, fileUrl }) {
434 if (!messageId || !fileUrl) {
435 throw new Error('Bad data');
436 }
437
438 const doc = await this.findById(messageId).setOptions({ lean: true });
439
440 if (!doc) {
441 throw new Error('Not found');
442 }
443
444 await this.checkPermission({ userId, chatId: doc.chatId });
445
446 await this.findOneAndUpdate(
447 { _id: messageId },
448 {
449 $pull: { files: { fileUrl } },
450 },
451 { runValidators: true },
452 );
453
454 const filesToDeleteFromS3 = [fileUrl];
455
456 deleteFiles(filesToDeleteFromS3).catch((err) => console.log(err));
457 }
458
459 public static async addFile({ userId, messageId, fileName, fileUrl }) {
460 if (!userId || !messageId || !fileName || !fileUrl) {

Callers

nothing calls this directly

Calls 2

checkPermissionMethod · 0.95
deleteFilesFunction · 0.90

Tested by

no test coverage detected