Socket
Book a DemoInstallSign in
Socket

imanagur

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imanagur

Helps you manage your imgur album images

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
3
50%
Maintainers
1
Weekly downloads
 
Created
Source

imanagur

Isomorphic Javascript library for managing Imgur albums

npm version Build states

Join the community on GitHub Discussions

Installation

npm install imanagur

Usage

Import and instantiate with credentials:

// ESModule syntax
import { ImgurClient } from 'imanagur';

// CommonJS syntax
const { ImgurClient } = require('imanagur');

let client;

// if you already have an access token acquired
client = new ImgurClient({ accessToken: process.env.ACCESS_TOKEN });

// or your client ID
client = new ImgurClient({ clientId: process.env.CLIENT_ID });

// or your username/password/client id to retrieve an access token automatically:
client = new ImgurClient({
  username: process.env.USERNAME,
  password: process.env.PASSWORD,
  clientId: process.env.CLIENT_ID,
});

If you don't have any credentials, you'll need to:

⚠️ For brevity, the rest of the examples will leave out the import and/or instantiation step.

Upload one or more images and videos

// 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:

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

Acceptable key/values match what the Imgur API expects:

KeyDescription
imageA string that is a URL pointing to a remote image (up to 10MB)
streamA readable stream that is to be piped to the upload method
base64A base 64 object that is to be placed in the the upload form
albumThe id of the album you want to add the media to. For anonymous albums, album should be the deletehash that is returned at creation
typeThe type of the media that's being transmitted; stream, base64 or url
nameThe name of the media. This is automatically detected, but you can override
titleThe title of the media
descriptionThe description of the media
disable_audio1 will remove the audio track from a video file

Upload and track progress of uploads

Instances of ImgurClient emit uploadProgress events so that you can track progress with event listeners.

const client = new ImgurClient({ accessToken: process.env.ACCESS_TOKEN });

client.on('uploadProgress', (progress) => console.log(progress));
await client.upload('/home/kai/cat.mp4');

The progress object looks like the following:

{
  percent: 1,
  transferred: 577,
  total: 577,
  id: '/home/user/trailer.mp4'
}
KeyDescription
percent0 to 1, measures the percentage of upload (e.g., 0, 0.5, 0.8, 1). Basically transferred / total
transferredtotal number of bytes transferred thus far
totaltotal number of bytes to be transferred
idunique id for the media being transferred; useful when uploading multiple things concurrently

Delete an image

Requires an image hash or delete hash, which are obtained in an image upload response

client.delete('someImageHash');

Update image information

Update the title and/or description of an image

client.updateImage({
  imageHash: 'someImageHash',
  title: 'A new title',
  description: 'A new description',
});

Update multiple images at once:

client.updateImage([
  {
    imageHash: 'someImageHash',
    title: 'A new title',
    description: 'A new description',
  },
  {
    imageHash: 'anotherImageHash',
    title: 'A better title',
    description: 'A better description',
  },
]);

Favorite an image:

client.favoriteImage('someImageHash');
client.getGallery({
  section: 'hot',
  sort: 'viral',
  mature: false,
});

getGallery() accepts an object of type GalleryOptions. The follow options are available:

KeyRequiredDescription
sectionrequiredhot | top | user
sortoptionalviral | top | time | rising (only available with user section). Defaults to viral
pageoptionalnumber - the data paging number
windowoptionalChange the date range of the request if the section is top. Accepted values are day | week | month | year | all. Defaults to day
showViraloptionaltrue | false - Show or hide viral images from the user section. Defaults to true
matureoptionaltrue | false - Show or hide mature (nsfw) images in the response section. Defaults to false. NOTE: This parameter is only required if un-authed. The response for authed users will respect their account setting
album_previewsoptionaltrue | false - Include image metadata for gallery posts which are albums
client.getSubredditGallery({
  subreddit: 'wallstreetbets',
  sort: 'time',
});

getSubredditGallery() accepts an object of type SubredditGalleryOptions. The follow options are available:

KeyRequiredDescription
subredditrequiredA valid subreddit name
sortoptionaltime | top - defaults to time
pageoptionalnumber - the data paging number
windowoptionalChange the date range of the request if the section is top. Accepted values are day | week | month | year | all. Defaults to week
client.searchGallery({
  query: 'title: memes',
});

searchGallery() accepts an object of type SearchGalleryOptions. The follow options are available:

| Key | Required | Description | | -------------- | -------- | --------------------------------------------------------------------- | ------ | ------- | ------ | ------------------------- | | query or q | required | Query string | | sort | optional | time | viral | top - defaults to time | | page | optional | number - the data paging number | | window | optional | Change the date range of the request if the sort is top -- to day | week | month | year | all, defaults to all. |

Additionally, the following advanced search query options can be set (NOTE: if any of the below are set in the options, the query option is ignored and these will take precedent):

KeyRequiredDescription
q_alloptionalSearch for all of these words (and)
q_anyoptionalSearch for any of these words (or)
q_exactlyoptionalSearch for exactly this word or phrase
q_notoptionalExclude results matching this string
q_typeoptionalShow results for any file type, jpg | png | gif | anigif (animated gif) | album
q_size_pxoptionalSize ranges, small (500 pixels square or less) | med (500 to 2,000 pixels square) | big (2,000 to 5,000 pixels square) | lrg (5,000 to 10,000 pixels square) | huge (10,000 square pixels and above)

Get album info

const album = await client.getAlbum('XtMnA');

Keywords

imgur

FAQs

Package last updated on 08 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.