Files
kami-parse-server/src/GridStoreAdapter.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-01-28 10:58:12 -08:00
// GridStoreAdapter
//
// Stores files in Mongo using GridStore
// Requires the database adapter to be based on mongoclient
2016-02-08 22:51:58 -08:00
import { GridStore } from 'mongodb';
import { FilesAdapter } from './FilesAdapter';
2016-01-28 10:58:12 -08:00
2016-02-08 22:51:58 -08:00
class GridStoreAdapter extends FilesAdapter {
// For a given config object, filename, and data, store a file
// Returns a promise
createFileAsync(config, filename, data) {
return config.database.connect().then(() => {
let gridStore = new GridStore(config.database.db, filename, 'w');
return gridStore.open();
}).then((gridStore) => {
return gridStore.write(data);
}).then((gridStore) => {
return gridStore.close();
});
}
getFileDataAsync(config, filename) {
return config.database.connect().then(() => {
return GridStore.exist(config.database.db, filename);
}).then(() => {
let gridStore = new GridStore(config.database.db, filename, 'r');
return gridStore.open();
}).then((gridStore) => {
return gridStore.read();
});
}
2016-01-28 10:58:12 -08:00
getFileLocation(config, filename) {
return (config.mount + '/files/' + config.applicationId + '/' + encodeURIComponent(filename));
2016-02-08 22:51:58 -08:00
}
2016-01-31 22:27:33 -08:00
}
2016-02-08 22:51:58 -08:00
export default GridStoreAdapter;