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GT,EAAQ,EAAS,GACjB,GACF,GAER,EAGF,OAAO,QAAU","file":"/npm/ghost-google-drive@2.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/ghost-google-drive@2.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n /*\n  * Google drive storage for ghost blog\n  * @author : Robin C Samuel <hi@robinz.in> http://robinz.in\n  * @updated : 10th April 2022\n  * \n*/\n\nconst StorageBase = require(\"ghost-storage-base\");\nconst fs = require(\"fs\");\nconst { google } = require(\"googleapis\");\nconst drive = google.drive(\"v3\");\n\nvar auth = config => {\n  var jwtClient = new google.auth.JWT(\n    config.key.client_email,\n    null,\n    config.key.private_key,\n    ['https://www.googleapis.com/auth/drive'],\n    null\n  );\n\n  return new Promise((resolve, reject) => {\n    jwtClient.authorize(err => {\n      if (err) {\n        reject(err);\n      }\n\n      resolve(jwtClient);\n    });\n  });\n}\n\nvar upload = (client, file) => {\n  return new Promise((resolve, reject) => {\n    drive.files.create({\n      auth: client,\n      resource: {\n        name: file.name,\n        mimeType: file.type\n      },\n      media: {\n        mimeType: file.type,\n        body: fs.createReadStream(file.path)\n      },\n      fields: 'id, fileExtension'\n    }, (err, uploadedFile) => {\n      if (err) {\n        reject(err);\n      }\n\n      // Promise is resolved with the result of create call\n      resolve(uploadedFile);\n    });\n  });\n}\n\nvar setPermissions = (client, data) => {\n  return new Promise((resolve, reject) => {\n    drive.permissions.create({\n      auth: client,\n      fileId: data.id,\n      supportsAllDrives: true,\n      supportsTeamDrives: true,\n      resource: {\n        'type': 'anyone',\n        'role': 'reader',\n      },\n      fields: 'id',\n    }, function (err, res) {\n      if (err) {\n        console.error(err);\n        reject(err);\n      }\n      resolve(res);\n    });\n  });\n}\n\nvar get = (client, fileId, callback) => {\n  drive.files.get({\n    auth: client,\n    fileId: fileId,\n    alt: 'media'\n  }, { responseType: \"stream\" },\n    function (error, response) {\n      callback(error, response);\n  });\n}\n\nvar remove = (client, file) => {\n  return new Promise(function (resolve, reject) {\n    drive.files.delete({\n      auth: client,\n      fileId: file\n    },\n    function (err, data) {\n      if (err) {\n        console.error(err);\n        reject(err);\n      }\n      resolve();\n    });\n  });\n}\n\nclass ghostGoogleDrive extends StorageBase {\n  constructor(config) {\n    super();\n    this.config = config;\n  }\n\n  /**\n   * Saves the image to storage (the file system)\n   * - image is the express image object\n   * - returns a promise which ultimately returns the full url to the uploaded image\n   *\n   * @param image\n   * @param targetDir\n   * @returns {*}\n   */\n  save(file, targetDir) {\n    return new Promise((resolve, reject) => {\n      auth(this.config)\n        .then(client => {\n          upload(client, file)\n            .then(resp => {\n              setPermissions(client, resp.data)\n                .then(res => {\n                  resolve('/content/images/' + resp.data.id + '.' + resp.data.fileExtension);\n              });\n            });\n        });\n    });\n  }\n\n  /**\n   * checks for existance of file (handle 404's proper)\n   * @param {*} fileName \n   * @param {*} targetDir \n   * @returns Promise.<*>\n   */\n  exists(fileName, targetDir) {\n    return new Promise((resolve, reject) => {\n      auth(this.config)\n        .then(client => {\n          get(client, fileName, (error, response) => {\n            if (error) {\n              console.error(fileName, \" not found\");\n              resolve(false);\n            }\n\n            resolve(true);\n          })\n        });\n    });\n  }\n\n  /**\n   * TODO: implement 404 functionality\n   * @returns {serveStaticContent}\n   */\n  serve() {\n    const _this = this;\n    return function serveContent(req, res, next) {\n      // get the file id from url\n      var fileId = req.path.replace('/', '').split('.')[0];\n      auth(_this.config).then(client => {\n        get(client, fileId, (err, resp) => {\n            if (err) {\n              console.error(\"fileId: \" + fileId, \"err: \" + err);\n              return next();\n            }\n            resp.data.pipe(res);\n        });\n      });\n    }\n  }\n\n  /**\n   * @returns {Promise.<*>}\n   */\n  delete() {\n    return function deleteContent(req, res, next) {\n      var fileId = req.path.replace('/', '').split('.')[0];\n      auth(this.config)\n        .then(client => {\n          remove(client, fileId)\n        });\n    };\n  }\n\n  /**\n   * Reads bytes from disk for a target image\n   * - path of target image (without content path!)\n   *\n   * @param options\n   */\n  read(options) {\n    var fileId = options.path.replace('/', '').split('.')[0];\n    return new Promise((resolve, reject) => {\n      auth(this.config)\n        .then(client => {\n          get(client, fileId, (error, response) => {\n            if (error) {\n              reject(error);\n            }\n\n            resolve(response);\n          });\n        });\n    });\n  }\n}\n\nmodule.exports = ghostGoogleDrive;\n"]}