Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Nov 20, 2024
1 parent 93896d5 commit 754942b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
53 changes: 38 additions & 15 deletions src/components/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,9 @@ export default {
return;
}
const loadingComponent = this.$buefy.loading.open({ container: this.$el });
const loadingComponent = this.$buefy.loading.open({
container: this.$el
});
try {
// Define the dataset id in the collection
Expand All @@ -635,11 +637,19 @@ export default {
},
async login() {
try {
const token = await hyphaWebsocketClient.login({server_url: this.siteConfig.hypha_server_url, login_callback(context){
window.open(context.login_url, '_blank');
}});
this.server = await hyphaWebsocketClient.connectToServer({server_url: this.siteConfig.hypha_server_url, token});
this.artifactManager = await this.server.getService("public/artifact-manager");
const token = await hyphaWebsocketClient.login({
server_url: this.siteConfig.hypha_server_url,
login_callback(context) {
window.open(context.login_url, "_blank");
}
});
this.server = await hyphaWebsocketClient.connectToServer({
server_url: this.siteConfig.hypha_server_url,
token
});
this.artifactManager = await this.server.getService(
"public/artifact-manager"
);
this.$forceUpdate();
} catch (e) {
alert(`Failed to login: ${e}`);
Expand Down Expand Up @@ -672,22 +682,26 @@ export default {
return;
}
const loadingComponent = this.$buefy.loading.open({ container: this.$el });
const loadingComponent = this.$buefy.loading.open({
container: this.$el
});
this.similarDeposits = null;
this.uploadProgress = 1;
try {
// Step 1: Define the dataset ID
// randomly generate a depositId using time and random id if not provided
depositId = depositId || Math.floor(Date.now() / 1000) + "-" + Math.floor(Math.random() * 100);
depositId =
depositId ||
Math.floor(Date.now() / 1000) + "-" + Math.floor(Math.random() * 100);
// Step 2: Create or overwrite the dataset in the artifact manager
const artifact = await this.artifactManager.create({
parent_id: "shareloc-xyz/shareloc-collection",
alias: `shareloc-xyz/${depositId}`,
manifest: this.rdf,
version: "stage",
// overwrite: true,
_rkwargs: true,
_rkwargs: true
});
// Step 3: Upload each file in editedFiles with a pre-signed URL
Expand All @@ -697,21 +711,31 @@ export default {
file = await file.generate();
}
const filePath = file.sampleName ? `${file.sampleName}/${file.name}` : file.name;
const putUrl = await this.artifactManager.put_file({ artifact_id: artifact.id, file_path: filePath, _rkwargs: true });
const filePath = file.sampleName
? `${file.sampleName}/${file.name}`
: file.name;
const putUrl = await this.artifactManager.put_file({
artifact_id: artifact.id,
file_path: filePath,
_rkwargs: true
});
// Upload file via PUT request
const response = await fetch(putUrl, {
method: "PUT",
body: file,
body: file
});
if (!response.ok) {
throw new Error(`Failed to upload file: ${file.name}`);
}
this.uploadProgress = Math.round(((i + 1) / this.editedFiles.length) * 100);
this.uploadStatus = `Uploaded ${i + 1}/${this.editedFiles.length}: ${file.name}`;
this.uploadProgress = Math.round(
((i + 1) / this.editedFiles.length) * 100
);
this.uploadStatus = `Uploaded ${i + 1}/${this.editedFiles.length}: ${
file.name
}`;
}
this.depositId = depositId;
this.uploadProgress = 0;
Expand All @@ -726,7 +750,6 @@ export default {
loadingComponent.close();
}
}
}
};
</script>
Expand Down
19 changes: 7 additions & 12 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function normalizeItem(item) {
}
// fix samples
const samples = item.attachments?.samples;
if(samples){
if (samples) {
for (let sample of samples) {
for (let f of sample.files) {
// make a copy of it
Expand Down Expand Up @@ -205,7 +205,7 @@ function normalizeItem(item) {

Object.assign(f, file);
}
for (let view of sample.views) {
for (let view of sample.views) {
if (!view.image) {
view.image = `${item.root_url}/${sample.name}/${
Array.isArray(view.image_name)
Expand Down Expand Up @@ -271,10 +271,7 @@ export const store = new Vuex.Store({
alert(`Failed to login: ${e}`);
}
},
async fetchResourceItems(
context,
{ manifest_url, repo, transform }
) {
async fetchResourceItems(context, { manifest_url, repo, transform }) {
if (context.state.loadedUrl === manifest_url) {
console.log("manifest already loaded");
return;
Expand All @@ -298,21 +295,19 @@ export const store = new Vuex.Store({
}
}

if (siteConfig.builtin_manifest_url){
if (siteConfig.builtin_manifest_url) {
const builtin_response = await fetch(siteConfig.builtin_manifest_url);
const builtin_manifest = JSON.parse(await builtin_response.text());
for (let item of builtin_manifest.resources){
for (let item of builtin_manifest.resources) {
context.commit("addResourceItem", item);
}
}
const resources_response = await fetch(
manifest_url + "/children"
);
const resources_response = await fetch(manifest_url + "/children");
const resourceItems = await resources_response.json();
const rawResourceItems = JSON.parse(JSON.stringify(resourceItems));
const artifacts_url = manifest_url.split("/artifacts")[0] + "/artifacts";
for (let artifact of rawResourceItems) {
const item = artifact.manifest
const item = artifact.manifest;
item.repo = repo;
item.root_url = `${artifacts_url}/${artifact.alias}/files`;
item.rdf_source = `${artifacts_url}/${artifact.alias}`;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export async function getFullRdfFromDeposit(rdf, resolveUrl) {
for (let f of sample.files) {
// make a copy of it
const file = {};
debugger
debugger;
file.download_url = `${root_url}/${sample.name}/${f.name}`; // <sample name>/ <file name>
// fix the name
file.name = f.name;
Expand Down
3 changes: 1 addition & 2 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ const isTouchDevice = (function() {
}
})();
async function updateFullRDF() {
}
async function updateFullRDF() {}
function connectApps(self, item) {
if (item.config && item.config._linked) return;
Expand Down

0 comments on commit 754942b

Please sign in to comment.