"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Pushover = void 0;

var _axios = _interopRequireDefault(require("axios"));

var _formData = _interopRequireDefault(require("form-data"));

var _sharp = _interopRequireDefault(require("sharp"));

var _createNotificationPlatform = require("../createNotificationPlatform");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const APP_TOKEN = 'ax32fzevhit7iwkm3fk18uw1i2ooyv';
const Pushover = (0, _createNotificationPlatform.createNotificationPlatform)({
  name: 'Pushover',
  credentialName: 'key',
  sendFunction: async args => {
    const {
      message,
      title,
      imagePath,
      credentials
    } = args;

    if (imagePath) {
      (0, _sharp.default)(imagePath).resize(20).toBuffer();
      const data = new _formData.default();
      data.append('message', message);
      data.append('title', title);
      data.append('user', credentials.key);
      data.append('token', APP_TOKEN);
      data.append('attachment', (0, _sharp.default)(imagePath).resize(600), {
        filename: 'poster.jpg'
      });
      await _axios.default.post('https://api.pushover.net/1/messages.json', data, {
        headers: data.getHeaders()
      });
    } else {
      const params = new URLSearchParams({
        message: message,
        title: title,
        user: credentials.key,
        token: APP_TOKEN
      });
      await _axios.default.post('https://api.pushover.net/1/messages.json', params);
    }
  }
});
exports.Pushover = Pushover;
//# sourceMappingURL=pushover.js.map