2017-12-27 02:43:43 +00:00
|
|
|
/* eslint-disable */
|
2020-02-25 22:14:50 +00:00
|
|
|
import s3 from '@auth0/s3';
|
2017-12-27 02:43:43 +00:00
|
|
|
import path from 'path';
|
|
|
|
import mongoose from 'mongoose';
|
|
|
|
import User from '../models/user';
|
|
|
|
import Project from '../models/project';
|
2017-12-27 17:04:52 +00:00
|
|
|
import async from 'async';
|
2017-12-27 02:43:43 +00:00
|
|
|
require('dotenv').config({path: path.resolve('.env')});
|
|
|
|
mongoose.connect('mongodb://localhost:27017/p5js-web-editor');
|
|
|
|
mongoose.connection.on('error', () => {
|
|
|
|
console.error('MongoDB Connection Error. Please make sure that MongoDB is running.');
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
|
2017-12-27 02:50:45 +00:00
|
|
|
// let client = s3.createClient({
|
|
|
|
// maxAsyncS3: 20,
|
|
|
|
// s3RetryCount: 3,
|
|
|
|
// s3RetryDelay: 1000,
|
|
|
|
// multipartUploadThreshold: 20971520, // this is the default (20 MB)
|
|
|
|
// multipartUploadSize: 15728640, // this is the default (15 MB)
|
|
|
|
// s3Options: {
|
|
|
|
// accessKeyId: `${process.env.AWS_ACCESS_KEY}`,
|
|
|
|
// secretAccessKey: `${process.env.AWS_SECRET_KEY}`,
|
|
|
|
// region: `${process.env.AWS_REGION}`
|
|
|
|
// },
|
|
|
|
// });
|
2017-12-27 02:43:43 +00:00
|
|
|
|
2017-12-27 17:29:36 +00:00
|
|
|
const CHUNK = 100;
|
2017-12-27 02:55:56 +00:00
|
|
|
Project.count({})
|
2017-12-27 17:22:12 +00:00
|
|
|
.exec().then((numProjects) => {
|
2017-12-27 03:08:20 +00:00
|
|
|
console.log(numProjects);
|
2017-12-27 17:18:23 +00:00
|
|
|
let index = 0;
|
|
|
|
async.whilst(
|
|
|
|
() => {
|
|
|
|
return index < numProjects;
|
|
|
|
},
|
|
|
|
(whilstCb) => {
|
2017-12-27 17:19:53 +00:00
|
|
|
Project.find({}).skip(index).limit(CHUNK).exec((err, projects) => {
|
|
|
|
async.eachSeries(projects, (project, cb) => {
|
2017-12-27 17:29:36 +00:00
|
|
|
console.log(project.name);
|
2017-12-27 17:19:53 +00:00
|
|
|
async.eachSeries(project.files, (file, fileCb) => {
|
2018-01-09 21:12:02 +00:00
|
|
|
if (file.url && file.url.includes('s3-us-west-2.amazonaws.com/')) {
|
|
|
|
file.url = file.url.replace('s3-us-west-2.amazonaws.com/', '');
|
2017-12-27 17:19:53 +00:00
|
|
|
project.save((err, newProject) => {
|
|
|
|
console.log(`updated file ${file.url}`);
|
|
|
|
fileCb();
|
|
|
|
});
|
|
|
|
} else {
|
2017-12-27 17:18:23 +00:00
|
|
|
fileCb();
|
2017-12-27 17:19:53 +00:00
|
|
|
}
|
|
|
|
}, () => {
|
|
|
|
cb();
|
|
|
|
});
|
2017-12-27 17:29:36 +00:00
|
|
|
}, () => {
|
|
|
|
index += CHUNK;
|
|
|
|
whilstCb();
|
2017-12-27 17:18:23 +00:00
|
|
|
});
|
2017-12-27 03:17:53 +00:00
|
|
|
});
|
2017-12-27 17:18:23 +00:00
|
|
|
},
|
|
|
|
() => {
|
|
|
|
console.log('finished processing all documents.')
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
);
|
2017-12-27 02:55:56 +00:00
|
|
|
});
|