Skip to content

Commit

Permalink
https://github.com/haxtheweb/issues/issues/2170
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed Nov 26, 2024
1 parent 6653259 commit e7d90bc
Show file tree
Hide file tree
Showing 2,099 changed files with 6,497 additions and 388,444 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
},
"dependencies": {
"archiver": "7.0.1",
"axios": "1.7.8",
"cookie-parser": "1.4.6",
"dotenv": "16.4.5",
"express": "4.19.2",
Expand Down
32 changes: 27 additions & 5 deletions src/lib/HAXCMSFile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const fs = require('fs-extra');
const Axios = require('axios')
const { HAXCMS } = require('./HAXCMS.js');
const mime = require('mime');
const sharp = require('sharp');
Expand All @@ -22,13 +23,21 @@ class HAXCMSFile
fs.mkdirSync(pathPart);
}
// ensure name does not exist already
if (await fs.existsSync(path.join(pathPart, tmpFile.name))) {
if (fs.existsSync(path.join(pathPart, tmpFile.name))) {
tmpFile.name = tmpFile.filename + '-' + tmpFile.originalname;
}
// save operations that are not bulk import need - path cleaning
tmpFile.name = tmpFile.name.replace(/[/\\?%*:|"<>\s]/g, '-');
let fullpath = pathPart + tmpFile['name'];
let fullpath = path.join(pathPart, tmpFile.name);
console.log(fullpath);
try {
await fs.moveSync(filedata, fullpath);
// support file saves from remote sources
if (filedata.startsWith('https://') || filedata.startsWith('http://')) {
downloadAndSaveFile(filedata, fullpath);
}
else {
fs.moveSync(filedata, fullpath);
}
}
catch(err) {
console.warn(err);
Expand Down Expand Up @@ -63,7 +72,7 @@ class HAXCMSFile
// fake the file object creation stuff from CMS land
returnData = {
'file': {
'path': path + tmpFile['name'],
'path': fullpath,
'fullUrl':
HAXCMS.basePath +
pathPart +
Expand All @@ -79,7 +88,7 @@ class HAXCMSFile
// fake the file object creation stuff from CMS land
returnData = {
'file':{
'path':path + tmpFile['name'],
'path': fullpath,
'fullUrl' :
HAXCMS.basePath +
pathPart +
Expand Down Expand Up @@ -126,4 +135,17 @@ class HAXCMSFile
}
}

async function downloadAndSaveFile(url, filepath) {
const response = await Axios({
url,
method: 'GET',
responseType: 'stream'
});
return new Promise((resolve, reject) => {
response.data.pipe(fs.createWriteStream(filepath))
.on('error', reject)
.once('close', () => resolve(filepath));
});
}

module.exports = HAXCMSFile;
2 changes: 1 addition & 1 deletion src/public/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0.16
9.0.21
36 changes: 1 addition & 35 deletions src/public/build/es6/build.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions src/public/build/es6/dist/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
// build default for all our properties is for CMSs other than HAXcms
// HAXcms will tack onto this routine through another method if integration
// that is similar
import "./build-cms.js";
import"./build-cms.js";
9 changes: 1 addition & 8 deletions src/public/build/es6/dist/build-cms.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 1 addition & 86 deletions src/public/build/es6/dist/build-full.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions src/public/build/es6/dist/build-haxcms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import "../node_modules/@haxtheweb/haxcms-elements/lib/core/haxcms-site-builder.js";
// this can be used for customizations / additional elements to get pulled in
// this assumes you're operating in a bit of a pro mode where you know to compile
// via polymer build and that you're managing your own fork of the package.json we ship
import"../node_modules/@haxtheweb/haxcms-elements/lib/core/haxcms-site-builder.js";
2 changes: 1 addition & 1 deletion src/public/build/es6/dist/build-home.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import "../node_modules/@haxtheweb/app-hax/app-hax.js";
import"../node_modules/@haxtheweb/app-hax/app-hax.js";
Loading

0 comments on commit e7d90bc

Please sign in to comment.