Created
October 8, 2022 05:28
-
-
Save ktwrd/4700deda0e87abfc14818c068546d039 to your computer and use it in GitHub Desktop.
Fetch Support Downloads for unlisted Acer Products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Requirements | |
- node.js >16 | |
- axios | |
- fast-xml-parser | |
*/ | |
// Acer Predator PH315-52 | |
const targetProductId = '7983' | |
const axios = require('axios') | |
const { XMLParser, XMLBuilder, XMLValidator} = require('fast-xml-parser'); | |
const baseUrl = 'https://www.acer.com/wjws/ws/gdp/allfiles/en/US/10M1/latest/%productId%/-?cross=false' | |
const urlBuilder = (productId) => | |
{ | |
return baseUrl.replaceAll('%productId%', productId) | |
} | |
const parser = new XMLParser() | |
const fetchProductData = async (productId) => | |
{ | |
let req = await axios.get(urlBuilder(productId)) | |
let stringBody = req.data | |
if (typeof stringBody == 'object') | |
{ | |
if (stringBody.Files == undefined) | |
{ | |
throw new Error(`Key 'Files' could not be found in body.`) | |
} | |
return stringBody.Files | |
} | |
let xmlParsed = parser.parse(stringBody) | |
if (xmlParsed['ns2:Files'] == undefined) | |
{ | |
throw new Error(`Key 'ns2:Files' could not be found in body.`) | |
} | |
return xmlParsed['ns2:Files'] | |
} | |
const fetchDownloadUrls = async (productId) => { | |
let data = await fetchProductData(productId) | |
let response = [] | |
for (let file of data.File) | |
{ | |
let urlString = file.Link | |
if (file.Link.startsWith('//')) | |
urlString = 'http:' + file.Link | |
let url = new URL(urlString) | |
let pushData = { | |
url: url.toString(), | |
filename: file.FileName, | |
size: file.Size, | |
verison: file.Version, | |
date: file.Date, | |
description: file.Description | |
} | |
response.push(pushData) | |
} | |
return response | |
} | |
fetchDownloadUrls(targetProductId).then(data => console.log(JSON.stringify(data, null, ' '))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment