New things for GCS Adapter

This commit is contained in:
Mike McDonald
2016-03-07 00:30:21 -08:00
parent 84635352e3
commit ce35b81cc6
5 changed files with 50 additions and 35 deletions

View File

@@ -2,7 +2,7 @@
AdaptableController.js
AdaptableController is the base class for all controllers
that support adapter,
that support adapter,
The super class takes care of creating the right instance for the adapter
based on the parameters passed
@@ -28,30 +28,30 @@ export class AdaptableController {
this.validateAdapter(adapter);
this[_adapter] = adapter;
}
get adapter() {
return this[_adapter];
}
get config() {
return new Config(this.appId);
}
expectedAdapterType() {
throw new Error("Subclasses should implement expectedAdapterType()");
}
validateAdapter(adapter) {
if (!adapter) {
throw new Error(this.constructor.name+" requires an adapter");
}
let Type = this.expectedAdapterType();
// Allow skipping for testing
if (!Type) {
if (!Type) {
return;
}
// Makes sure the prototype matches
let mismatches = Object.getOwnPropertyNames(Type.prototype).reduce( (obj, key) => {
const adapterType = typeof adapter[key];
@@ -64,7 +64,7 @@ export class AdaptableController {
}
return obj;
}, {});
if (Object.keys(mismatches).length > 0) {
throw new Error("Adapter prototype don't match expected prototype", adapter, mismatches);
}

View File

@@ -13,11 +13,11 @@ export class FilesController extends AdaptableController {
}
createFile(config, filename, data, contentType) {
let extname = path.extname(filename);
const hasExtension = extname.length > 0;
if (!hasExtension && contentType && mime.extension(contentType)) {
filename = filename + '.' + mime.extension(contentType);
} else if (hasExtension && !contentType) {
@@ -27,6 +27,8 @@ export class FilesController extends AdaptableController {
filename = randomHexString(32) + '_' + filename;
var location = this.adapter.getFileLocation(config, filename);
console.log(this.adapter);
console.log(location);
return this.adapter.createFile(config, filename, data, contentType).then(() => {
return Promise.resolve({
url: location,