change http urls to https

This commit is contained in:
catarak 2016-09-08 22:02:42 -04:00
parent 0e0d3975e1
commit b004fd077f
2 changed files with 56 additions and 36 deletions

View file

@ -3,6 +3,7 @@ import { createFile } from './files';
const textFileRegex = /text\//; const textFileRegex = /text\//;
const s3Bucket = `http://${process.env.S3_BUCKET}.s3.amazonaws.com/`; const s3Bucket = `http://${process.env.S3_BUCKET}.s3.amazonaws.com/`;
const s3BucketHttps = `https://s3-us-west-2.amazonaws.com/${process.env.S3_BUCKET}/`;
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
function localIntercept(file, options = {}) { function localIntercept(file, options = {}) {
@ -94,22 +95,22 @@ export function dropzoneCompleteCallback(file) {
url: `${s3Bucket}${file.postData.key}`, url: `${s3Bucket}${file.postData.key}`,
originalFilename: file.name originalFilename: file.name
}; };
console.log(json, JSON.stringify(json), JSON.stringify(json).replace('"', '\\"')); // console.log(json, JSON.stringify(json), JSON.stringify(json).replace('"', '\\"'));
inputHidden += `${window.btoa(JSON.stringify(json))}" />`; inputHidden += `${window.btoa(JSON.stringify(json))}" />`;
// document.getElementById('uploader').appendChild(inputHidden); // document.getElementById('uploader').appendChild(inputHidden);
document.getElementById('uploader').innerHTML += inputHidden; document.getElementById('uploader').innerHTML += inputHidden;
const formParams = { const formParams = {
name: file.name, name: file.name,
url: `${s3Bucket}${file.postData.key}` url: `${s3BucketHttps}${file.postData.key}`
}; };
console.log(formParams);
createFile(formParams)(dispatch, getState); createFile(formParams)(dispatch, getState);
} else { } else {
const formParams = { const formParams = {
name: file.name, name: file.name,
content: file.content content: file.content
}; };
console.log(formParams);
createFile(formParams)(dispatch, getState); createFile(formParams)(dispatch, getState);
} }
}; };

View file

@ -8,41 +8,41 @@ mongoose.connection.on('error', () => {
import Project from '../models/project'; import Project from '../models/project';
let projectsNotToUpdate; // let projectsNotToUpdate;
Project.find({'files.name': 'root'}) // Project.find({'files.name': 'root'})
.exec((err, projects) => { // .exec((err, projects) => {
projectsNotToUpdate = projects.map(project => project.id); // projectsNotToUpdate = projects.map(project => project.id);
console.log(projectsNotToUpdate); // console.log(projectsNotToUpdate);
Project.find({}) // Project.find({})
.exec((err, projects) => { // .exec((err, projects) => {
projects.forEach( (project, projectIndex) => { // projects.forEach( (project, projectIndex) => {
if (!projectsNotToUpdate.find(projectId => projectId === project.id)) { // if (!projectsNotToUpdate.find(projectId => projectId === project.id)) {
const childIdArray = project.files.map(file => file._id.valueOf()); // const childIdArray = project.files.map(file => file._id.valueOf());
const newId = new ObjectId(); // const newId = new ObjectId();
project.files.push({ // project.files.push({
name: 'root', // name: 'root',
_id: newId, // _id: newId,
id: newId, // id: newId,
fileType: 'folder', // fileType: 'folder',
children: childIdArray, // children: childIdArray,
content: '' // content: ''
}); // });
project.files = project.files.map(file => { // project.files = project.files.map(file => {
if (file.name === "sketch.js") { // if (file.name === "sketch.js") {
file.isSelected = true; // file.isSelected = true;
return file; // return file;
} // }
return file; // return file;
}); // });
project.save((err, savedProject) => { // project.save((err, savedProject) => {
console.log('project', projectIndex, 'is saved.'); // console.log('project', projectIndex, 'is saved.');
}); // });
} // }
}); // });
}); // });
}); // });
// Project.find({'files.name': 'root'}) // Project.find({'files.name': 'root'})
// .exec((err, projects) => { // .exec((err, projects) => {
@ -64,5 +64,24 @@ Project.find({'files.name': 'root'})
// }); // });
// }); // });
const s3Bucket = `http://p5.js-webeditor.s3.amazonaws.com/`;
const s3BucketHttps = `https://s3-us-west-2.amazonaws.com/p5.js-webeditor/`;
Project.find({})
.exec((err, projects) => {
projects.forEach((project, projectIndex) => {
project.files.forEach((file) => {
if (file.url) {
file.url = file.url.replace(s3Bucket, s3BucketHttps);
console.log('Updating', file.name);
console.log(file.url);
}
});
project.save((err, savedProject) => {
console.log('project', projectIndex, 'is saved.');
});
});
});