Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sharinpix-move album node package #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions bin/moveAlbum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

require('coffeescript/register');
require('./moveInterface.coffee')();
16 changes: 16 additions & 0 deletions bin/moveInterface.coffee
Original file line number Diff line number Diff line change
@@ -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.'
30 changes: 30 additions & 0 deletions moveAlbum.coffee
Original file line number Diff line number Diff line change
@@ -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])
3 changes: 3 additions & 0 deletions moveAlbum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require('coffeescript/register')
moveAlbum = require('./moveAlbum.coffee');
module.exports = moveAlbum
Loading