Skip to content

Commit

Permalink
json upload fix
Browse files Browse the repository at this point in the history
  • Loading branch information
parkchamchi committed Nov 1, 2024
1 parent d4906b0 commit c6e0d49
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/backend/gs_index/src/components/Corpus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
let a = document.createElement("a"); //dummy a
let file = new Blob([json], {type: "text/plain"});
a.download = this.corpus_id + ".corpus.json";
a.download = this.corpus.id + ".corpus.json";
a.href = URL.createObjectURL(file);
a.click();
},
Expand Down
5 changes: 3 additions & 2 deletions src/backend/gs_index/src/components/CorpusesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
/* Local */
async addLocalCorpus(corpus) {
console.log("addLocalCorpus", corpus.id);
this.corpusStorage.create(corpus);
},
updateCorpusIds() {
Expand All @@ -52,7 +53,7 @@
},
},
async created() {
EventBus.on("updateCorpusIds", this.updateCorpusIds); // Listen for the error event
EventBus.on("updateCorpusIds", this.updateCorpusIds);
EventBus.on("addLocalCorpus", this.addLocalCorpus); // From UploadView
this.getRemoteSamples();
Expand All @@ -62,7 +63,7 @@
this.updateCorpusIds();
},
beforeDestroy() {
EventBus.off("updateCorpuses", this.updateCorpuses); // Clean up the event listener
EventBus.off("updateCorpusIds", this.updateCorpusIds);
EventBus.off("addLocalCorpus", this.addLocalCorpus); // From UploadView
},
}
Expand Down
8 changes: 5 additions & 3 deletions src/backend/gs_index/src/components/UploadView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
methods: {
async onUploadButtonClicked() {
const corpus = Corpus.init_with_txt(this.originalText);
const corpus_id = this.makeTitle(this.originalText);
corpus.id = corpus_id;
corpus.id = this.makeTitle(this.originalText);
EventBus.emit("addLocalCorpus", corpus);
},
async onJsonFileInput(event) {
const file = event.target.files[0];
const content = await file.text();
const corpus = JSON.parse(content);
const corpus_id = this.makeTitle(corpus.original_text);
corpus.id = "JSON Corpus";
EventBus.emit("addLocalCorpus", corpus);
},
makeTitle(str, maxlen=16) {
if (!str)
return "Corpus";
return str.substring(0, maxlen);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/gs_index/src/corpusStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class CorpusStorageInner {
getRequest.onerror = (event) => reject(event.target.error);
};

if (!content.id)
content.id = "id";
checkAndAdd(content, content.id);
});
}
Expand Down

0 comments on commit c6e0d49

Please sign in to comment.