-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathserver-framework.js
More file actions
67 lines (54 loc) · 1.9 KB
/
server-framework.js
File metadata and controls
67 lines (54 loc) · 1.9 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
import React from 'react';
import {getSettings} from './server-entry';
import {bindState, validateState, resetState, whitelistState, bindProp, queryString} from './validate-state.js';
import errorMessages from './error-messages';
export {route, ready, config} from './server-entry';
export {ObjectID} from 'mongodb';
export function server(ctx, fn) {
return function(...args) {
return fn.apply(ctx, args);
}
}
export class Page extends React.Component {
settings = getSettings();
state = {};
schema = {};
authorize() {
}
constructor(props) {
super(props);
this.errorMessages = errorMessages[this.settings.locale];
this.queryString = queryString.bind(this);
this.bindProp = bindProp.bind(this);
this.bindState = bindState.bind(this);
this.validateState = validateState.bind(this);
this.resetState = resetState.bind(this);
this.whitelistState = whitelistState.bind(this);
}
setState(updates) {
this.state = Object.assign(this.state, updates);
}
setSession(updates) {
this.session = Object.assign(this.session, updates);
}
set(updates) {
this.settings = Object.assign(this.settings, updates);
}
redirect(target) {
this._redirect = target;
}
async uploadImage(recordKey, propertyKey, file) {
const sizes = {};
const collection = `${recordKey}-${propertyKey}`;
for(const size of Object.keys(this.schema[recordKey][propertyKey].sizes)) {
const settings = this.schema[recordKey][propertyKey].sizes[size];
sizes[size] = await this.storage.collection(collection).insertOne({...file, ...settings, ...this.settings});
};
return {...sizes, label: file.originalname};
}
async uploadFile(recordKey, propertyKey, file) {
const collection = `${recordKey}-${propertyKey}`;
const link = await this.storage.collection(collection).insertOne({...file, ...this.settings});
return {link, label: file.originalname};
}
}