/** * Returns filename, encoded in url * @param {string} url - url of file * @return {string} filename, saved at Firebase */ decodeUrl(url) { const decoded = urlParse(querystring.unescape(url)); if (decoded.hostname !== hostName) { throw new APIError('Provided url is not an url of Firebase resource', httpStatus.BAD_REQUEST, true); } else if (regexForAppId.exec(decoded.pathname)[1] !== this.bucketName) { throw new APIError('Provided url is not an url of this Firebase project', httpStatus.BAD_REQUEST, true); } else if (!regexForFileId.test(decoded.pathname)) { throw new APIError('Provided url does not contain file ID', httpStatus.BAD_REQUEST, true); } return regexForFileId.exec(decoded.pathname)[1]; }
const getData = (config, type, device) => { const url = getUrl(config, type, device); const arrUrl = urlParse(url); let filename; if (device.vendor === 'panasonic') { filename = 'Config{mac}.xml'; } else if (device.vendor === 'fanvil') { filename = '{mac}.cfg'; } return { url, protocol: arrUrl['protocol'], server: arrUrl['hostname'], qs: arrUrl['pathname'], filename, }; }