diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md new file mode 100644 index 0000000..be3d02c --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# SharinPix Move Album + +#### Installation +```sh +$ npm install -g sharinpix-move +``` + +#### Usage + +##### Unix + +```sh +$ env SHARINPIX_URL=sharinpix://secret_url_you_can_find_in_your_admin_dashboard sharinpix-move sample.csv > success.csv 2> error.csv +``` +##### Windows + +```sh +C:\foo>set SHARINPIX_URL=sharinpix://secret_url_you_can_find_in_your_admin_dashboard +``` + +```sh +C:\foo>sharinpix-move sample.csv > success.csv 2> error.csv +``` + +- ``` sample.csv ``` refers to the path of the file containing the albums to be moved. +- ``` success.csv ``` refers to the path of the log file containing only successfully-moved albums. +- ``` error.csv ``` refers to the path of the error log file containing only albums that failed to be moved. + +The structure of the ``` sample.csv ``` file should be in the following form: +``` +source_id,destination_id +foo,bar +``` +License +---- + +MIT diff --git a/bin/moveAlbum b/bin/moveAlbum new file mode 100755 index 0000000..9bf1c33 --- /dev/null +++ b/bin/moveAlbum @@ -0,0 +1,4 @@ +#!/usr/bin/env node + +require('coffeescript/register'); +require('./moveInterface.coffee')(); diff --git a/bin/moveInterface.coffee b/bin/moveInterface.coffee new file mode 100644 index 0000000..e9cfe82 --- /dev/null +++ b/bin/moveInterface.coffee @@ -0,0 +1,16 @@ +moveAlbum = require '../moveAlbum.js' +fs = require 'fs' + +module.exports = -> + if process.env.SHARINPIX_URL + if process.argv.length is 3 + filePath = process.argv[2] + + if fs.existsSync(filePath) + moveAlbum filePath + else + console.error "Error: Could not find file #{ filePath }." + else + console.error 'Error: Expected atleast 1 argument. E.g: sharinpix-move sample.csv > success.csv 2> error.csv' + else + console.error 'Environment variable SHARINPIX_URL is incorrect.' \ No newline at end of file diff --git a/moveAlbum.coffee b/moveAlbum.coffee new file mode 100644 index 0000000..dd44c03 --- /dev/null +++ b/moveAlbum.coffee @@ -0,0 +1,30 @@ +csv = require 'fast-csv' +sharinpix = require 'sharinpix' +superagent = require 'superagent' +async = require 'async' +_ = require 'lodash' +fs = require 'fs' + +module.exports = (path) -> + q = async.queue((task, callback)-> + line = "#{task.src},#{task.dst}" + sharinpix + .get_instance() + .put( + "/albums/#{task.src}?merge=true", + { + album: + public_id: task.dst + } + ).then((res)-> + console.log line + callback() + , (err)-> + console.error line + callback() + ) + , 10) + csv + .fromStream(fs.createReadStream(path)) + .on "data", (data)-> + q.push(src: data[0], dst: data[1]) diff --git a/moveAlbum.js b/moveAlbum.js new file mode 100755 index 0000000..1630330 --- /dev/null +++ b/moveAlbum.js @@ -0,0 +1,3 @@ +require('coffeescript/register') +moveAlbum = require('./moveAlbum.coffee'); +module.exports = moveAlbum diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..aef7c26 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,310 @@ +{ + "name": "sharinpix-move", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "arguments-extended": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/arguments-extended/-/arguments-extended-0.0.3.tgz", + "integrity": "sha1-YQfkkX0OtvCk3WYyD8Fa/HLvSUY=", + "requires": { + "extended": "~0.0.3", + "is-extended": "~0.0.8" + } + }, + "array-extended": { + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/array-extended/-/array-extended-0.0.11.tgz", + "integrity": "sha1-1xRK50jek8pybxIQCdv/FibRZL0=", + "requires": { + "arguments-extended": "~0.0.3", + "extended": "~0.0.3", + "is-extended": "~0.0.3" + } + }, + "async": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz", + "integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==", + "requires": { + "lodash": "^4.17.10" + } + }, + "coffeescript": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.3.1.tgz", + "integrity": "sha512-DNJmSPMyiz+OjWYyuDXNBcFutDjP2TS2owsZ8YvT65hA8c5IdHWIBqdA3Yf/XHoK23d/f1HqLjQbEJJZJoeV1w==" + }, + "combined-stream": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", + "integrity": "sha1-cj599ugBrFYTETp+RFqbactjKBg=", + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "component-emitter": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz", + "integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=" + }, + "cookiejar": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.2.tgz", + "integrity": "sha512-Mw+adcfzPxcPeI+0WlvRrr/3lGVO0bD75SxX6811cxSh1Wbxx7xZBGK1eVtDf6si8rg2lhnUjsVLMFMfbRIuwA==" + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "date-extended": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/date-extended/-/date-extended-0.0.6.tgz", + "integrity": "sha1-I4AtV90b94GIE/4MMuhRqG2iZ8k=", + "requires": { + "array-extended": "~0.0.3", + "extended": "~0.0.3", + "is-extended": "~0.0.3" + } + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "declare.js": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/declare.js/-/declare.js-0.0.8.tgz", + "integrity": "sha1-BHit/5VkwAT1Hfc9i8E0AZ0o3N4=" + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, + "extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" + }, + "extended": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/extended/-/extended-0.0.6.tgz", + "integrity": "sha1-f7i/e52uOXWG5IVwrP1kLHjlBmk=", + "requires": { + "extender": "~0.0.5" + } + }, + "extender": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/extender/-/extender-0.0.10.tgz", + "integrity": "sha1-WJwHSCvmGhRgttgfnCSqZ+jzJM0=", + "requires": { + "declare.js": "~0.0.4" + } + }, + "fast-csv": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/fast-csv/-/fast-csv-2.4.1.tgz", + "integrity": "sha1-vX3SaDkfcpNntZRFuN0K0CaIGyY=", + "requires": { + "extended": "0.0.6", + "is-extended": "0.0.10", + "object-extended": "0.0.7", + "string-extended": "0.0.8" + } + }, + "form-data": { + "version": "1.0.0-rc4", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-1.0.0-rc4.tgz", + "integrity": "sha1-BaxrwiIntD5EYfSIFhVUaZ1Pi14=", + "requires": { + "async": "^1.5.2", + "combined-stream": "^1.0.5", + "mime-types": "^2.1.10" + }, + "dependencies": { + "async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=" + } + } + }, + "formidable": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz", + "integrity": "sha512-Fs9VRguL0gqGHkXS5GQiMCr1VhZBxz0JnJs4JmMp/2jL18Fmbzvv7vOFRU+U8TBkHEE/CX1qDXzJplVULgsLeg==" + }, + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "is-extended": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/is-extended/-/is-extended-0.0.10.tgz", + "integrity": "sha1-JE4UDfdbscmjEG9BL/GC+1NKbWI=", + "requires": { + "extended": "~0.0.3" + } + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "jsrsasign": { + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/jsrsasign/-/jsrsasign-5.0.12.tgz", + "integrity": "sha1-1i6jZlGKUv87AP+BOcCC8JA8rFA=" + }, + "lodash": { + "version": "4.17.10", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", + "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" + }, + "mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" + }, + "mime-db": { + "version": "1.36.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.36.0.tgz", + "integrity": "sha512-L+xvyD9MkoYMXb1jAmzI/lWYAxAMCPvIBSWur0PZ5nOf5euahRLVqH//FKW9mWp2lkqUgYiXPgkzfMUFi4zVDw==" + }, + "mime-types": { + "version": "2.1.20", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.20.tgz", + "integrity": "sha512-HrkrPaP9vGuWbLK1B1FfgAkbqNjIuy4eHlIYnFi7kamZyLLrGlo2mpcx0bBmNpKqBtYtAfGbodDddIgddSJC2A==", + "requires": { + "mime-db": "~1.36.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "object-extended": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/object-extended/-/object-extended-0.0.7.tgz", + "integrity": "sha1-hP0j9WsVWCrrPoiwXLVdJDLWijM=", + "requires": { + "array-extended": "~0.0.4", + "extended": "~0.0.3", + "is-extended": "~0.0.3" + } + }, + "process-nextick-args": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" + }, + "promise-polyfill": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-6.1.0.tgz", + "integrity": "sha1-36lpQ+qcEh/KTem1hoyznTRy4Fc=" + }, + "qs": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", + "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" + }, + "readable-stream": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "reduce-component": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/reduce-component/-/reduce-component-1.0.1.tgz", + "integrity": "sha1-4Mk1QsV0UhvqE98PlIjtgqt3xdo=" + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "sharinpix": { + "version": "0.0.9", + "resolved": "https://registry.npmjs.org/sharinpix/-/sharinpix-0.0.9.tgz", + "integrity": "sha512-5+xzuJZ0gYcaH/ANyTOAmUECRyISCznhwEVh1M8d9hAOEvu9K7tzOCZ6ETv95p8/PPHRTPmEYUodW27FENCOaQ==", + "requires": { + "async": "^2.5.0", + "coffeescript": "^2.3.1", + "fast-csv": "^2.4.1", + "jsrsasign": "5.0.12", + "promise-polyfill": "^6.1.0", + "superagent": "2.0.0" + } + }, + "string-extended": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/string-extended/-/string-extended-0.0.8.tgz", + "integrity": "sha1-dBlX3/SHsCcqee7FpE8jnubxfM0=", + "requires": { + "array-extended": "~0.0.5", + "date-extended": "~0.0.3", + "extended": "~0.0.3", + "is-extended": "~0.0.3" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "requires": { + "safe-buffer": "~5.1.0" + } + }, + "superagent": { + "version": "2.0.0", + "resolved": "http://registry.npmjs.org/superagent/-/superagent-2.0.0.tgz", + "integrity": "sha1-SZgg8Lbk3TUKIc1Wa1yBVx5MdYQ=", + "requires": { + "component-emitter": "^1.2.0", + "cookiejar": "^2.0.6", + "debug": "^2.2.0", + "extend": "^3.0.0", + "form-data": "1.0.0-rc4", + "formidable": "^1.0.17", + "methods": "^1.1.1", + "mime": "^1.3.4", + "qs": "^6.1.0", + "readable-stream": "^2.0.5", + "reduce-component": "^1.0.1" + } + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..31a85f1 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "sharinpix-move", + "version": "1.0.0", + "description": "Use origin_id and destination_id inside csv file to rename albums", + "main": "index.js", + "bin": { + "sharinpix-move": "./bin/moveAlbum" + }, + "scripts": { + "test": "" + }, + "author": "sharinpix", + "license": "ISC", + "dependencies": { + "async": "^2.6.1", + "coffeescript": "^2.3.1", + "fast-csv": "^2.4.1", + "fs": "0.0.1-security", + "lodash": "^4.17.10", + "sharinpix": "0.0.9" + } +} diff --git a/sample.csv b/sample.csv new file mode 100644 index 0000000..7069666 --- /dev/null +++ b/sample.csv @@ -0,0 +1 @@ +foo,bar