Socket
Socket
Sign inDemoInstall

imgbb-uploader

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imgbb-uploader - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

12

CHANGELOG.md

@@ -0,1 +1,13 @@

# 1.3.0
Issue #6 brought an interesting feature idea. Took a bit of time because I first had to adapt the module used by the tests (waifu-generator owo).
Everything seem to work as intended.
Took the opportunity to reduce insanity within test code. Not perfect, but still less horrible than before.
Finally, I'm abandoning the idea of making this frontend-compatible some day. I don't want to endorse terrorism, and it's definitely not reasonable to encourage people to throw API keys into their frontends (even free API key - remember this module will stop working the day imgBB stop providing their service).
What I could do, aside writing this in the README, is perhaps redirecting to a working HTML/JS or React snippet, so people looking for a quick solution without any regard for security (for POC/hackathon/pet project) could gain some time.
# 1.2.0

@@ -2,0 +14,0 @@

13

lib/cjs/index.d.ts

@@ -5,3 +5,11 @@ /**

* @param {string} apiKey - Your imgBB API key
* @param {string} pathToFile - Absolute path to your file
* @param {string} pathToFile - Path to your file
*
* @param {Object} options - OPTIONAL: pass Option object as parameter
* @param {string} options.apiKey - Your imgBB API key
* @param {string} options.imagePath - Path to your image
* @param {string} options.name - Custom name for your file
* @param {string} options.expiration - Expiration value in seconds
* @param {string} options.base64string - Upload a base64 string (alternative to options.imagePath)
*
* @returns {Promise.<ResponseObject>}

@@ -16,7 +24,8 @@ * A promise. Access your data using `.then` as shown in [the README](https://github.com/TheRealBarenziah/imgbb-uploader#use) :

apiKey: string;
imagePath: string;
imagePath: string | undefined;
name: string | undefined;
expiration: number | undefined;
base64string: string | undefined;
}
declare const imgbbUploader: (...args: string[] | IOptions[]) => Promise<import("./responseInterface").default>;
export = imgbbUploader;

55

lib/cjs/index.js

@@ -58,5 +58,5 @@ "use strict";

return __awaiter(void 0, void 0, void 0, function () {
var _a, _b, e_1, _c, imagePath, apiKey, _d, name_1, _e, expiration, _f, _g, e_2;
return __generator(this, function (_h) {
switch (_h.label) {
var _a, _b, e_1, _c, imagePath, apiKey, _d, name_1, _e, expiration, _f, base64string, _g, _h, _j, e_2;
return __generator(this, function (_k) {
switch (_k.label) {
case 0:

@@ -66,6 +66,6 @@ if (!(args.length === 2)) return [3 /*break*/, 8];

case 1:
if (!_h.sent()) return [3 /*break*/, 6];
_h.label = 2;
if (!_k.sent()) return [3 /*break*/, 6];
_k.label = 2;
case 2:
_h.trys.push([2, 4, , 5]);
_k.trys.push([2, 4, , 5]);
_a = postToImgbb_1.postToImgbb;

