From b004fd077fcba13c7f8543bdedb91f791953d53e Mon Sep 17 00:00:00 2001 From: catarak Date: Thu, 8 Sep 2016 22:02:42 -0400 Subject: [PATCH] change http urls to https --- client/modules/IDE/actions/uploader.js | 7 ++- server/utils/db_reformat.js | 85 ++++++++++++++++---------- 2 files changed, 56 insertions(+), 36 deletions(-) diff --git a/client/modules/IDE/actions/uploader.js b/client/modules/IDE/actions/uploader.js index 44173a59..23e77265 100644 --- a/client/modules/IDE/actions/uploader.js +++ b/client/modules/IDE/actions/uploader.js @@ -3,6 +3,7 @@ import { createFile } from './files'; const textFileRegex = /text\//; 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'; function localIntercept(file, options = {}) { @@ -94,22 +95,22 @@ export function dropzoneCompleteCallback(file) { url: `${s3Bucket}${file.postData.key}`, 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))}" />`; // document.getElementById('uploader').appendChild(inputHidden); document.getElementById('uploader').innerHTML += inputHidden; const formParams = { name: file.name, - url: `${s3Bucket}${file.postData.key}` + url: `${s3BucketHttps}${file.postData.key}` }; + console.log(formParams); createFile(formParams)(dispatch, getState); } else { const formParams = { name: file.name, content: file.content }; - console.log(formParams); createFile(formParams)(dispatch, getState); } }; diff --git a/server/utils/db_reformat.js b/server/utils/db_reformat.js index a709ca02..cdc9c2b2 100644 --- a/server/utils/db_reformat.js +++ b/server/utils/db_reformat.js @@ -8,41 +8,41 @@ mongoose.connection.on('error', () => { import Project from '../models/project'; -let projectsNotToUpdate; -Project.find({'files.name': 'root'}) - .exec((err, projects) => { - projectsNotToUpdate = projects.map(project => project.id); - console.log(projectsNotToUpdate); +// let projectsNotToUpdate; +// Project.find({'files.name': 'root'}) +// .exec((err, projects) => { +// projectsNotToUpdate = projects.map(project => project.id); +// console.log(projectsNotToUpdate); - Project.find({}) - .exec((err, projects) => { - projects.forEach( (project, projectIndex) => { - if (!projectsNotToUpdate.find(projectId => projectId === project.id)) { - const childIdArray = project.files.map(file => file._id.valueOf()); - const newId = new ObjectId(); - project.files.push({ - name: 'root', - _id: newId, - id: newId, - fileType: 'folder', - children: childIdArray, - content: '' - }); +// Project.find({}) +// .exec((err, projects) => { +// projects.forEach( (project, projectIndex) => { +// if (!projectsNotToUpdate.find(projectId => projectId === project.id)) { +// const childIdArray = project.files.map(file => file._id.valueOf()); +// const newId = new ObjectId(); +// project.files.push({ +// name: 'root', +// _id: newId, +// id: newId, +// fileType: 'folder', +// children: childIdArray, +// content: '' +// }); - project.files = project.files.map(file => { - if (file.name === "sketch.js") { - file.isSelected = true; - return file; - } - return file; - }); - project.save((err, savedProject) => { - console.log('project', projectIndex, 'is saved.'); - }); - } - }); - }); - }); +// project.files = project.files.map(file => { +// if (file.name === "sketch.js") { +// file.isSelected = true; +// return file; +// } +// return file; +// }); +// project.save((err, savedProject) => { +// console.log('project', projectIndex, 'is saved.'); +// }); +// } +// }); +// }); +// }); // Project.find({'files.name': 'root'}) // .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.'); + }); + }); + }); +