Skip to content

Commit

Permalink
add ratio for image
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahim-nazari committed Dec 12, 2023
1 parent 587beb1 commit ebcf73f
Show file tree
Hide file tree
Showing 3 changed files with 991 additions and 945 deletions.
14 changes: 12 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { default: axios } = require("axios");
const probe = require("probe-image-size");
var bodyParser = require("body-parser");
const express = require("express"),
cors = require("cors");
Expand Down Expand Up @@ -37,11 +38,20 @@ app.post("/", async (req, res) => {
try {
const url = makeUrl(req.body);
const response = await axios.get(url);
getPreviewFromContent({ ...response, url }).then((data) => {
getPreviewFromContent({ ...response, url }).then(async (data) => {
let newData = data;
const imagesource = data?.images[0] || null;
if (imagesource) {
let result = await probe(imagesource);
const ratio = Number((result.width / result.height).toFixed(2));
newData = {
...newData,
ratio,
};
}
if (newData.mediaType == "video.other") {
const videoId = youtube_parser(url);
newData = { ...data, videoId };
newData = { ...newData, videoId };
}
return res.status(200).json(newData);
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"link-preview-js": "^3.0.5"
"link-preview-js": "^3.0.5",
"probe-image-size": "^7.2.3"
},
"devDependencies": {
"nodemon": "^3.0.1"
Expand Down
Loading

0 comments on commit ebcf73f

Please sign in to comment.