@@ -76,3 +76,3 @@ _b = {

return [4 /*yield*/, fileToString_1.fileToString(String(args[1]))];
case 3: return [2 /*return*/, _a.apply(void 0, [(_b.base64str = _h.sent(),
case 3: return [2 /*return*/, _a.apply(void 0, [(_b.base64str = _k.sent(),
_b.name = null,

@@ -82,28 +82,35 @@ _b.expiration = null,

case 4:
e_1 = _h.sent();
e_1 = _k.sent();
throw new Error(e_1);
case 5: return [3 /*break*/, 7];
case 6: throw new Error("Invalid params: please make sure that first argument is an imgBB API key, and second argument is a valid path to image file.");
case 7: return [3 /*break*/, 14];
case 7: return [3 /*break*/, 16];
case 8:
if (!(args.length === 1 && typeof args[0] === "object")) return [3 /*break*/, 13];
_c = __assign({}, args[0]), imagePath = _c.imagePath, apiKey = _c.apiKey, _d = _c.name, name_1 = _d === void 0 ? null : _d, _e = _c.expiration, expiration = _e === void 0 ? null : _e;
_h.label = 9;
if (!(args.length === 1 && typeof args[0] === "object")) return [3 /*break*/, 15];
_c = __assign({}, args[0]), imagePath = _c.imagePath, apiKey = _c.apiKey, _d = _c.name, name_1 = _d === void 0 ? null : _d, _e = _c.expiration, expiration = _e === void 0 ? null : _e, _f = _c.base64string, base64string = _f === void 0 ? null : _f;
_k.label = 9;
case 9:
_h.trys.push([9, 11, , 12]);
_f = postToImgbb_1.postToImgbb;
_g = {
_k.trys.push([9, 13, , 14]);
_g = postToImgbb_1.postToImgbb;
_h = {
apiKey: String(apiKey)
};
return [4 /*yield*/, fileToString_1.fileToString(String(imagePath))];
case 10: return [2 /*return*/, _f.apply(void 0, [(_g.base64str = _h.sent(),
_g.name = name_1 ? String(name_1) : null,
_g.expiration = expiration ? Number(expiration) : null,
_g)])];
if (!base64string // if base64string is provided, skip fs call
) return [3 /*break*/, 10]; // if base64string is provided, skip fs call
_j = base64string;
return [3 /*break*/, 12];
case 10: return [4 /*yield*/, fileToString_1.fileToString(String(imagePath))];
case 11:
e_2 = _h.sent();
_j = _k.sent();
_k.label = 12;
case 12: return [2 /*return*/, _g.apply(void 0, [(_h.base64str = _j,
_h.name = name_1 ? String(name_1) : null,
_h.expiration = expiration ? Number(expiration) : null,
_h)])];
case 13:
e_2 = _k.sent();
throw new Error(e_2);
case 12: return [3 /*break*/, 14];
case 13: throw new Error("It seems you didn't pass your arguments properly! Please check imgbbUploader documentation here:\nhttps://github.com/TheRealBarenziah/imgbb-uploader/tree/master");
case 14: return [2 /*return*/];
case 14: return [3 /*break*/, 16];
case 15: throw new Error("It seems you didn't pass your arguments properly! Please check imgbbUploader documentation here:\nhttps://github.com/TheRealBarenziah/imgbb-uploader/tree/master");
case 16: return [2 /*return*/];
}

@@ -110,0 +117,0 @@ });

@@ -66,3 +66,5 @@ "use strict";

var output = JSON.parse(response).data;
resolve(output);
output
? resolve(output)
: reject(new Error("There was a problem with imgBB, please check your inputs"));
});

@@ -69,0 +71,0 @@ })

@@ -7,4 +7,4 @@ /**

* @returns {Promise.<Boolean>}
* A promise that resolve to `true` if things are looking good, and otherwise resolve to `false`
* A promise that resolve to `true` if things are looking good, and to `false` otherwise
*/
export declare const validateInput: (apiKey: string, path: string) => Promise<boolean>;

@@ -38,5 +38,8 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateInput = void 0;
var promises_1 = require("fs/promises");
var fs_1 = __importDefault(require("fs"));
/**

@@ -48,9 +51,11 @@ * Formally validate input params

* @returns {Promise.<Boolean>}
* A promise that resolve to `true` if things are looking good, and otherwise resolve to `false`
* A promise that resolve to `true` if things are looking good, and to `false` otherwise
*/
exports.validateInput = function (apiKey, path) { return __awaiter(void 0, void 0, void 0, function () {
var presumedFile;
var presumedFile, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, promises_1.lstat(path)];
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, fs_1.default.promises.lstat(path)];
case 1:

@@ -65,5 +70,9 @@ presumedFile = _a.sent();

return [2 /*return*/, false];
return [2 /*return*/];
return [3 /*break*/, 3];
case 2:
e_1 = _a.sent();
return [2 /*return*/, false];
case 3: return [2 /*return*/];
}
});
}); };
{
"name": "imgbb-uploader",
"version": "1.2.0",
"version": "1.3.0",
"description": "Lightweight module to upload images through Imgbb API.",

@@ -32,3 +32,3 @@ "main": "lib/cjs/index.js",

"@types/node": "^14.0.27",
"axios": "^0.21.0",
"axios": "^0.21.1",
"dotenv": "^8.2.0",

@@ -47,3 +47,3 @@ "eslint-plugin-import": "^2.22.0",

"typescript": "^3.9.7",
"waifu-generator": "^1.0.0"
"waifu-generator": "^1.1.0"
},

