web: add logging related to attachments

This commit is contained in:
Abdullah Atta
2024-05-04 17:15:04 +05:00
committed by Abdullah Atta
parent 647ff7ae0e
commit 0f5ce465c3
5 changed files with 45 additions and 7 deletions

View File

@@ -100,6 +100,9 @@ export class Attachments implements ICollection {
async init() {
await this.collection.init();
logger.debug("attachments initialized", {
total: await this.collection.count()
});
}
async add(
@@ -199,8 +202,12 @@ export class Attachments implements ICollection {
}
async remove(hashOrId: string, localOnly: boolean) {
logger.debug("Removing attachment", { hashOrId, localOnly });
const attachment = await this.attachment(hashOrId);
if (!attachment) return false;
if (!attachment) {
logger.debug("Attachment not found", { hashOrId, localOnly });
return false;
}
if (!localOnly && !(await this.canDetach(attachment)))
throw new Error("This attachment is inside a locked note.");
@@ -326,9 +333,11 @@ export class Attachments implements ICollection {
}
async attachment(hashOrId: string): Promise<Attachment | undefined> {
return this.all.find((eb) =>
const attachment = await this.all.find((eb) =>
eb.or([eb("id", "==", hashOrId), eb("hash", "==", hashOrId)])
);
if (attachment) logger.debug("attachment exists", { hashOrId });
return attachment;
}
markAsUploaded(id: string) {

View File

@@ -140,6 +140,8 @@ export class FileStorage {
}
async downloadFile(groupId: string, filename: string, chunkSize: number) {
logger.debug("[downloadFile] downloading", { filename, groupId });
const url = `${hosts.API_HOST}/s3?name=${filename}`;
const token = await this.tokenManager.getAccessToken();
const { execute, cancel } = this.fs.downloadFile(filename, {