Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imgup

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imgup - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

dist/cli.js

55

dist/index.js
#!/usr/bin/env node
import axios from 'axios';
import chalk from 'chalk';
import { program } from 'commander';
import * as dotenv from 'dotenv';
import formData from 'form-data';
import fs from 'fs';
import capitalize from 'lodash/fp/capitalize.js';
import ora from 'ora';
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
dotenv.config({ path: path.resolve(__dirname, '../.env') });
// This ID seems not necessary at all, but we're putting it in the request header anyway since it's
// documented in the official docs
const CLIENT_ID = process.env.IMGUR_CLIENT_ID;
// There are some crazy issues with the TS and the new module system. So instead of importing the
// package.json, we will just read it via the fs module... 😢
const packageJSONFilePath = path.resolve(__dirname, '../package.json');
const packageJSON = JSON.parse(fs.readFileSync(packageJSONFilePath, 'utf8'));
const appVersion = packageJSON.version;
program
.option('-f, --file <string>', 'specify an image file path to upload to imgur');
program.version(appVersion, '-v, --version', 'output the current version');
program.parse(process.argv);
import path from 'path';
import { createProgram } from './cli.js';
import { uploadImage } from './utils.js';
const program = createProgram();
const options = program.opts();
const data = new formData();
const file = options.file;

@@ -37,4 +19,2 @@ if (!file) {

const filePath = path.resolve(process.cwd(), file);
const baseName = path.basename(filePath);
const fileName = path.parse(baseName).name;
if (!fs.existsSync(filePath)) {

@@ -44,2 +24,5 @@ console.log(`${filePath} doesn't exist!`);

}
const data = new formData();
const baseName = path.basename(filePath);
const fileName = path.parse(baseName).name;
data.append('image', fs.createReadStream(filePath));

@@ -51,16 +34,16 @@ data.append('name', fileName);

url: 'https://api.imgur.com/3/upload',
headers: Object.assign({ Authorization: `Client-ID ${CLIENT_ID}` }, data.getHeaders()),
headers: {
...data.getHeaders(),
},
data: data,
};
const spinner = ora('Uploading image to imgur...').start();
axios(config)
.then((response) => {
spinner.succeed('Success');
console.log('Image URL:', chalk.bold(response.data.data.link));
console.log('Markdown:', `![${capitalize(fileName)} image](${response.data.data.link})`);
})
.catch((error) => {
spinner.fail('Failed');
console.log(error);
});
const maybeLink = await uploadImage(config);
if (maybeLink) {
console.log('Image URL:', chalk.bold(maybeLink));
console.log('Markdown:', `![${capitalize(fileName)} image](${maybeLink})`);
process.exit(0);
}
else {
process.exit(1);
}
//# sourceMappingURL=index.js.map
{
"name": "imgup",
"version": "1.1.1",
"version": "1.2.0",
"main": "index.js",

@@ -22,17 +22,15 @@ "license": "MIT",

"dependencies": {
"@types/axios": "^0.14.0",
"@types/form-data": "^2.5.0",
"@types/lodash": "^4.14.176",
"@types/node": "^16.11.7",
"axios": "^0.24.0",
"axios": "^1.2.6",
"chalk": "^4.1.2",
"commander": "^8.3.0",
"dotenv": "^10.0.0",
"form-data": "^4.0.0",
"husky": "^4.3.8",
"lodash": "^4.17.21",
"ora": "^6.0.1",
"prettier": "^2.4.1"
},
"devDependencies": {
"husky": "^4.3.8"
}
}

@@ -5,2 +5,8 @@ # imgup

## Installation
```sh
npm install -g imgup
```
## Usage

@@ -17,13 +23,17 @@

## Example
To upload an image from our test data directory:
```sh
imgup --file ./a/path/to/an/image.jpg
imgup --file ./testData/big-cat.png
# The following output will be shown in your CLI
✔ Success
Image URL: https://i.imgur.com/example.png
Markdown: ![Example image](https://i.imgur.com/example.png)
Image URL: https://i.imgur.com/mWbxxoM.png
Markdown: ![Big-cat image](https://i.imgur.com/mWbxxoM.png)
```
## Acknowledgement
Big thanks to [Rob Potter](https://unsplash.com/@robpotter) for the test data image
## TODOs

@@ -38,4 +48,4 @@

License
## License
MIT
#!/usr/bin/env node
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
import { AxiosRequestConfig } from 'axios';
import chalk from 'chalk';
import { program } from 'commander';
import * as dotenv from 'dotenv';
import formData from 'form-data';
import fs from 'fs';
import capitalize from 'lodash/fp/capitalize.js';
import ora from 'ora';
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
import path from 'path';
import { createProgram } from './cli.js';
import { uploadImage } from './utils.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
dotenv.config({ path: path.resolve(__dirname, '../.env') });
// This ID seems not necessary at all, but we're putting it in the request header anyway since it's
// documented in the official docs
const CLIENT_ID = process.env.IMGUR_CLIENT_ID;
// There are some crazy issues with the TS and the new module system. So instead of importing the
// package.json, we will just read it via the fs module... 😢
const packageJSONFilePath = path.resolve(__dirname, '../package.json');
const packageJSON = JSON.parse(fs.readFileSync(packageJSONFilePath, 'utf8'));
const appVersion = packageJSON.version;
program.option(
'-f, --file <string>',
'specify an image file path to upload to imgur',
);
program.version(appVersion, '-v, --version', 'output the current version');
program.parse(process.argv);
const program = createProgram();
const options = program.opts();
const data = new formData();
const file = options.file as string;

@@ -48,4 +24,2 @@

const filePath = path.resolve(process.cwd(), file);
const baseName = path.basename(filePath);
const fileName = path.parse(baseName).name;

@@ -57,2 +31,5 @@ if (!fs.existsSync(filePath)) {

const data = new formData();
const baseName = path.basename(filePath);
const fileName = path.parse(baseName).name;
data.append('image', fs.createReadStream(filePath));

@@ -66,3 +43,2 @@ data.append('name', fileName);

headers: {
Authorization: `Client-ID ${CLIENT_ID}`,
...data.getHeaders(),

@@ -73,16 +49,10 @@ },

const spinner = ora('Uploading image to imgur...').start();
const maybeLink = await uploadImage(config);
axios(config)
.then((response: AxiosResponse) => {
spinner.succeed('Success');
console.log('Image URL:', chalk.bold(response.data.data.link));
console.log(
'Markdown:',
`![${capitalize(fileName)} image](${response.data.data.link})`,
);
})
.catch((error: AxiosError) => {
spinner.fail('Failed');
console.log(error);
});
if (maybeLink) {
console.log('Image URL:', chalk.bold(maybeLink));
console.log('Markdown:', `![${capitalize(fileName)} image](${maybeLink})`);
process.exit(0);
} else {
process.exit(1);
}

@@ -6,6 +6,6 @@ {

"allowSyntheticDefaultImports": true,
"target": "es6",
"target": "ES2018",
"noImplicitAny": true,
"strictNullChecks": true,
"moduleResolution": "node",
"moduleResolution": "nodenext",
"strict": true,

@@ -19,5 +19,3 @@ "sourceMap": true,

},
"include": [
"src/**/*"
]
}
"include": ["src/**/*"]
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc