Skip to content

Commit

Permalink
fix(load): auto stringify json when creating corpus from json
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmacdonald committed Oct 22, 2024
1 parent c283391 commit 6a28759
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/corpus.js
Original file line number Diff line number Diff line change
Expand Up @@ -1627,15 +1627,15 @@ class Corpus {
resolve(config);
}

if (typeof config === 'string') {
if (Util.isString(config)) {
if (config.length>0 && /\W/.test(config)===false) {
config = {corpus: config};
} else {
config = {input: config};
}
} else if (Util.isArray(config) && config.length > 0 && typeof config[0] === 'string') {
config = {input: config};
} else if (config instanceof Blob || Util.isNode(config) || (Util.isArray(config) && (config[0] instanceof Blob || Util.isNode(config[0])))) {
} else if (Util.isBlob(config) || Util.isNode(config) || (Util.isArray(config) && (Util.isBlob(config[0]) || Util.isNode(config[0])))) {
const formData = new FormData();
if (Util.isArray(config)) {
config.forEach(file => {
Expand All @@ -1658,7 +1658,7 @@ class Corpus {
}

// append any other form options that may have been included
if (api && typeof api === 'object') {
if (api && Util.isObject(api)) {
for (let key in api) {
formData.set(key, api[key]);
}
Expand All @@ -1670,6 +1670,10 @@ class Corpus {
body: formData,
method: 'POST'
};
} else if (Util.isObject(config)) {
if (config.inputFormat === 'json' && Util.isString(config.input) === false) {
config.input = JSON.stringify(config.input);
}
}

Load.trombone({...config,...api}, {tool: 'corpus.CorpusMetadata'})
Expand Down

0 comments on commit 6a28759

Please sign in to comment.