Merge pull request #6 from ArcaneDisgea/clean-up

This commit is contained in:
goaaats 2021-05-27 18:43:12 +02:00 committed by GitHub
commit 95f6bc1873
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 23 deletions

View file

@ -1,2 +1 @@
index.js index.js
test.js

View file

@ -1,5 +1,4 @@
const fetch = require("node-fetch"); const fetch = require("node-fetch");
const fs = require("fs");
const path = require("path"); const path = require("path");
const { createCanvas, loadImage, registerFont } = require("canvas"); const { createCanvas, loadImage, registerFont } = require("canvas");

2
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "shit", "name": "shit",
"version": "1.0.0", "version": "1.1.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View file

@ -1,8 +1,13 @@
{ {
"name": "xiv-character-cards", "name": "xiv-character-cards",
"version": "1.0.0", "description": "API to create fancy cards for FFXIV characters based on their Lodestone data, hosted at https://ffxiv-character-cards.herokuapp.com.",
"version": "1.1.0",
"main": "create-card.js", "main": "create-card.js",
"license": "MIT", "license": "MIT",
"keywords": [
"ffxiv",
"xivapi"
],
"scripts": { "scripts": {
"start": "node index.js", "start": "node index.js",
"dev": "nodemon index.js" "dev": "nodemon index.js"

View file

@ -32,4 +32,45 @@ The API will reply with its status, and in case of success, the URL to the final
## Using in your application ## Using in your application
You can use the ``create-card.js`` file in any NodeJS project. It will return a PNG-buffer for you to use in your bot or application.<br>Check ``index.js`` for usage examples. ```
yarn add xiv-character-cards
# or
npm i xiv-character-cards
```
You will receive a PNG-buffer for you to use in your bot or application.<br>Check ``index.js`` for other usage examples.
### Example
```js
const { CardCreator } = require("xiv-character-cards");
const fs = require("fs");
const card = new CardCreator();
const lodestoneid = "13821878";
function example(cb) {
card.ensureInit()
.then(
() => card.createCard(lodestoneid),
(reason) => cb("Init failed: " + reason, null)
)
.then((image) =>
cb(null, {
binary: {
image: image,
},
})
)
.catch((reason) => cb("createCard failed: " + reason, null));
}
example((err, response) => {
const buffer = response.binary.image;
fs.writeFileSync(`./${lodestoneid}.png`, response.binary.image, (err) => {
if (err) {
console.log(err);
}
});
});
```

18
test.js
View file

@ -1,18 +0,0 @@
const fs = require("fs");
const createCard = require("./create-card").createCard;
createCard("9575452", (png) => {
const data = png.replace(/^data:image\/\w+;base64,/, "");
const buf = Buffer.from(data, "base64");
fs.writeFile('test.png', buf, (err) => {
console.log(err)
})
});
createCard("13821878", (png) => {
const data = png.replace(/^data:image\/\w+;base64,/, "");
const buf = Buffer.from(data, "base64");
fs.writeFile('image.png', buf, (err) => {
console.log(err)
})
});