-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel.js
More file actions
110 lines (81 loc) · 2.61 KB
/
model.js
File metadata and controls
110 lines (81 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Digital Fortress -- data model
// Loaded on both the client and the server
///////////////////////////////////////////////////////////////////////////////
// UserData
// Collection to store the user's data
UserData = new Meteor.Collection('userData');
UserData.allow({
insert: function (userId, doc) {
// the user must be logged in, and the document must be owned by the user
return (userId && userId == doc.uid);
},
update: function (userId, doc, fields, modifier) {
// can only change your own documents
return userId == doc.uid;
},
remove: function (userId, doc) {
// can only remove your own documents
return doc.owner === userId;
}
});
///////////////////////////////////////////////////////////////////////////////
// Captures
// Collection to store information about the user's captures
Captures = new Meteor.Collection('captures');
Captures.allow({
insert: function (userId, doc) {
// the user must be logged in, and the document must be owned by the user
return (userId && userId == doc.uid);
},
update: function (userId, doc, fields, modifier) {
// can only change your own documents
return doc.owner === userId;
},
remove: function (userId, doc) {
// can only remove your own documents
return doc.owner === userId;
}
});
///////////////////////////////////////////////////////////////////////////////
// CapturesFS
// Collection that actually holds the files in question
CapturesFS = new CollectionFS('capturesFS', { autopublish: false });
CapturesFS.allow({
insert: function(userId, myFile) {
return false;
},
update: function(userId, files, fields, modifier) {
return _.all(files, function (myFile) {
return false;
});
},
remove: function(userId, files) {
return false;
}
});
CapturesFS.fileHandlers({
default: function(options) {
/*
* Options contains blob and fileRecord - same is expected in return if should
* be saved on filesytem, can be modified.
*/
// Collect variables to use when updating capture
var filename = options.fileRecord.filename;
var dest = options.destination().fileData.url;
// Update the capture source for the user
Captures.update({
'filename': filename
}, {
$set: {
'source': dest
}
});
console.log('Saved file to: ' + dest);
// Return the blob and fileRecord to save
return { blob: options.blob, fileRecord: options.fileRecord }; //if no blob then save result in fileHandle (added createdAt)
}
});
///////////////////////////////////////////////////////////////////////////////
// Users
// Handled by Meteor
// To access, use Meteor.users