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AU,EAAc,GAC/C,GAA4B,iBAAjB,EACV,MAAM,IAAI,UAAU,oDAErB,MACM,EADO,KACI,IACX,EAAU,CACf,KAAM,iBACN,KAAM,IACN,KAAM,uBAAyB,EAAI,UACnC,OAAQ,OACR,QAAS,CACR,mBAAoB,iBACpB,eAAgB,4CAChB,OAAU,WACV,eAAgB,mBAChB,OAAU,kDACV,gBAAiB,WACjB,OAAU,oBAAsB,EAAI,IAAM,SAAW,EAAI,IAAM,SAAW,EAAI,IAAM,SAAW,EAAI,IAAM,aAAe,EAAI,QAAU,IACtI,QAAW,oCAAsC,EAAI,UAAY,sBAAwB,EAAI,YAGzF,EAAW,KAAK,UAAU,CAC/B,aAAc,EACd,GAAI,EAAI,UACR,cAAe,EAAI,gBAId,EAAU,MAAM,QAAQ,GAAS,IACtC,IAAK,IAAa,EAAS,KAC1B,OAED,IAAI,EAAW,GACf,EAAI,GAAG,QAAQ,IACd,GAAY,CAAK,IAElB,EAAI,GAAG,OAAO,KACb,GAAI,sCAAsC,KAAK,GAC9C,EAAS,IAAI,MAAM,+BAEnB,IAEC,KAAK,MAAM,GAEX,GAAS,EACV,CAAE,MAAO,GACR,EAAS,IAAI,MAAM,+BAAiC,GACrD,CACD,GACC,IAWH,OARI,GAAY,EAAS,MACxB,EAAQ,GAAG,SAAS,IACnB,EAAS,IAAI,MAAM,EAAE,SAAS,IAIhC,EAAQ,MAAM,GACd,EAAQ,MAxDK,IA0Dd,EAkDA,OAAO,QAAU,oBACjB,OAAO,QAAQ,KAAO","file":"/npm/tumblr-upload@0.8.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/tumblr-upload@0.8.1/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","// @todo: cancel upload if a new upload is requested (debounce, but better)\n// @todo: prevent upload if file is empty. tumblr will fail silently\n'use strict';\nconst https = require('https');\nconst path = require('path');\nconst ini = require('iniparser');\nconst appRoots = [\n\tprocess.cwd(),\n\tpath.dirname(require.main.filename),\n\trequire('app-root-path')\n];\n\n/**\n * Set tumblr account to accept future uploads\n * @param {object|array} c  Credentials to use, object or array in this order: tumblr_id, user_form_key, anon_id, pfe, pfp, pfs, pfu\n */\nfunction Blog(c) {\n\tconst blog = this;\n\tif (c && c.length === 7) {\n\t\tc = {\n\t\t\ttumblr_id: c[0],\n\t\t\tuser_form_key: c[1],\n\t\t\tanon_id: c[2],\n\t\t\tpfe: c[3],\n\t\t\tpfp: c[4],\n\t\t\tpfs: c[5],\n\t\t\tpfu: c[6]\n\t\t};\n\t}\n\tif (!c || !c.tumblr_id || !c.user_form_key || !c.anon_id || !c.pfe || !c.pfp || !c.pfs || !c.pfu) {\n\t\tthrow new Error('Credentials missing or incomplete!');\n\t}\n\n\tblog.pwd = c;\n}\n\n/**\n * Upload the specified template using the previously-specified credentials\n * @param  {string}   htmlTemplate  Tumblr template to upload\n * @param  {Function} callback      Function to call after the upload is done or has failed\n * @return {ClientRequest}          Node ClientRequest method, can be .abort()'ed\n */\nBlog.prototype.upload = function (htmlTemplate, callback) {\n\tif (typeof htmlTemplate !== 'string') {\n\t\tthrow new TypeError('The parameter `htmlTemplate` should be a string.');\n\t}\n\tconst blog = this;\n\tconst pwd = blog.pwd;\n\tconst options = {\n\t\thost: 'www.tumblr.com',\n\t\tport: 443,\n\t\tpath: '/customize_api/blog/' + pwd.tumblr_id,\n\t\tmethod: 'POST',\n\t\theaders: {\n\t\t\t'x-requested-with': 'XMLHttpRequest',\n\t\t\t'x-for-issues': 'https://github.com/bfred-it/tumblr-upload',\n\t\t\t'pragma': 'no-cache',\n\t\t\t'content-type': 'application/json',\n\t\t\t'accept': 'application/json, text/j avascript, */*; q=0.01',\n\t\t\t'cache-control': 'no-cache',\n\t\t\t'Cookie': 'logged_in=1; pfp=' + pwd.pfp + '; pfs=' + pwd.pfs + '; pfe=' + pwd.pfe + '; pfu=' + pwd.pfu + '; anon_id=' + pwd.anon_id + ';',\n\t\t\t'referer': 'https://www.tumblr.com/customize/' + pwd.tumblr_id + '?redirect_to=/blog/' + pwd.tumblr_id\n\t\t}\n\t};\n\tconst httpBody = JSON.stringify({\n\t\tcustom_theme: htmlTemplate,\n\t\tid: pwd.tumblr_id,\n\t\tuser_form_key: pwd.user_form_key\n\t});\n\n\t// do request\n\tconst request = https.request(options, res => {\n\t\tif (!callback || !callback.call) {\n\t\t\treturn;\n\t\t}\n\t\tlet response = '';\n\t\tres.on('data', chunk => {\n\t\t\tresponse += chunk;\n\t\t});\n\t\tres.on('end', () => {\n\t\t\tif (/Authentication required|permission/i.test(response)) {\n\t\t\t\tcallback(new Error('Authentication failed'));\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\t// verify that it's a valid json response\n\t\t\t\t\tJSON.parse(response);\n\n\t\t\t\t\tcallback(false);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tcallback(new Error('Failed parsing of response: ' + response));\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t});\n\n\tif (callback && callback.call) {\n\t\trequest.on('error', e => {\n\t\t\tcallback(new Error(e.message));\n\t\t});\n\t}\n\n\trequest.write(httpBody);\n\trequest.end();\n\treturn blog;\n};\n\n/**\n * Upload specified template and use the settings in tumblr-upload.ini file\n * @see  Blog.prototype.upload\n */\nfunction uploadWithIniConfig(htmlTemplate, tumblr_id, callback) {\n\tlet c;\n\tconst paths = [];\n\n\tif (typeof htmlTemplate !== 'string') {\n\t\tthrow new TypeError('The parameter `htmlTemplate` should be a string.');\n\t}\n\tif (typeof tumblr_id !== 'string') {\n\t\tthrow new TypeError('The parameter `tumblr_id` should be a string.');\n\t}\n\n\t// try to load config file from all the possible paths\n\tappRoots.some(appRoot => {\n\t\ttry {\n\t\t\tconst filename = appRoot + '/tumblr-upload.ini';\n\t\t\tpaths.push(path.dirname(filename));\n\t\t\tc = ini.parseSync(filename);\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\treturn false;\n\t\t}\n\t});\n\n\t// were the credentials found?\n\tif (!c) {\n\t\tthrow new Error('Credentials missing! I looked for tumblr-upload.ini in:\\n' + paths.join('\\n'));\n\t}\n\n\t// pick the right blog\n\tc = c[tumblr_id];\n\tif (!c) {\n\t\tthrow new Error('Blog `' + tumblr_id + '` doesn\\'t exist in the config file ' + paths.pop());\n\t}\n\tc.tumblr_id = tumblr_id;\n\n\t// cheaply verify credentials\n\tif (!c.user_form_key || !c.anon_id || !c.pfe || !c.pfp || !c.pfs || !c.pfu) {\n\t\tthrow new Error('Credentials incomplete: ' + JSON.stringify(c));\n\t}\n\n\t// upload template\n\treturn new Blog(c).upload(htmlTemplate, callback);\n}\n\nmodule.exports = uploadWithIniConfig;\nmodule.exports.Blog = Blog;\n"]}