A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: add attachment deletion
thecodrr61e70855c228
diff --git a/packages/core/collections/attachments.js b/packages/core/collections/attachments.jsindex ea4fcc833..f014079bc 100644--- a/packages/core/collections/attachments.js+++ b/packages/core/collections/attachments.js@@ -1,7 +1,7 @@import Collection from "./collection";import id from "../utils/id";-import SparkMD5 from "spark-md5";import { deleteItem } from "../utils/array";+import hosts from "../utils/constants";export default class Attachments extends Collection {constructor(db, name, cached) {@@ -77,8 +77,15 @@ export default class Attachments extends Collection {delete(hash, noteId) {const attachment = this.all.find((a) => a.metadata.hash === hash);if (!attachment || !deleteItem(attachment.noteIds, noteId)) return;- if (!attachment.noteIds.length) attachment.dateDeleted = Date.now();-+ if (!attachment.noteIds.length) {+ attachment.dateDeleted = Date.now();+ const token = await this._db.user.tokenManager.getToken();+ const result = await this.fs.deleteFile(attachment.metadata.hash, {+ url: `${hosts.API_HOST}/s3?name=${attachment.metadata.hash}`,+ headers: { Authorization: `Bearer ${token}` },+ });+ if (!result) return;+ }return this._collection.updateItem(attachment);}