Merge branch 'fix-char-restriction' of git://github.com/GaurangTandon/p5.js-web-editor into GaurangTandon-fix-char-restriction
This commit is contained in:
commit
4dcec4baa8
3 changed files with 40 additions and 17 deletions
|
@ -4,6 +4,7 @@ import moment from 'moment';
|
|||
import isUrl from 'is-url';
|
||||
import slugify from 'slugify';
|
||||
import jsdom, { serializeDocument } from 'jsdom';
|
||||
import generateFileSystemSafeName from '../utils/generateFileSystemSafeName';
|
||||
import Project from '../models/project';
|
||||
import User from '../models/user';
|
||||
import { deleteObjectsFromS3, getObjectKey } from './aws.controller';
|
||||
|
@ -295,7 +296,7 @@ function buildZip(project, req, res) {
|
|||
|
||||
const currentTime = moment().format('YYYY_MM_DD_HH_mm_ss');
|
||||
project.slug = slugify(project.name, '_');
|
||||
res.attachment(`${project.slug}_${currentTime}.zip`);
|
||||
res.attachment(`${generateFileSystemSafeName(project.slug)}_${currentTime}.zip`);
|
||||
zip.pipe(res);
|
||||
|
||||
function addFileToZip(file, path) {
|
||||
|
|
|
@ -4,14 +4,17 @@ import slugify from 'slugify';
|
|||
|
||||
const { Schema } = mongoose;
|
||||
|
||||
const fileSchema = new Schema({
|
||||
const fileSchema = new Schema(
|
||||
{
|
||||
name: { type: String, default: 'sketch.js' },
|
||||
content: { type: String, default: '' },
|
||||
url: { type: String },
|
||||
children: { type: [String], default: [] },
|
||||
fileType: { type: String, default: 'file' },
|
||||
isSelectedFile: { type: Boolean }
|
||||
}, { timestamps: true, _id: true, usePushEach: true });
|
||||
},
|
||||
{ timestamps: true, _id: true, usePushEach: true }
|
||||
);
|
||||
|
||||
fileSchema.virtual('id').get(function getFileId() {
|
||||
return this._id.toHexString();
|
||||
|
@ -21,14 +24,17 @@ fileSchema.set('toJSON', {
|
|||
virtuals: true
|
||||
});
|
||||
|
||||
const projectSchema = new Schema({
|
||||
const projectSchema = new Schema(
|
||||
{
|
||||
name: { type: String, default: "Hello p5.js, it's the server" },
|
||||
user: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
serveSecure: { type: Boolean, default: false },
|
||||
files: { type: [fileSchema] },
|
||||
_id: { type: String, default: shortid.generate },
|
||||
slug: { type: String }
|
||||
}, { timestamps: true, usePushEach: true });
|
||||
},
|
||||
{ timestamps: true, usePushEach: true }
|
||||
);
|
||||
|
||||
projectSchema.virtual('id').get(function getProjectId() {
|
||||
return this._id;
|
||||
|
|
16
server/utils/generateFileSystemSafeName.js
Normal file
16
server/utils/generateFileSystemSafeName.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* generate file system safe string for a given string
|
||||
* that can be used as a valid file name
|
||||
* in all operating systems
|
||||
* @param {String} string
|
||||
* @param {String} replacer (optional) character to replace invalid characters
|
||||
*/
|
||||
function generateFileSystemSafeName(string, replacer) {
|
||||
// from here https://serverfault.com/a/242134
|
||||
const INVALID_CHARS_REGEX = /[*/?:\\<>|"\u0000-\u001F]/g;
|
||||
const slug = string.replace(INVALID_CHARS_REGEX, replacer || '');
|
||||
|
||||
return slug;
|
||||
}
|
||||
|
||||
export default generateFileSystemSafeName;
|
Loading…
Reference in a new issue