stream-api/backend/seafile.js

59 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-09-05 12:55:57 +00:00
#!/usr/bin/env node
const esprima = require('esprima');
const cheerio = require('cheerio');
const axios = require('axios');
let url = null;
for(let i=0; i<process.argv.length; i++) {
const arg = process.argv[i];
if(arg.startsWith("http://") || arg.startsWith("https://")) {
url = arg;
}
}
if(url !== null) {
axios.get(url).then((resp) => {
const dom = cheerio.load(resp.data, {xmlMode: false});
const tags = dom('script').get();
const data = {};
let props = [];
for(let i=0; i<tags.length; i++) {
const children = tags[i].children;
for(let j=0; j<children.length; j++) {
let tdata = {};
let assign = true;
try {
tdata = children[j].data;
} catch(err) {
assign = false;
console.log(err);
}
if(assign) {
const script = esprima.parseScript(tdata);
for(let k=0; k<script.body.length; k++) {
const prop = script.body[k].expression.right.properties;
for(let l=0; l<prop.length; l++) {
props = [...props, ...(prop[l].value.properties)];
}
}
}
}
}
for(let i=0; i<props.length; i++) {
const prop = props[i];
2021-09-06 07:02:36 +00:00
if((prop.key.type === "Identifier") && (prop.value.type === "Literal")) {
data[prop.key.name] = prop.value.value;
}
}
for(let i=0; i<props.length; i++) {
const prop = props[i];
const valid = (new Boolean(prop.value.value)).valueOf();
if((prop.key.type === "Identifier") && (prop.value.type === "Literal") && valid) {
2021-09-05 12:55:57 +00:00
data[prop.key.name] = prop.value.value;
}
}
console.log(JSON.stringify(data));
})
}