Skip to content

Commit

Permalink
Merge pull request #116 from KenEucker/develop
Browse files Browse the repository at this point in the history
2.0.3
  • Loading branch information
KenEucker committed Jan 3, 2022
2 parents 6df2830 + 17d6e70 commit 612b64d
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 95 deletions.
48 changes: 23 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1 align="center" style="border-bottom: none;">imgur</h1>
<h3 align="center">Unofficial JavaScript library</h3>
<h3 align="center">Unofficial JavaScript library for the Imgur.com API</h3>
<p align="center">
<a href="https://www.npmjs.com/package/imgur">
<img alt="npm version" src="https://img.shields.io/npm/v/imgur/latest.svg">
Expand Down Expand Up @@ -44,11 +44,11 @@ const client = new ImgurClient({ accessToken: process.env.ACCESS_TOKEN });
// or your client ID
const client = new ImgurClient({ clientId: process.env.CLIENT_ID });

// or your username/password/client id to retrieve an access token automatically:
// all credentials with a refresh token, in order to get access tokens automatically
const client = new ImgurClient({
username: process.env.USERNAME,
password: process.env.PASSWORD,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
refreshToken: process.env.REFRESH_TOKEN,
});
```

Expand All @@ -62,39 +62,37 @@ If you don't have any credentials, you'll need to:
### Upload one or more images and videos

```ts
// multiple images via an array of absolute paths
const responses = await client.upload([
'/home/kai/dank-meme.jpg',
'/home/kai/another-dank-meme',
]);
responses.forEach((r) => console.log(r.link));
```

If you want to provide metadata, such as a title, description, etc., then pass an object instead of a string:

```ts
// multiple images via an array of absolute paths
const responses = await client.upload([
// upload multiple images via fs.createReadStream (node)
const response = await client.upload([
{
image: createReadStream('/home/kai/dank-meme.jpg'),
title: 'Meme',
description: 'Dank Meme',
type: 'stream',
},
{
image: createReadStream('/home/kai/cat.mp4'),
title: 'A Cat Movie',
description: 'Caturday',
image: createReadStream('/home/kai/another-dank-meme'),
type: 'stream',
},
]);
responses.forEach((r) => console.log(r.link));
response.data.forEach((r) => console.log(r.link));
```

If you want to provide metadata, such as a title, description, etc., then pass an object instead of a string:

```ts
// upload image via url
const response = await client.upload({
image: 'https://i.imgur.com/someImageHash',
title: 'Meme',
description: 'Dank Meme',
});
console.log(response.data);
```

Acceptable key/values match what [the Imgur API expects](https://apidocs.imgur.com/#c85c9dfc-7487-4de2-9ecd-66f727cf3139):

| Key | Description |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `image` | A string that is a URL pointing to a remote image (up to 10MB) |
| `base64` | A base 64 object that is to be placed in the the upload form |
| `image` | A string, stream, or buffer that is a URL pointing to a remote image or video (up to 10MB) |
| `album` | The id of the album you want to add the media to. For anonymous albums, album should be the deletehash that is returned at creation |
| `type` | The type of the media that's being transmitted; `stream`, `base64` or `url` |
| `name` | The name of the media. This is automatically detected, but you can override |
Expand Down
1 change: 1 addition & 0 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const imgur = new ImgurClient({
accessToken: process.env.ACCESS_TOKEN,
clientSecret: process.env.CLIENT_SECRET,
clientId: process.env.CLIENT_ID,
rapidApiKey: process.env.RAPID_API_KEY,
});

const run = async (client) => {
Expand Down
112 changes: 56 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Ken Eucker <[email protected]>",
"name": "imgur",
"description": "Unofficial JavaScript library for Imgur",
"version": "2.0.1",
"version": "2.0.3",
"homepage": "https://github.com/keneucker/imgur",
"license": "MIT",
"keywords": [
Expand All @@ -19,7 +19,7 @@
"form-data": "^4.0.0"
},
"engines": {
"node": ">=16"
"node": ">=14"
},
"main": "imgur.node.js",
"browser": "imgur.js",
Expand Down Expand Up @@ -70,11 +70,11 @@
"commitizen": "^4.2.4",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^10.0.0",
"eslint": "^8.5.0",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
"husky": "^7.0.4",
"jest": "^27.4.5",
"lint-staged": "^12.1.4",
"lint-staged": "^12.1.5",
"mock-fs": "^5.1.2",
"msw": "^0.36.3",
"node-polyfill-webpack-plugin": "^1.1.4",
Expand Down

0 comments on commit 612b64d

Please sign in to comment.