"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Pushbullet = 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 Pushbullet = (0, _createNotificationPlatform.createNotificationPlatform)({
  name: 'Pushbullet',
  credentialName: 'token',
  sendFunction: async args => {
    const {
      message,
      title,
      imagePath,
      credentials
    } = args;

    if (imagePath) {
      const uploadRequestRes = await _axios.default.post('https://api.pushbullet.com/v2/upload-request', {
        file_name: 'poster.jpg',
        file_type: 'image/jpeg'
      }, {
        headers: {
          'Access-Token': credentials.token
        }
      });
      const data = new _formData.default();
      data.append('file', (0, _sharp.default)(imagePath).resize(400));
      const uploadRes = await _axios.default.post(uploadRequestRes.data.upload_url, data, {
        headers: data.getHeaders()
      });
      await _axios.default.post('https://api.pushbullet.com/v2/pushes', {
        body: message,
        title: title,
        type: 'file',
        file_name: 'poster.jpg',
        file_type: 'image/jpeg',
        file_url: uploadRequestRes.data.file_url
      }, {
        headers: {
          'Access-Token': credentials.token
        }
      });
    } else {
      await _axios.default.post('https://api.pushbullet.com/v2/pushes', {
        body: message,
        title: title,
        type: 'note'
      }, {
        headers: {
          'Access-Token': credentials.token
        }
      });
    }
  }
});
exports.Pushbullet = Pushbullet;
//# sourceMappingURL=pushbullet.js.map