-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from earthpulse/229-ingest-models-through-ui
added model ingestion through ui
- Loading branch information
Showing
10 changed files
with
387 additions
and
85 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { PUBLIC_EOTDL_API } from '$env/static/public'; | ||
import fetchEOTDL from '$lib/shared/fetchEOTDL'; | ||
|
||
export default async (name, authors, source, license, token) => { | ||
const url = `${PUBLIC_EOTDL_API}/models`; | ||
const body = {name, authors, license, source}; | ||
const { data, error } = await fetchEOTDL(url, token, 'POST', body); | ||
if (error) throw new Error(error); | ||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PUBLIC_EOTDL_API } from '$env/static/public'; | ||
import EOTDLFileUpload from '$lib/shared/EOTDLFileUpload'; | ||
import fileChecksum from '../datasets/fileChecksum'; | ||
export default async (model_id, file, token, version) => { | ||
const url = `${PUBLIC_EOTDL_API}/models/${model_id}?version=${version.version}`; | ||
const formData = new FormData(); | ||
formData.append("file", file); | ||
formData.append("checksum", fileChecksum(await file.arrayBuffer())); | ||
const { data, error } = await EOTDLFileUpload(url, token, formData); | ||
if (error) throw new Error(error); | ||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { PUBLIC_EOTDL_API } from '$env/static/public'; | ||
import fetchEOTDL from '$lib/shared/fetchEOTDL'; | ||
|
||
export default async (model_id, token) => { | ||
const url = `${PUBLIC_EOTDL_API}/models/version/${model_id}`; | ||
const { data, error } = await fetchEOTDL(url, token, 'POST'); | ||
if (error) throw new Error(error); | ||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<script> | ||
import { user, id_token } from "$stores/auth"; | ||
import { models } from "../../stores/models"; | ||
import IngestForm from "./IngestForm.svelte"; | ||
export let tags; | ||
const submit = async ( | ||
files, | ||
name, | ||
content, | ||
authors, | ||
source, | ||
license, | ||
selected_tags | ||
) => { | ||
if ( | ||
!name || | ||
files?.length == 0 || | ||
authors.length == 0 || | ||
!license || | ||
!source || | ||
!content || | ||
content.length == 0 | ||
) | ||
throw new Error("Please fill in all fields"); | ||
let data; | ||
if (files.length == 0) throw new Error("Please upload a file"); | ||
const modelExists = $models.data.find( | ||
(d) => d.name == name && d.uid == $user.uid | ||
); | ||
if (modelExists) | ||
throw new Error("Model already exists, choose a different name"); | ||
const model_id = await models.create( | ||
name, | ||
authors, | ||
source, | ||
license, | ||
$id_token | ||
); | ||
const version = await models.setVersion(model_id, $id_token); | ||
for (var i = 0; i < files.length; i++) { | ||
data = await models.ingest(model_id, files[i], $id_token, version, name); | ||
} | ||
await models.update( | ||
model_id, | ||
name, | ||
content, | ||
authors, | ||
source, | ||
license, | ||
selected_tags, | ||
$id_token | ||
); | ||
}; | ||
</script> | ||
{#if $user} | ||
<IngestForm | ||
{tags} | ||
{submit} | ||
text="Ingest model" | ||
forCreate={true} | ||
required={true} | ||
name={""} | ||
authors={""} | ||
source={""} | ||
license={""} | ||
content={""}> | ||
<h3 class="text-lg font-bold">Ingest model</h3> | ||
</IngestForm> | ||
{/if} |
Oops, something went wrong.