fix(core): update
This commit is contained in:
		| @@ -1,19 +1,20 @@ | ||||
| import * as plugins from './mailgun.plugins'; | ||||
| import * as interfaces from './interfaces'; | ||||
|  | ||||
| export class MailgunAccount { | ||||
|   public baseUrl = 'https://api.mailgun.net/v3'; | ||||
|   public baseUrlSe = 'https://se.api.mailgun.net/v3'; | ||||
|   public apiToken: string; | ||||
|  | ||||
|   constructor(apiTokenArg: string) { | ||||
|     this.apiToken = apiTokenArg; | ||||
|   } | ||||
|  | ||||
|   public getRequest(routeArg: string) { | ||||
|   public async getRequest(routeArg: string, binaryArg: boolean = false) { | ||||
|     let requestUrl = routeArg; | ||||
|     const needsBaseUrlPrefix = (routeArg.startsWith(this.baseUrl)) || routeArg.startsWith(this.baseUrlSe); | ||||
|     const needsBaseUrlPrefix = !routeArg.startsWith('https://'); | ||||
|     needsBaseUrlPrefix ? requestUrl = `${this.baseUrl}${routeArg}` : null; | ||||
|     const response = plugins.smartrequest.request(requestUrl, { | ||||
|     console.log(requestUrl); | ||||
|     const requestOptions: plugins.smartrequest.ISmartRequestOptions = { | ||||
|       method: 'GET', | ||||
|       headers: { | ||||
|         Authorization: `Basic ${plugins.smartstring.base64.encode( | ||||
| @@ -21,7 +22,13 @@ export class MailgunAccount { | ||||
|         )}`, | ||||
|         'Content-Type': 'application/json' | ||||
|       } | ||||
|     }); | ||||
|     }; | ||||
|     let response: plugins.smartrequest.IExtendedIncomingMessage; | ||||
|     if (!binaryArg) { | ||||
|       response = await plugins.smartrequest.request(requestUrl, requestOptions); | ||||
|     } else { | ||||
|       response = await plugins.smartrequest.getBinary(requestUrl, requestOptions); | ||||
|     } | ||||
|     return response; | ||||
|   } | ||||
|  | ||||
| @@ -69,6 +76,8 @@ export class MailgunAccount { | ||||
|       } | ||||
|     ]; | ||||
|  | ||||
|     console.log(smartmailArg.attachments); | ||||
|  | ||||
|     for (const attachment of smartmailArg.attachments) { | ||||
|       formFields.push({ | ||||
|         name: 'attachment', | ||||
| @@ -89,9 +98,27 @@ export class MailgunAccount { | ||||
|  | ||||
|   public async retrieveSmartMailFromMessageUrl(messageUrlArg: string) { | ||||
|     const response = await this.getRequest(messageUrlArg); | ||||
|     return response.body; | ||||
|   } | ||||
|     const responseBody: interfaces.IMailgunMessage = response.body; | ||||
|     const smartmail = new plugins.smartmail.Smartmail({ | ||||
|       from: responseBody.From, | ||||
|       body: responseBody["body-html"], | ||||
|       subject: responseBody.Subject, | ||||
|     }); | ||||
|  | ||||
|     // lets care about attachments | ||||
|     for (const attachmentInfo of responseBody.attachments) { | ||||
|       const attachmentName = attachmentInfo.name; | ||||
|       const attachmentContents = await this.getRequest(attachmentInfo.url, true); | ||||
|       smartmail.addAttachment(new plugins.smartfile.Smartfile({ | ||||
|         path: `./${attachmentName}`, | ||||
|         base: `./${attachmentName}`, | ||||
|         contentBuffer: attachmentContents.body | ||||
|       })); | ||||
|     } | ||||
|  | ||||
|     return smartmail; | ||||
|   } | ||||
|    | ||||
|   public async retrieveSmartMailFromNotifyPayload(notifyPayloadArg: any) { | ||||
|     return await this.retrieveSmartMailFromMessageUrl(notifyPayloadArg['message-url']); | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user