diff --git a/Fonts/.nomedia b/Fonts/.nomedia new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Fonts/.nomedia @@ -0,0 +1 @@ + diff --git a/Fonts/NotoColorEmoji-Regular.ttf b/Fonts/NotoColorEmoji-Regular.ttf new file mode 100644 index 0000000..559002b Binary files /dev/null and b/Fonts/NotoColorEmoji-Regular.ttf differ diff --git a/Fonts/Rokkitt-Regular.ttf b/Fonts/Rokkitt-Regular.ttf new file mode 100644 index 0000000..7e4dd71 Binary files /dev/null and b/Fonts/Rokkitt-Regular.ttf differ diff --git a/Instagram/Assets/Rokkitt-Regular.ttf b/Instagram/Assets/Rokkitt-Regular.ttf new file mode 100644 index 0000000..7e4dd71 Binary files /dev/null and b/Instagram/Assets/Rokkitt-Regular.ttf differ diff --git a/Instagram/Assets/comment-dark.png b/Instagram/Assets/comment-dark.png new file mode 100644 index 0000000..5ed607d Binary files /dev/null and b/Instagram/Assets/comment-dark.png differ diff --git a/Instagram/Assets/comment.png b/Instagram/Assets/comment.png new file mode 100644 index 0000000..c861e7a Binary files /dev/null and b/Instagram/Assets/comment.png differ diff --git a/Instagram/Assets/like-dark.png b/Instagram/Assets/like-dark.png new file mode 100644 index 0000000..470da50 Binary files /dev/null and b/Instagram/Assets/like-dark.png differ diff --git a/Instagram/Assets/like.png b/Instagram/Assets/like.png new file mode 100644 index 0000000..3c4806f Binary files /dev/null and b/Instagram/Assets/like.png differ diff --git a/Instagram/Assets/liked.png b/Instagram/Assets/liked.png new file mode 100644 index 0000000..6487a48 Binary files /dev/null and b/Instagram/Assets/liked.png differ diff --git a/Instagram/Assets/save-dark.png b/Instagram/Assets/save-dark.png new file mode 100644 index 0000000..d042e43 Binary files /dev/null and b/Instagram/Assets/save-dark.png differ diff --git a/Instagram/Assets/save.png b/Instagram/Assets/save.png new file mode 100644 index 0000000..6f0a369 Binary files /dev/null and b/Instagram/Assets/save.png differ diff --git a/Instagram/Assets/saved.png b/Instagram/Assets/saved.png new file mode 100644 index 0000000..4dccd48 Binary files /dev/null and b/Instagram/Assets/saved.png differ diff --git a/Instagram/Assets/share-dark.png b/Instagram/Assets/share-dark.png new file mode 100644 index 0000000..0ae5a44 Binary files /dev/null and b/Instagram/Assets/share-dark.png differ diff --git a/Instagram/Assets/share.png b/Instagram/Assets/share.png new file mode 100644 index 0000000..9884ebc Binary files /dev/null and b/Instagram/Assets/share.png differ diff --git a/Instagram/Assets/verified.png b/Instagram/Assets/verified.png new file mode 100644 index 0000000..ec1afde Binary files /dev/null and b/Instagram/Assets/verified.png differ diff --git a/Instagram/Digital Regular.ttf b/Instagram/Digital Regular.ttf new file mode 100644 index 0000000..500b3d8 Binary files /dev/null and b/Instagram/Digital Regular.ttf differ diff --git a/Instagram/VacerSansThinPersonal.ttf b/Instagram/VacerSansThinPersonal.ttf new file mode 100644 index 0000000..b7af80f Binary files /dev/null and b/Instagram/VacerSansThinPersonal.ttf differ diff --git a/Instagram/instgramPost.js b/Instagram/instgramPost.js index a6ee091..1a12dd6 100644 --- a/Instagram/instgramPost.js +++ b/Instagram/instgramPost.js @@ -1,11 +1,29 @@ -import { createCanvas, loadImage } from 'canvas'; +import { createCanvas, registerFont, loadImage } from 'canvas'; +import path from 'path'; +import { fileURLToPath } from 'url'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +// Register custom font +const fontPath = path.join(__dirname, '../Fonts', 'Rokkitt-Regular.ttf'); +registerFont(fontPath, { family: 'Rokkitt' }); + +const emojiPath = path.join(__dirname, '../Fonts', 'NotoColorEmoji-Regular.ttf'); +registerFont(emojiPath, { family: 'Noto Color Emoji' }); + +const likePng = (value) => path.join(__dirname, 'Assets', value ? 'liked.png' : 'like.png'); +const savePng = (value) => path.join(__dirname, 'Assets', value ? 'saved.png' : 'save.png'); +const commentPng = path.join(__dirname, 'Assets', 'comment.png'); +const sharePng = path.join(__dirname, 'Assets', 'share.png'); +const verifiedPng = path.join(__dirname, 'Assets', 'verified.png'); + export default class InstagramPost { constructor() { this.following = false; this.verified = false; - this.pfp = 'https://avatars.githubusercontent.com/u/121213527?v=4&number=69'; + this.pfp = 'https://avatars.githubusercontent.com/u/121213527?v=4'; this.username = 'PikaBotz'; this.watermark = false; this.saved = false; @@ -15,7 +33,8 @@ export default class InstagramPost { this.caption = ''; this.ago = '1 year ago'; this.liked = false; - this.imageUrl = 'https://avatars.githubusercontent.com/u/121213527?v=4&number=69'; + this.dark = true; + this.imageUrl = 'https://avatars.githubusercontent.com/u/121213527?v=4'; } isFollowing(value) { @@ -78,92 +97,266 @@ export default class InstagramPost { return this; } + isDark(value) { + if (typeof value === 'boolean') this.dark = value; + return this; + } + setImage(value) { this.imageUrl = value; return this; } async buildCanvas() { - const postImage = await loadImage(this.imageUrl); - const frameWidth = Math.min(1080, postImage.width); - const frameHeight = Math.min(1350, postImage.height); - const canvas = createCanvas(frameWidth, frameHeight + 200); + const width = 400; + const height = 540; + const canvas = createCanvas(width, height); const ctx = canvas.getContext('2d'); - const black = '#000'; - const white = '#fff'; - const gray = '#888'; - const blue = '#1da1f2'; - const red = '#ff0000'; - ctx.font = '14px Arial'; - ctx.fillStyle = black; - ctx.fillRect(0, 0, canvas.width, canvas.height); + + // Background + ctx.fillStyle = '#000'; + ctx.fillRect(0, 0, width, height); + + // Header + const headerHeight = 60; + ctx.fillStyle = '#1c1c1c'; + ctx.fillRect(0, 0, width, headerHeight); + + // Profile Picture with gradient border + const profilePicSize = 44; + const profilePicX = 10; + const profilePicY = 8; + const gradient = ctx.createLinearGradient(0, 0, profilePicSize, profilePicSize); + gradient.addColorStop(0, 'red'); + gradient.addColorStop(0.14, 'orange'); + gradient.addColorStop(0.28, 'yellow'); + gradient.addColorStop(0.42, 'green'); + gradient.addColorStop(0.57, 'blue'); + gradient.addColorStop(0.71, 'indigo'); + gradient.addColorStop(0.85, 'violet'); + ctx.fillStyle = gradient; + ctx.beginPath(); + ctx.arc(profilePicX + profilePicSize / 2, profilePicY + profilePicSize / 2, profilePicSize / 2, 0, Math.PI * 2); + ctx.fill(); + ctx.fillStyle = '#1c1c1c'; - ctx.fillRect(0, 0, canvas.width, 60); - const profilePic = await loadImage(this.pfp); ctx.beginPath(); - ctx.arc(30, 30, 22, 0, Math.PI * 2); - ctx.fillStyle = black; + ctx.arc(profilePicX + profilePicSize / 2, profilePicY + profilePicSize / 2, (profilePicSize - 4) / 2, 0, Math.PI * 2); ctx.fill(); + + // Load Profile Picture + const profileImage = await loadImage(this.pfp); + ctx.save(); + ctx.beginPath(); + ctx.arc(profilePicX + profilePicSize / 2, profilePicY + profilePicSize / 2, (profilePicSize - 8) / 2, 0, Math.PI * 2); + ctx.closePath(); ctx.clip(); - ctx.drawImage(profilePic, 8, 8, 44, 44); + ctx.drawImage(profileImage, profilePicX + 4, profilePicY + 2, profilePicSize - 8, profilePicSize - 8); ctx.restore(); - ctx.fillStyle = white; - ctx.font = 'bold 16px Arial'; - ctx.fillText(this.username, 60, 30); + + ctx.font = 'bold 18px Rokkitt'; // Increase font size and make it bold +ctx.fillStyle = '#fff'; // White text color + +// Optional: Add a stroke for extra boldness +ctx.strokeStyle = '#000'; // Black outline for contrast +ctx.lineWidth = 2; // Thickness of the outline +ctx.strokeText(this.username, profilePicX + profilePicSize + 10, profilePicY + 19); // Draw the outline + +// Fill the text +ctx.fillText(this.username, profilePicX + profilePicSize + 10, profilePicY + 19); + if (this.verified) { - const verifiedBadge = await loadImage( - 'https://upload.wikimedia.org/wikipedia/commons/e/e4/Twitter_Verified_Badge.svg' - ); - ctx.drawImage(verifiedBadge, 60 + ctx.measureText(this.username).width + 5, 15, 16, 16); + const verifiedImage = await loadImage(verifiedPng); // Replace with the path to your heart PNG image +const verifiedX = profilePicX + profilePicSize + 72; // X position of the heart image +const verifiedY = profilePicY + 6; // Y position of the heart image +const verifiedSize = 15; // Size of the heart image + +// Draw the heart image +ctx.drawImage(verifiedImage, verifiedX, verifiedY, verifiedSize, verifiedSize); } - ctx.fillStyle = gray; - ctx.font = '12px Arial'; - const watermarkText = this.watermark ? this.watermark : 'Instagram Post'; - ctx.fillText(watermarkText, 60, 45); - ctx.fillStyle = this.following ? white : blue; - ctx.strokeStyle = white; - ctx.lineWidth = 1; - ctx.strokeRect(canvas.width - 80, 15, 65, 30); - ctx.fillText(this.following ? 'Following' : 'Follow', canvas.width - 70, 35); - ctx.fillStyle = white; - ctx.font = 'bold 16px Arial'; - ctx.fillText('...', canvas.width - 20, 30); - const aspectRatio = postImage.width / postImage.height; - const maxAspectRatio = 16 / 9; - const minAspectRatio = 3 / 4; - let imgWidth = frameWidth, - imgHeight = frameHeight; - if (aspectRatio > maxAspectRatio) { - imgWidth = frameHeight * maxAspectRatio; - } else if (aspectRatio < minAspectRatio) { - imgHeight = frameWidth / minAspectRatio; + if (this.watermark) { + ctx.font = '12px Rokkitt'; + ctx.fillStyle = '#888'; + ctx.fillText(this.watermark, profilePicX + profilePicSize + 10, profilePicY + 32); } - ctx.drawImage( - postImage, - (frameWidth - imgWidth) / 2, - 60, - imgWidth, - imgHeight - ); - const contentY = frameHeight + 70; - const heartIcon = this.liked ? '\u2665' : '\u2661'; - const saveIcon = this.saved ? '\u{1F516}' : '\u{1F517}'; - ctx.fillStyle = this.liked ? red : white; - ctx.fillText(`${heartIcon} ${this.likes}k`, 10, contentY); - ctx.fillStyle = white; - ctx.fillText(`💬 ${this.comments}`, 100, contentY); - ctx.fillText(`✈️ ${this.shares}`, 200, contentY); - ctx.fillStyle = this.saved ? red : white; - ctx.fillText(`${saveIcon}`, frameWidth - 30, contentY); - ctx.fillStyle = white; - ctx.font = 'bold 14px Arial'; - ctx.fillText(this.username, 10, contentY + 30); - ctx.font = '14px Arial'; - ctx.fillText(this.caption, 10, contentY + 50); - ctx.fillStyle = gray; - ctx.fillText(this.ago, 10, contentY + 70); - const buffer = canvas.toBuffer('image/png'); + + // Follow Button +const buttonWidth = 60; +const buttonHeight = 20; +const buttonX = width - 100; // Move square 10px to the left +const buttonY = profilePicY + 9; +const cornerRadius = 5; // Radius for rounded corners + +// Draw the rounded rectangle +ctx.beginPath(); +ctx.moveTo(buttonX + cornerRadius, buttonY); // Top-left corner +ctx.lineTo(buttonX + buttonWidth - cornerRadius, buttonY); // Top edge +ctx.quadraticCurveTo(buttonX + buttonWidth, buttonY, buttonX + buttonWidth, buttonY + cornerRadius); // Top-right corner +ctx.lineTo(buttonX + buttonWidth, buttonY + buttonHeight - cornerRadius); // Right edge +ctx.quadraticCurveTo(buttonX + buttonWidth, buttonY + buttonHeight, buttonX + buttonWidth - cornerRadius, buttonY + buttonHeight); // Bottom-right corner +ctx.lineTo(buttonX + cornerRadius, buttonY + buttonHeight); // Bottom edge +ctx.quadraticCurveTo(buttonX, buttonY + buttonHeight, buttonX, buttonY + buttonHeight - cornerRadius); // Bottom-left corner +ctx.lineTo(buttonX, buttonY + cornerRadius); // Left edge +ctx.quadraticCurveTo(buttonX, buttonY, buttonX + cornerRadius, buttonY); // Top-left corner +ctx.closePath(); + +// Style the button +ctx.strokeStyle = '#fff'; +ctx.lineWidth = 1; +ctx.stroke(); + +// Set the text +const buttonText = this.following ? 'Following' : 'Follow'; +ctx.font = '12px Rokkitt'; +ctx.fillStyle = '#fff'; + +// Measure text width for centering +const textWidth = ctx.measureText(buttonText).width; +const textX = buttonX + (buttonWidth - textWidth) / 2; // Center text horizontally +const textY = buttonY + (buttonHeight + 12) / 2 - 2; // Center text vertically (fine-tuned) + +// Draw the text +ctx.fillText(buttonText, textX, textY); + +// Save the current state of the context +ctx.save(); + + /* + // Follow Button +const buttonWidth = 60; +const buttonHeight = 20; +const buttonX = width - 100; // Move square 10px to the left +const buttonY = profilePicY + 9; + +// Draw the button rectangle +ctx.fillStyle = '#fff'; +ctx.strokeStyle = '#fff'; +ctx.lineWidth = 1; +ctx.strokeRect(buttonX, buttonY, buttonWidth, buttonHeight); + +// Set the text +const buttonText = this.following ? 'Following' : 'Follow'; +ctx.font = '12px Rokkitt'; +ctx.fillStyle = '#fff'; + +// Measure text width for centering +const textWidth = ctx.measureText(buttonText).width; +const textX = buttonX + (buttonWidth - textWidth) / 2; // Center text horizontally +const textY = buttonY + ((buttonHeight + 12) / 2) - 2; // Center text vertically (approx.) + +// Draw the text +ctx.fillText(buttonText, textX, textY); + + // Save the current state of the context +ctx.save(); +*/ +// Move the canvas origin to the position of the three dots +ctx.translate(width - 25, profilePicY + 13); + +// Rotate the canvas by 90 degrees (clockwise) +ctx.rotate(Math.PI / 2); + +// Draw the three dots at the new origin (0, 0) because the rotation applies to the origin +ctx.font = '18px Rokkitt'; +ctx.fillStyle = '#fff'; +ctx.fillText('•••', 0, 0); + +// Restore the context to its original state +ctx.restore(); + + /* + // Options Dots + ctx.font = '18px Rokkitt'; + ctx.fillStyle = '#fff'; + ctx.fillText('•••', width - 25, profilePicY + 25); +*/ + + // Post Image + const postImage = await loadImage(this.imageUrl); + ctx.drawImage(postImage, 0, headerHeight, width, 400); + + // Footer + const footerY = headerHeight + 400; + ctx.fillStyle = '#000'; + ctx.fillRect(0, footerY, width, height - footerY); + + // --- LIKE ICON (Heart PNG) --- +// Canvas dimensions and other setup code remains unchanged + +// Inside the buildCanvas method... + +// --- LIKE ICON (Heart PNG) --- +const heartImage = await loadImage(likePng(this.liked)); // Replace with the path to your heart PNG image +const heartX = 10; // X position of the heart image +const heartY = footerY + 10; // Y position of the heart image +const heartSize = 30; // Size of the heart image + +// Draw the heart image +ctx.drawImage(heartImage, heartX, heartY, heartSize, heartSize); + +// --- LIKE COUNT (Next to the heart) --- +ctx.font = '20px Rokkitt'; // Font style for like count +ctx.fillStyle = '#fff'; // Text color (white) +const likeCount = this.likes; // Replace with the actual like count +ctx.fillText(likeCount, heartX + heartSize - 3, heartY + 20); // Position the like count to the right of the heart + +// Caption and Time... + +const commentImage = await loadImage(commentPng); // Replace with the path to your heart PNG image +const commentX = 75; // X position of the heart image +const commentY = footerY + 14; // Y position of the heart image +const commentSize = 20; // Size of the heart image + +// Draw the heart image +ctx.drawImage(commentImage, commentX, commentY, commentSize, commentSize); + +// --- LIKE COUNT (Next to the heart) --- +ctx.font = '20px Rokkitt'; // Font style for like count +ctx.fillStyle = '#fff'; // Text color (white) +const commentCount = this.comments; // Replace with the actual like count +ctx.fillText(commentCount, commentX + commentSize + 3, commentY + 16); + + + const shareImage = await loadImage(sharePng); // Replace with the path to your heart PNG image +const shareX = 130; // X position of the heart image +const shareY = footerY + 14; // Y position of the heart image +const shareSize = 18; // Size of the heart image + +// Draw the heart image +ctx.drawImage(shareImage, shareX, shareY, shareSize, shareSize); + +// --- LIKE COUNT (Next to the heart) --- +ctx.font = '20px Rokkitt'; // Font style for like count +ctx.fillStyle = '#fff'; // Text color (white) +const shareCount = this.shares; // Replace with the actual like count +ctx.fillText(shareCount, shareX + shareSize + 3, shareY + 16); + + + + const saveImage = await loadImage(savePng(this.saved)); // Replace with the path to your heart PNG image +const saveX = 365; // X position of the heart image +const saveY = footerY + 14; // Y position of the heart image +const saveSize = 20; // Size of the heart image + +// Draw the heart image +ctx.drawImage(saveImage, saveX, saveY, saveSize, saveSize); + + // Caption + ctx.font = 'bold 15px Rokkitt'; + ctx.fillStyle = '#fff'; + ctx.fillText(this.username, 10, footerY + 55); + + ctx.font = '14px "Rokkitt", "Noto Color Emoji"'; + ctx.fillStyle = '#fff'; + ctx.fillText(this.caption, 70, footerY + 55); + + // Time + ctx.font = '12px Rokkitt'; + ctx.fillStyle = '#888'; + ctx.fillText(this.ago, 10, footerY + 75); + + // Save to file or return buffer + const buffer = canvas.toBuffer(); return buffer; } - } diff --git a/Instagram/test.js b/Instagram/test.js new file mode 100644 index 0000000..8e7155a --- /dev/null +++ b/Instagram/test.js @@ -0,0 +1,68 @@ +import { createCanvas, registerFont } from 'canvas'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +// Register custom font +const fontPath = path.join(__dirname, 'Digital Regular.ttf'); +registerFont(fontPath, { family: 'Digital Regular' }); +const fontPath2 = path.join(__dirname, 'VacerSansThinPersonal.ttf'); +registerFont(fontPath2, { family: 'VacerSansThinPersonal' }); + +/** + * Generate an image buffer for the "System Uptime" design. + * @param {Object} uptime - The uptime data. + * @param {number} uptime.days - Number of days. + * @param {number} uptime.hours - Number of hours. + * @param {number} uptime.minutes - Number of minutes. + * @param {number} uptime.seconds - Number of seconds. + * @returns {Buffer} - The generated image buffer. + */ +export async function generateUptimeImage(uptime) { + const { days, hours, minutes, seconds } = uptime; + + // Canvas setup + const width = 1200; + const height = 400; + const canvas = createCanvas(width, height); + const ctx = canvas.getContext('2d'); + + // Background + ctx.fillStyle = 'black'; + ctx.fillRect(0, 0, width, height); + + // Title text + ctx.fillStyle = '#00ffff'; + ctx.font = '80px "VacerSansThinPersonal"'; + ctx.textAlign = 'center'; + ctx.fillText('SYSTEM UPTIME', width / 2, 80); + + // Time format: 12 34 56 78 + const formattedTime = `${String(days).padStart(2, '0')} ${String(hours).padStart(2, '0')} ${String(minutes).padStart(2, '0')} ${String(seconds).padStart(2, '0')}`; + + // Set font and measure text + ctx.font = '220px "Digital Regular"'; + ctx.textAlign = 'center'; + ctx.textBaseline = 'middle'; // Align text vertically + + // Center the text in the middle of the canvas + ctx.fillText(formattedTime, width / 2, height / 2); + + // Lower labels: DAYS, HOURS, MINUTES, SECONDS + const labels = ['DAYS', 'HOURS', 'MINUTES', 'SECONDS']; + const timeSegments = [days, hours, minutes, seconds]; + const offsetX = -440; // Adjust this value to shift all labels to the left + const segmentPadding = 139; // Spacing between each number and label + ctx.font = '30px "Courier New"'; + ctx.textAlign = 'center'; + + timeSegments.forEach((_, index) => { + const segmentX = width / 2 + offsetX + index * (150 + segmentPadding); + ctx.fillText(labels[index], segmentX, height / 2 + 120); // Place labels below the numbers + }); + + // Return the image buffer + return canvas.toBuffer(); +} diff --git a/api/index.js b/api/index.js new file mode 100644 index 0000000..f8afc74 --- /dev/null +++ b/api/index.js @@ -0,0 +1,18 @@ +import express from 'express'; + +const app = express(); +const PORT = process.env.PORT || 3000; +app.use(express.json()); + +// Routes +import test from '../routers/test.js'; +import InstagramPost from '../routers/instagramPost.js'; +import Test2 from '../routers/test2.js'; + +app.use('/', test); +app.use('/igpost', InstagramPost); +app.use('/test', Test2); + +app.listen(PORT, () => { + console.log(`App is running on port ${PORT}`); +}); diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..85f53b1 --- /dev/null +++ b/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash +apt-get update + +apt-get install -y build-essential \ + libcairo2-dev \ + libpango1.0-dev \ + libjpeg-dev \ + libgif-dev \ + librsvg2-dev \ + libpixman-1-dev + +export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig + +npm install diff --git a/index.js b/index.js deleted file mode 100644 index 2c9448b..0000000 --- a/index.js +++ /dev/null @@ -1,24 +0,0 @@ -import express from 'express'; -import path,{dirname} from 'path'; -import { - fileURLToPath - } from 'url'; - import { - createRequire - } from 'module'; - const __filename = fileURLToPath(import.meta.url); - const __dirname = dirname(fileURLToPath(import.meta.url)) - - const app = express(); - const PORT = process.env.PORT||3000; - - //Routes - import test from './routers/test.js'; - import InstagramPost from './routers/instagramPost.js'; - - app.use('/', test); - app.use('/igpost', InstagramPost); - - app.listen(PORT,()=>{ - console.log(`App is running on port ${PORT}`) - }) diff --git a/package.json b/package.json index 776663e..69d057b 100644 --- a/package.json +++ b/package.json @@ -5,16 +5,19 @@ "description": "***This repo is being developed for free and open-source template generators, specifically developing for serverless platforms like vercel.***", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "node index.js" + "start": "node server.js", + "build": "npm install --build-from-source", + "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { - "cors": "^2.8.5", - "express": "^4.21.2", + "canvas": "^2.11.2", + "express": "^4.19.2", "fs": "^0.0.1-security", + "path": "^0.12.7", + "axios": "^1.7.9", "path": "^0.12.7" } } diff --git a/routers/instgramPost.js b/routers/instagramPost.js similarity index 92% rename from routers/instgramPost.js rename to routers/instagramPost.js index 3e7c2e0..c2ee25e 100644 --- a/routers/instgramPost.js +++ b/routers/instagramPost.js @@ -1,5 +1,6 @@ import express from 'express'; -import InstagramPost from '../InstagramPost'; +import axios from 'axios'; +import InstagramPost from '../Instagram/instgramPost.js'; import { Buffer } from 'buffer'; const router = express.Router(); @@ -116,9 +117,10 @@ router.post('/', async (req, res) => { } } else { try { - const response = await fetch(image); - imageBuffer = await response.buffer(); + const response = await axios.get(image, { responseType: 'arraybuffer' }); + imageBuffer = response.data; } catch (err) { + console.log(err); return res.status(400).json({ status: false, code: 400, @@ -128,7 +130,7 @@ router.post('/', async (req, res) => { } try { - const buffer = await new InstagramPost() + const post = await new InstagramPost() .isFollowing(following) .isVerified(verified) .setPfp(pfp) @@ -141,8 +143,8 @@ router.post('/', async (req, res) => { .setCaption(caption) .setAgo(ago) .isLiked(liked) - .setImage(imageBuffer) - .buildCanvas(); + .setImage(imageBuffer); + const buffer = await post.buildCanvas(); res.set("Content-Type", "image/png"); return res.send(buffer); } catch (error) { diff --git a/routers/test2.js b/routers/test2.js new file mode 100644 index 0000000..bb2300d --- /dev/null +++ b/routers/test2.js @@ -0,0 +1,23 @@ +import express from 'express'; +import { generateUptimeImage } from '../Instagram/test.js'; + +const router = express.Router(); + +router.use('/', async (req, res) => { + try { + // Example uptime data + const uptimeData = { days: 2, hours: 30, minutes: 56, seconds: 0 }; + + // Generate the image buffer + const imageBuffer = await generateUptimeImage(uptimeData); + + // Set headers and send the image + res.setHeader('Content-Type', 'image/png'); + res.send(imageBuffer); + } catch (error) { + console.error('Error generating uptime image:', error); + res.status(500).send('Internal Server Error'); + } +}); + +export default router; diff --git a/vercel.json b/vercel.json index 39d158d..bd87632 100644 --- a/vercel.json +++ b/vercel.json @@ -1,14 +1,14 @@ { - "routes": [ - { - "src": "/(.*)", - "dest": "index.js" - } - ], - "functions": { - "api/index.js": { - "maxDuration": 60 - - } + "version": 2, + "buildCommand": "./build.sh", + "builds": [ + { + "src": "api/*.js", + "use": "@vercel/node" } - } \ No newline at end of file + ], + "routes": [ + { "handle": "filesystem" }, + { "src": "/(.*)", "dest": "api/index.js" } + ] +}