Skip to content

Commit

Permalink
Fixup download save all (#32)
Browse files Browse the repository at this point in the history
* add documentation and tests.

* implement download --save-all and --save-all-by-user

* Resolve issue related to being unable to download default emoji
    * emoji in the format data:image... were previously undownloadable /
made the operation hang, which seems bad.
    * the resolultion here is to clip the data tag, then switch from
writeFile to writeFileSync, which seems bad and is probably something to
replace later on.
  • Loading branch information
jackellenberger committed Dec 1, 2018
1 parent 35ebc79 commit 9e45045
Show file tree
Hide file tree
Showing 9 changed files with 1,906 additions and 1,727 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 1.4.0
* Revamp download
* `--save` can no longer be called with 'all' (but that never worked)
* `--save-all-by-user` added to save all emoji by all users into build/$subdomain/$user
* `--save-all` added to save all emoji to build/$subdomain
* Add jsdoc documentation, available at https://jackellenberger.github.io/emojme
* Configure circle ci
* Clarify what a user token should look like

# 1.3.3
* Fix bug preventing correct package contents from being uploaded to npm
* Fix bug preventing empty slack instances from adding and syncing emoji
Expand Down
18 changes: 12 additions & 6 deletions docs/emojme-download.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ <h1 class="page-title">
* @param {string|string[]} tokens a single or list of tokens to add emoji to. Must match respectively to `subdomains`
* @param {object} options contains singleton or arrays of emoji descriptors.
* @param {string|string[]} [options.save] A user name or array of user names whose emoji source images will be saved. All emoji source images are linked to in the default adminList, but passing a user name here will save that user's emoji to build/&lt;subdomain>/&lt;username>
* @param {boolean} [options.saveAll] if `true`, download all emoji on slack instance from all users to disk in a single location.
* @param {boolean} [options.saveAllByUser] if `true`, download all emoji on slack instance from all users to disk, organized into directories by user.
* @param {boolean} [options.bustCache] if `true`, ignore any adminList younger than 24 hours and repull slack instance's existing emoji. Can be useful for making `options.avoidCollisions` more accurate
* @param {boolean} [options.output] if `false`, no files will be written during execution. Prevents saving of adminList for future use
*
Expand Down Expand Up @@ -150,12 +152,14 @@ <h1 class="page-title">

const downloadPromises = authPairs.map(async (authPair) => {
const subdomain = authPair[0];
let saveResults;
let saveResults = [];

const adminList = new EmojiAdminList(...authPair, options.output);
const emojiList = await adminList.get(options.bustCache);
if (options.save &amp;&amp; options.save.length) {
saveResults = await EmojiAdminList.save(emojiList, subdomain, options.save);
if ((options.save &amp;&amp; options.save.length) || options.saveAll || options.saveAllByUser) {
saveResults = saveResults.concat(await EmojiAdminList.save(emojiList, subdomain, {
save: options.save, saveAll: options.saveAll, saveAllByUser: options.saveAllByUser
}));
}

return { emojiList, subdomain, saveResults };
Expand All @@ -168,13 +172,15 @@ <h1 class="page-title">

Cli.requireAuth(program);
Cli.allowIoControl(program)
// TODO: re-add --user option to save user admin list without getting stats or saving to disk
.option('--save &lt;user>', 'save all of &lt;user>\'s emoji to disk. specify "all" to save all emoji.', Cli.list, [])
.option('--save &lt;user>', 'save all of &lt;user>\'s emoji to disk at build/$subdomain/$user', Cli.list, [])
.option('--save-all', 'save all emoji from all users to disk at build/$subdomain')
.option('--save-all-by-user', 'save all emoji from all users to disk at build/$subdomain/$user')
.parse(process.argv);

return download(program.subdomain, program.token, {
// user: program.user, // TODO see above
save: program.save,
saveAll: program.saveAll,
saveAllByUser: program.saveAllByUser,
bustCache: program.bustCache,
output: program.output,
});
Expand Down
80 changes: 79 additions & 1 deletion docs/module-download.html
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,84 @@ <h6>Properties</h6>
</tr>


<tr>

<td class="name"><code>saveAll</code></td>


<td class="type">


<span class="param-type">
boolean
</span>





</td>


<td class="attributes">

&lt;optional><br>





</td>




<td class="description last">
<p>if <code>true</code>, download all emoji on slack instance from all users to disk in a single location.</p>

</td>
</tr>


<tr>

<td class="name"><code>saveAllByUser</code></td>


<td class="type">


<span class="param-type">
boolean
</span>





</td>


<td class="attributes">

&lt;optional><br>





</td>




<td class="description last">
<p>if <code>true</code>, download all emoji on slack instance from all users to disk, organized into directories by user.</p>

</td>
</tr>


<tr>

<td class="name"><code>bustCache</code></td>
Expand Down Expand Up @@ -453,7 +531,7 @@ <h6>Properties</h6>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="emojme-download.js.html">emojme-download.js</a>, <a href="emojme-download.js.html#line55">line 55</a>
<a href="emojme-download.js.html">emojme-download.js</a>, <a href="emojme-download.js.html#line57">line 57</a>
</li>
</ul>
</dd>
Expand Down
Loading

0 comments on commit 9e45045

Please sign in to comment.