Skip to content

Commit

Permalink
fix: disable uploading to custom server by default, upload to cloud i…
Browse files Browse the repository at this point in the history
…nstead unless viewerOrigin is defined
  • Loading branch information
popstas committed Apr 5, 2024
1 parent 633e05d commit 3ddbb79
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/actions/saveAsJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export default async ({csvPath, jsonPath, lang, preset, defaultFilter, url, args
}

// filter empty redirected items
console.log("data.items before filter:", data.items.length);
// console.log("data.items before filter:", data.items.length);
data.items = filterItems(data.items);

// write
const raw = JSON.stringify(data);
fs.writeFileSync(jsonPath, raw);

const msg = `Saved ${data.items.length} items` + (itemsPartial.length > 0 ? `, including ${itemsPartial.length} previous items` : '');
console.log("saveAsJson:", msg);
console.log(msg);

return data;
}
Expand Down
10 changes: 5 additions & 5 deletions src/actions/startViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export default async (jsonPath, webPath = false) => {
}

function outLinks(url) {
console.log(`JSON file: ${url}`);
// console.log(`JSON file: ${url}`);
// console.log('');
// console.log(`Dev viewer: http://localhost:3000/?url=${url}`);
// console.log(`Short link: ${viewerOrigin}/?url=${url}`);
console.log('');
console.log(`Dev viewer: http://localhost:3000/?url=${url}`);
console.log(`Short link: ${viewerOrigin}/?url=${url}`);
console.log('');
console.log(`Online viewer: ${onlineViewLink(url)}`);
console.log(`Report link: ${onlineViewLink(url)}`);
//console.log(`Public viewer: ${onlineViewLink(url.replace(`http://localhost:${port}`, 'https://3001.home.popstas.ru'))}`);
console.log('');
}
Expand Down
44 changes: 25 additions & 19 deletions src/actions/uploadJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,41 @@ export default async (jsonPath) => {

const uploadName = getJsonName(jsonPath);

const viewerOrigin = config.viewerOrigin || 'https://site-audit.viasite.ru';
const viewerOrigin = config.viewerOrigin || ""; //'https://site-audit.viasite.ru';
const uploadOrigin = config.uploadOrigin || `${viewerOrigin}`;
const uploadUrl = `${uploadOrigin}/upload/`;
const uploadUrl = uploadOrigin ? `${uploadOrigin}/upload/` : "";

console.log(`Uploading to ${uploadUrl}...`);
const res = await axios.post(`${uploadUrl}`, {
name: uploadName,
data: data,
upload_origin: uploadOrigin,
});
let uploadedUrl;

if (res.status !== 200 || !res.data.url) {
console.error('Failed to upload file!');
return jsonPath;
}
if (uploadUrl) {
console.log(`Uploading to ${uploadUrl}...`);
const res = await axios.post(`${uploadUrl}`, {
name: uploadName,
data: data,
upload_origin: uploadOrigin,
});

let uploadedUrl = res.data.url;
try {
uploadedUrl = await uploadToCloud(jsonPath);
} catch(e) {
console.error('Failed to upload to cloud!');
console.error(e);
if (res.status !== 200 || !res.data.url) {
console.error('Failed to upload file!');
return jsonPath;
}

uploadedUrl = res.data.url;
}
else {
try {
console.log("Uploading to cloud...");
uploadedUrl = await uploadToCloud(jsonPath);
} catch(e) {
console.error('Failed to upload to cloud!');
console.error(e);
}
}

return uploadedUrl;
};

async function uploadToCloud(jsonPath) {
console.log("uploadToCloud:", jsonPath);
const uploadUrl = config.uploadUrl;
if (!uploadUrl) return;

Expand Down

0 comments on commit 3ddbb79

Please sign in to comment.