ig.rizaldy.club/remoteOptimizedImages.js

43 lines
1.2 KiB
JavaScript

const config = require("./config.json");
const minio = require("minio");
const xml2json = require("xml2json");
const minioEndpoint = process.env.MINIO_ENDPOINT;
const minioBucket = process.env.MINIO_BUCKET;
const mc = new minio.Client({
endPoint: minioEndpoint,
accessKey: process.env.MINIO_ACCESS_KEY,
secretKey: process.env.MINIO_SECRET_KEY,
});
const minioObjects = new Promise((resolve, reject) => {
const data = [];
const stream = mc.listObjectsV2(minioBucket, "photos", true, "");
stream.on("data", (obj) => data.push(obj.name));
stream.on("error", reject);
stream.on("end", () => {
resolve(data);
});
}).then((data) => {
return data.map((id) => `https://${minioEndpoint}/${minioBucket}/${id}`);
});
const getPeertubeFeeds = fetch(process.env.PEERTUBE_FEED_URL)
.then((res) => res.text())
.then((payload) => {
const peertubeFeedsJSON = xml2json.toJson(payload, { object: true });
const peertubeItems = peertubeFeedsJSON.rss.channel.item;
const videos = peertubeItems.map((item) => item["media:thumbnail"][0].url);
return videos;
});
module.exports = Promise.all([minioObjects, getPeertubeFeeds]).then((data) => {
return [...data[0], ...data[1], config.navbar.logo, config.profile.avatar];
});