Commit 9097c251 authored by Boris Kocherov's avatar Boris Kocherov

ziptodocuments: use generateMetadata as external function for configuraton

parent 28a4df18
...@@ -25,46 +25,50 @@ ...@@ -25,46 +25,50 @@
*/ */
function ZipToDocumentsBridgeStorage(spec) { function ZipToDocumentsBridgeStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage); this._sub_storage = jIO.createJIO(spec.sub_storage);
} if (spec.generateMetadata) {
this._generateMetadata = spec.generateMetadata;
function endsWith(str, suffix) { } else {
return str.indexOf(suffix, str.length - suffix.length) !== -1; throw new jIO.util.jIOError("Need specify generateMetadata function",
} 400);
/**
/** * used for generate metadata for files
* used for generate metadata for files * based on extension and file content.
* based on extension and file content. * used for determine supported or not
* used for determine supported or not * supported file by return undefined.
* supported file by return undefined. *
* * @function generateMetadata
* @function generateMetadata */
*/ // example generateMetadata function
function generateMetadata(id, filename, path, body) { // function generateMetadata(id, filename, path, body) {
var ret; // var ret;
if (endsWith(filename, ".json")) { // if (endsWith(filename, ".json")) {
ret = { // ret = {
id: id, // id: id,
content_type: "application/json", // content_type: "application/json",
reference: path // reference: path
}; // };
if (body) { // if (body) {
if (body.$schema && body.$schema !== "") { // if (body.$schema && body.$schema !== "") {
ret.portal_type = "JSON Schema"; // ret.portal_type = "JSON Schema";
ret.parent_relative_url = "schema_module"; // ret.parent_relative_url = "schema_module";
ret.title = body.title || filename; // ret.title = body.title;
} else { // } else {
// XXX need schema relation property // // XXX need schema relation property
ret.portal_type = "JSON Document"; // ret.portal_type = "JSON Document";
ret.parent_relative_url = "document_module"; // ret.parent_relative_url = "document_module";
} // ret.title = body.filename;
} else { // }
ret.format = "json"; // } else {
} // ret.format = "json";
// used for detect supported extension // }
return ret; // // used for detect supported extension
// return ret;
// }
// }
} }
} }
ZipToDocumentsBridgeStorage.prototype.get = function (id) { ZipToDocumentsBridgeStorage.prototype.get = function (id) {
var context = this, var context = this,
path = "/" + decodeJsonPointer(id), path = "/" + decodeJsonPointer(id),
...@@ -73,7 +77,7 @@ ...@@ -73,7 +77,7 @@
dirname = path.substring(0, idx), dirname = path.substring(0, idx),
file_supported; file_supported;
path = path.substring(1); path = path.substring(1);
file_supported = generateMetadata(id, filename, path); file_supported = context._generateMetadata(id, filename, path);
if (!file_supported) { if (!file_supported) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -94,7 +98,7 @@ ...@@ -94,7 +98,7 @@
throw error; throw error;
}) })
.push(function (attachment) { .push(function (attachment) {
return generateMetadata(id, filename, path, attachment); return context._generateMetadata(id, filename, path, attachment);
}); });
}; };
...@@ -159,7 +163,7 @@ ...@@ -159,7 +163,7 @@
function push_doc(k, filename, path) { function push_doc(k, filename, path) {
return function (json) { return function (json) {
result_dict[k].doc = generateMetadata(k, filename, path, json); result_dict[k].doc = context._generateMetadata(k, filename, path, json);
}; };
} }
...@@ -175,7 +179,7 @@ ...@@ -175,7 +179,7 @@
path = dirname.substring(1) + filename; path = dirname.substring(1) + filename;
k = encodeJsonPointer(dirname.substring(1) + filename); k = encodeJsonPointer(dirname.substring(1) + filename);
// check file with extension supported // check file with extension supported
if (generateMetadata(k, filename, path)) { if (context._generateMetadata(k, filename, path)) {
result_dict[k] = { result_dict[k] = {
id: k, id: k,
value: {} value: {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment