Skip to content

Commit e7d90bc

Browse files
committed
https://github.com/haxtheweb/issues/issues/2170
1 parent 6653259 commit e7d90bc

File tree

2,099 files changed

+6497
-388444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,099 files changed

+6497
-388444
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
"dependencies": {
4747
"archiver": "7.0.1",
48+
"axios": "1.7.8",
4849
"cookie-parser": "1.4.6",
4950
"dotenv": "16.4.5",
5051
"express": "4.19.2",

src/lib/HAXCMSFile.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path');
22
const fs = require('fs-extra');
3+
const Axios = require('axios')
34
const { HAXCMS } = require('./HAXCMS.js');
45
const mime = require('mime');
56
const sharp = require('sharp');
@@ -22,13 +23,21 @@ class HAXCMSFile
2223
fs.mkdirSync(pathPart);
2324
}
2425
// ensure name does not exist already
25-
if (await fs.existsSync(path.join(pathPart, tmpFile.name))) {
26+
if (fs.existsSync(path.join(pathPart, tmpFile.name))) {
2627
tmpFile.name = tmpFile.filename + '-' + tmpFile.originalname;
2728
}
29+
// save operations that are not bulk import need - path cleaning
2830
tmpFile.name = tmpFile.name.replace(/[/\\?%*:|"<>\s]/g, '-');
29-
let fullpath = pathPart + tmpFile['name'];
31+
let fullpath = path.join(pathPart, tmpFile.name);
32+
console.log(fullpath);
3033
try {
31-
await fs.moveSync(filedata, fullpath);
34+
// support file saves from remote sources
35+
if (filedata.startsWith('https://') || filedata.startsWith('http://')) {
36+
downloadAndSaveFile(filedata, fullpath);
37+
}
38+
else {
39+
fs.moveSync(filedata, fullpath);
40+
}
3241
}
3342
catch(err) {
3443
console.warn(err);
@@ -63,7 +72,7 @@ class HAXCMSFile
6372
// fake the file object creation stuff from CMS land
6473
returnData = {
6574
'file': {
66-
'path': path + tmpFile['name'],
75+
'path': fullpath,
6776
'fullUrl':
6877
HAXCMS.basePath +
6978
pathPart +
@@ -79,7 +88,7 @@ class HAXCMSFile
7988
// fake the file object creation stuff from CMS land
8089
returnData = {
8190
'file':{
82-
'path':path + tmpFile['name'],
91+
'path': fullpath,
8392
'fullUrl' :
8493
HAXCMS.basePath +
8594
pathPart +
@@ -126,4 +135,17 @@ class HAXCMSFile
126135
}
127136
}
128137

138+
async function downloadAndSaveFile(url, filepath) {
139+
const response = await Axios({
140+
url,
141+
method: 'GET',
142+
responseType: 'stream'
143+
});
144+
return new Promise((resolve, reject) => {
145+
response.data.pipe(fs.createWriteStream(filepath))
146+
.on('error', reject)
147+
.once('close', () => resolve(filepath));
148+
});
149+
}
150+
129151
module.exports = HAXCMSFile;

src/public/VERSION.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9.0.16
1+
9.0.21

src/public/build/es6/build.js

+1-35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/build/es6/dist/app.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
// build default for all our properties is for CMSs other than HAXcms
2-
// HAXcms will tack onto this routine through another method if integration
3-
// that is similar
4-
import "./build-cms.js";
1+
import"./build-cms.js";

src/public/build/es6/dist/build-cms.js

+1-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/build/es6/dist/build-full.js

+1-86
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
import "../node_modules/@haxtheweb/haxcms-elements/lib/core/haxcms-site-builder.js";
2-
// this can be used for customizations / additional elements to get pulled in
3-
// this assumes you're operating in a bit of a pro mode where you know to compile
4-
// via polymer build and that you're managing your own fork of the package.json we ship
1+
import"../node_modules/@haxtheweb/haxcms-elements/lib/core/haxcms-site-builder.js";
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import "../node_modules/@haxtheweb/app-hax/app-hax.js";
1+
import"../node_modules/@haxtheweb/app-hax/app-hax.js";

0 commit comments

Comments
 (0)