@@ -50,0 +50,0 @@ "repository": {

@@ -9,2 +9,3 @@ # imgbb-uploader

[![Known Vulnerabilities](https://snyk.io/test/github/TheRealBarenziah/imgbb-uploader/badge.svg?targetFile=package.json)](https://snyk.io/test/github/TheRealBarenziah/imgbb-uploader?targetFile=package.json)
[![dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](https://img.shields.io/badge/dependencies-0-brightgreen)
[![Build Status](https://travis-ci.org/TheRealBarenziah/imgbb-uploader.svg?branch=master)](https://travis-ci.org/TheRealBarenziah/imgbb-uploader)

@@ -15,5 +16,7 @@

**Node >= 8** ( [this module uses async/await](https://node.green/) )
_Care: this module uses `fs` under the hood. It means **it WON'T work outside the node environment !**_
_To upload pictures from your frontend please check the [File API](https://developer.mozilla.org/en-US/docs/Web/API/File) instead_
_Care: this module uses `fs` under the hood. It means **it WON'T work outside the node environment !**_
_You really SHOULDN'T use API keys from your frontend. But, if you're the yolo type, you could use window.File & window.fetch. PLEASE DON'T DO THAT !!!_
[Blah blah blah, my soul is lost already, bring it on](https://stackoverflow.com/a/63669049/11894221)
## Install

@@ -81,3 +84,3 @@

- II) [Put that in an environment variable](https://www.npmjs.com/package/dotenv)
- III) pass an option object as argument :
- III) **pass an option object as argument** :

@@ -89,8 +92,18 @@ ```javascript

apiKey: process.env.IMGBB_API_KEY, // MANDATORY
imagePath: "yourImagePath", // MANDATORY
imagePath: "./your/image/path", // OPTIONAL (unless options.base64string is falsy)
name: "yourCustomFilename", // OPTIONAL: pass a custom filename to imgBB API
expiration: 3600 /* OPTIONAL: pass a numeric value in seconds.
It must be in the 60-15552000 range (POSIX time ftw).
Enable this to force your image to be deleted after that time. */,
It must be in the 60-15552000 range (feature based on POSIX time).
Enable this to force your image to be deleted after that time. */,
base64string:
"data:image/jpeg;base64,blahblahblah" /* OPTIONAL (unless options.imagePath is falsy)
Enable this to upload base64-encoded image directly as string. (available from 1.3.0 onward)
Allows to work with RAM directly for increased performance (skips fs I/O calls).
Beware: options.imagePath will be ignored as long as options.base64string is defined!
*/,
};

@@ -101,7 +114,2 @@

.catch((error) => console.error(error));
/*
Same data structure as above; if you provided name and/or expiration value,
response.expiration and/or response.image.name will change accordingly.
*/
```

@@ -112,2 +120,37 @@

## More examples using option object
Using options.base64string:
```javascript
const imgbbUploader = require("imgbb-uploader");
// Some promise of base64 data
const base64str = () =>
new Promise((resolve) => {
return setTimeout(() => {
resolve(
"iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAEklEQVR42mNcLVNbzwAEjDAGACcSA4kB6ARiAAAAAElFTkSuQmCC",
);
}, 1000);
});
// Your barebone async function
const myFunc = async (name) => {
try {
return await imgbbUploader({
apiKey: "definitely-not-a-valid-key",
base64string: await base64str(),
name: name,
});
} catch (e) {
throw e;
}
};
myFunc("Dolunay_Obruk-Sama_<3")
.then((res) => console.log(res))
.catch((e) => console.error(e));
```
## Learn more

@@ -114,0 +157,0 @@

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