working apache logic
This commit is contained in:
parent
bc63d15636
commit
a315c3e6b7
95
lib/apache_functions.js
Normal file
95
lib/apache_functions.js
Normal file
@ -0,0 +1,95 @@
|
||||
const { actions, configs } = require('apache-api');
|
||||
|
||||
const { getStreamsNew } = require('../routes/getStreams')
|
||||
|
||||
apache_config = 'tv.k-world'
|
||||
|
||||
async function get_config() {
|
||||
return await configs.readConfig(apache_config, true, true)
|
||||
}
|
||||
|
||||
async function split_streams(siteList) {
|
||||
const notUndefined = anyValue => typeof anyValue !== 'undefined'
|
||||
|
||||
final_array = siteList.map(function (item) {
|
||||
if (item.content.includes('Redirect')) {
|
||||
// console.log(item)
|
||||
var cleanString = item.content.replace(/^(.*?)\//g, "");
|
||||
cleanString = cleanString.split(' ')
|
||||
cleanString[1] = cleanString[1].replace(/"/g, "")
|
||||
// console.log(cleanString)
|
||||
return cleanString
|
||||
}
|
||||
}).filter(notUndefined)
|
||||
return final_array
|
||||
}
|
||||
|
||||
// async function updateStream(sub, oldUrl, newUrl) {
|
||||
// config = await get_config()
|
||||
// config.children[0].children.map(function (item) {
|
||||
// // string = `Redirect 302 /${sub} "${oldUrl}"`
|
||||
// if (item.content.includes(oldUrl)) {
|
||||
// console.log('found')
|
||||
// return item.content = `Redirect 302 /${sub} "${newUrl}"`
|
||||
// }
|
||||
// })
|
||||
// try {
|
||||
// await configs.saveConfig(apache_config, config, true, true)
|
||||
// } catch (error) {
|
||||
// console.log(error)
|
||||
// }
|
||||
// await actions.restartApache()
|
||||
// }
|
||||
|
||||
async function checkExists(fullStreamList, mappedStreams) {
|
||||
newstreams = mappedStreams.map(function (s) {
|
||||
return s[1]
|
||||
})
|
||||
// console.log(newstreams)
|
||||
myArray = fullStreamList.filter(function (el) {
|
||||
return newstreams.indexOf(el) < 0;
|
||||
});
|
||||
if (myArray.length == 0) {
|
||||
console.log('No new streams')
|
||||
} else {
|
||||
console.log('New streams ' + myArray)
|
||||
}
|
||||
return myArray
|
||||
}
|
||||
|
||||
function makeid() {
|
||||
var result = '';
|
||||
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
var charactersLength = characters.length;
|
||||
for (var i = 0; i < 5; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() *
|
||||
charactersLength));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
async function addNewStreams(config, streamList) {
|
||||
streamList.forEach(stream => {
|
||||
config.children[0].children.push({ "tagName": '$rule', "content": `Redirect 302 /${makeid()} "${stream}"` })
|
||||
})
|
||||
try {
|
||||
await configs.saveConfig(apache_config, config, true, true)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
await actions.restartApache()
|
||||
}
|
||||
|
||||
// update('DIAZ', 'http://google.com', 'https://watchtower.ddns.net:8443')
|
||||
|
||||
|
||||
async function main() {
|
||||
streams = await getStreamsNew()
|
||||
a = await get_config()
|
||||
b = await split_streams(a.children[0].children)
|
||||
c = await checkExists(streams, b)
|
||||
d = await addNewStreams(a, c)
|
||||
}
|
||||
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user