ae668f681e
* Checkbox to toggle project's serveSecure flag This doesn't yet persist or reload the page. * Help button that shows modal to explain feature * Extracts protocol redirection to helper * Returns promise from saveProject() action to allow chaining * Setting serveSecure flag on project redirects after saving project * Set serveSecure on Project model in API and client * Redirect to correct protocol when project is loaded
39 lines
1 KiB
JavaScript
39 lines
1 KiB
JavaScript
import mongoose from 'mongoose';
|
|
import shortid from 'shortid';
|
|
|
|
const Schema = mongoose.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 });
|
|
|
|
fileSchema.virtual('id').get(function getFileId() {
|
|
return this._id.toHexString();
|
|
});
|
|
|
|
fileSchema.set('toJSON', {
|
|
virtuals: true
|
|
});
|
|
|
|
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 }
|
|
}, { timestamps: true });
|
|
|
|
projectSchema.virtual('id').get(function getProjectId() {
|
|
return this._id;
|
|
});
|
|
|
|
projectSchema.set('toJSON', {
|
|
virtuals: true
|
|
});
|
|
|
|
export default mongoose.model('Project', projectSchema);
|