mirror of
https://git.sanhost.net/sanasol/hytale-f2p
synced 2026-02-26 11:41:49 -03:00
refactor: split main file into smaller modules for better maintainability
This commit is contained in:
31
backend/services/newsManager.js
Normal file
31
backend/services/newsManager.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const axios = require('axios');
|
||||
|
||||
async function getHytaleNews() {
|
||||
try {
|
||||
const response = await axios.get('https://launcher.hytale.com/launcher-feed/release/feed.json', {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
||||
},
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
const articles = response.data.articles || [];
|
||||
return articles.map(article => ({
|
||||
title: article.title || '',
|
||||
description: article.description || '',
|
||||
destUrl: article.dest_url || '',
|
||||
imageUrl: article.image_url ?
|
||||
(article.image_url.startsWith('http') ?
|
||||
article.image_url :
|
||||
`https://launcher.hytale.com/launcher-feed/release/${article.image_url}`
|
||||
) : ''
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch news:', error.message);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getHytaleNews
|
||||
};
|
||||
Reference in New Issue
Block a user