p5.js-web-editor/server/models/project.js

37 lines
928 B
JavaScript
Raw Normal View History

import mongoose from 'mongoose';
const Schema = mongoose.Schema;
2016-06-17 22:40:13 +02:00
import shortid from 'shortid';
const defaultSketch = `function setup() {
2016-06-29 18:52:16 +02:00
createCanvas(400, 400);
}
function draw() {
2016-06-29 18:52:16 +02:00
background(220);
}`
const defaultHTML =
`
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script src="sketch.js"></script>
</body>
</html>
`
2016-06-17 20:11:52 +02:00
const fileSchema = new Schema({
2016-06-24 00:29:55 +02:00
name: { type: String, default: 'sketch.js' },
2016-06-29 18:52:16 +02:00
content: { type: String, default: defaultSketch }
2016-06-24 00:29:55 +02:00
}, { timestamps: true });
2016-06-17 20:11:52 +02:00
const projectSchema = new Schema({
2016-06-24 00:29:55 +02:00
name: { type: String, default: "Hello p5.js, it's the server" },
user: { type: Schema.Types.ObjectId, ref: 'User' },
files: {type: [ fileSchema ], default: [{ name: 'sketch.js', content: defaultSketch }, { name: 'index.html', content: defaultHTML }]},
2016-06-24 00:29:55 +02:00
_id: { type: String, default: shortid.generate }
}, { timestamps: true });
2016-06-24 00:29:55 +02:00
export default mongoose.model('Project', projectSchema);