Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
jio
Commits
9097c251
Commit
9097c251
authored
Jul 17, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ziptodocuments: use generateMetadata as external function for configuraton
parent
28a4df18
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
41 deletions
+45
-41
src/jio.storage/ziptodocuments.js
src/jio.storage/ziptodocuments.js
+45
-41
No files found.
src/jio.storage/ziptodocuments.js
View file @
9097c251
...
@@ -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
:
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment