chore: add new featurew
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { Observable } from "rxjs";
|
||||
import { catchError, map, throwError } from "rxjs";
|
||||
|
||||
import { WildDuckBaseService } from "./wildduck-base.service";
|
||||
import { MailServerException } from "../../../core/exceptions/mail-server.exceptions";
|
||||
import { ListMessagesQueryDto, SearchMessagesQueryDto, UpdateMessageDto, UploadMessageDto } from "../DTO/message.dto";
|
||||
import { AttachmentResponse } from "../interfaces/attachment.interface";
|
||||
import {
|
||||
@@ -75,7 +77,37 @@ export class WildDuckMessagesService extends WildDuckBaseService {
|
||||
*/
|
||||
getMessageAttachment(userId: string, mailboxId: string, messageId: number, attachmentId: string): Observable<AttachmentResponse> {
|
||||
// This returns binary content
|
||||
return this.get<AttachmentResponse>(`/users/${userId}/mailboxes/${mailboxId}/messages/${messageId}/attachments/${attachmentId}`);
|
||||
const url = this.buildUrl(`/users/${userId}/mailboxes/${mailboxId}/messages/${messageId}/attachments/${attachmentId}`);
|
||||
this.logger.debug(`WildDuck GET: ${url}`);
|
||||
|
||||
return this.httpService
|
||||
.get(url, {
|
||||
responseType: "stream",
|
||||
headers: {
|
||||
Accept: "*/*",
|
||||
},
|
||||
})
|
||||
.pipe(
|
||||
map((response) => {
|
||||
this.logger.debug(`HTTP ${response.status}: ${response.config?.url}`);
|
||||
return {
|
||||
success: response.data,
|
||||
headers: response.headers,
|
||||
contentType: response.headers["content-type"],
|
||||
contentDisposition: response.headers["content-disposition"],
|
||||
contentLength: response.headers["content-length"],
|
||||
} as AttachmentResponse;
|
||||
}),
|
||||
catchError((error) => {
|
||||
this.logger.error(`WildDuck API error: ${error.message}`, error.stack);
|
||||
|
||||
if (error.response?.data?.error) {
|
||||
return throwError(() => new MailServerException(error.response.data.error));
|
||||
}
|
||||
|
||||
return throwError(() => error);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user