Skip to content

Commit 2432068

Browse files
committed
Add support for python
Signed-off-by: David Weik <[email protected]>
1 parent 0449941 commit 2432068

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

js/utility/create-model-content.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @param {String} modelID - The ID of the model for which content should be added
66
* @param {Object} modelContent - The object of the model content that should be uploaded
77
* @param {String} modelContentFileName - The name that the file should have in SAS Model Manager
8-
* @param {String} modelContentRole - Optional, defaults to Documentation - define the role of the file within the model
8+
* @param {String} modelContentRole - Optional, defaults to documentation - define the role of the file within the model
99
* @param {String} contentType - Optional, defaults to application/json - define the content type of the content to be uploaded
1010
* @returns {Promise/Object of Content and Status Code} - Returns a Promise that should resolve into content information and the status code
1111
*/
@@ -14,21 +14,24 @@ async function createModelContent(
1414
modelID,
1515
modelContent,
1616
modelContentFileName,
17-
modelContentRole = 'Documentation',
17+
modelContentRole = 'documentation',
1818
contentType = 'application/json'
1919
) {
2020
const formData = new FormData();
2121
if (contentType === "multipart/form-data" && modelContent instanceof Uint8Array) {
2222
contentType = "application/octet-stream";
23+
} else if (contentType === 'text/x-python') {
24+
formData.append("files", modelContent, modelContentFileName);
25+
formData.append('role', modelContentRole);
2326
} else if (typeof modelContent === 'object') {
2427
let modelContentJSONString = JSON.stringify(modelContent, null, 2);
2528
let modelContentBlob = new Blob([modelContentJSONString], {type: contentType});
2629
formData.append("files", modelContentBlob, modelContentFileName);
2730
formData.append('role', modelContentRole);
28-
}
31+
}
2932

3033
let CREATEMODELCONTENTRESPONSE = await fetch(
31-
`${VIYAHOST}/modelRepository/models/${modelID}/contents?onConflict=update`,
34+
`${VIYAHOST}/modelRepository/models/${modelID}/contents?onConflict=update&role=${modelContentRole}`,
3235
{
3336
// mode: 'no-cors',
3437
method: 'post',
@@ -51,7 +54,7 @@ async function createModelContent(
5154
let t = CREATEMODELCONTENTRESPONSE.headers.get('x-csrf-token');
5255
document.csrfToken = t;
5356
CREATEMODELCONTENTRESPONSE = await fetch(
54-
`${VIYAHOST}/modelRepository/models/${modelID}/contents?onConflict=update`,
57+
`${VIYAHOST}/modelRepository/models/${modelID}/contents?onConflict=update&role=${modelContentRole}`,
5558
{
5659
method: 'post',
5760
headers: {

0 commit comments

Comments
 (0)