From d38683e143777ac1aad4e5f7edb27c8c26ad88d8 Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Thu, 4 Apr 2024 20:43:59 +0200
Subject: [PATCH] wip import c+ to AMT

---
 README.md               |  5 ++++-
 src/cesium-plus.ts      |  2 +-
 src/views/CplusView.vue | 46 +++++++++++++++++++++++------------------
 3 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md
index a141d82..b79f880 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@ pnpm dev
 After exporting the data to json files with the Rust script from `v2s-datapod`.
 
 ```sh
+# takes about 200 seconds (4 minutes)
 time npx tsx src/scripts/cesium-plus-import.ts
 ```
 
@@ -19,4 +20,6 @@ You can then manually pin the cid according to the command output.
 
 ```sh
 ipfs pin add -r bafyreie74jtf23zzz2tdgsz7axfrm4pidje43ypqn25v4gkdtfjbcj62km
-```
\ No newline at end of file
+```
+
+This will make easier to insert this data in any AMT or other data structure.
\ No newline at end of file
diff --git a/src/cesium-plus.ts b/src/cesium-plus.ts
index 09eb75b..5ca1a1c 100644
--- a/src/cesium-plus.ts
+++ b/src/cesium-plus.ts
@@ -4,7 +4,7 @@ import { Buffer } from 'buffer'
 
 // for reference see
 // https://doc.e-is.pro/cesium-plus-pod/REST_API.html
-interface CplusProfile {
+export interface CplusProfile {
   version: number
   title: string
   description: string
diff --git a/src/views/CplusView.vue b/src/views/CplusView.vue
index 7568f7d..e4cd5ba 100644
--- a/src/views/CplusView.vue
+++ b/src/views/CplusView.vue
@@ -1,26 +1,28 @@
 <script setup lang="ts">
-import { ref, type Ref } from 'vue'
-import { processCesiumPlusImport } from '../cesium-plus'
-import type { CID } from 'kubo-rpc-client'
+import { ref, type Ref, computed } from 'vue'
+import { processCesiumPlusProfile, type CplusProfile } from '../cesium-plus'
 
 const file: Ref<File | null> = ref(null)
 const sample = ref('')
-const importResult: Ref<CID | null> = ref(null)
+const cidlist = ref('')
+const MAX = 20
 
-async function setfile(input: any) {
+function setfile(input: any) {
   file.value = input.target.files[0]
 }
 
-async function importCplus() {
+function importCplus() {
+  cidlist.value = ''
   if (file.value) {
     console.log(file.value)
-
     const reader = new FileReader()
     reader.onload = function (event) {
       const obj = JSON.parse(event.target!.result as string)
       console.log(obj)
       sample.value = JSON.stringify(obj[0], undefined, 4)
-      processCesiumPlusImport(obj.slice(0, 10)).then((cid) => (importResult.value = cid))
+      obj
+        .slice(0, MAX)
+        .map((e: CplusProfile) => processCesiumPlusProfile(e).then((c) => (cidlist.value += c.toString() + '\n')))
     }
     reader.readAsText(file.value)
   }
@@ -28,19 +30,23 @@ async function importCplus() {
 </script>
 
 <template>
-  <main>
-    <h1>Cesium Plus</h1>
-    <h2>Import</h2>
-    <p>Import data from Cesium+</p>
-    <p>
-      json input file:
-      <input type="file" @change="setfile" />
-      <button v-on:click="importCplus">Import</button>
-    </p>
-    <p>sample:</p>
+  <h1>Cesium Plus</h1>
+  <h2>Import from file</h2>
+  <p>Import data from Cesium+</p>
+  <p>
+    json input file:
+    <input type="file" @change="setfile" />
+    <button v-on:click="importCplus">Import</button> (max {{ MAX }})
+  </p>
+  <details>
+    <summary>sample:</summary>
     <pre>{{ sample }}</pre>
-    <p>root node for import: {{ importResult }}</p>
-  </main>
+  </details>
+  <p>list of imported cids:</p>
+  <pre>{{ cidlist }}</pre>
+
+  <h2>Import from root cid</h2>
+  <p>Choose a root CID from Cesium import and the root CID of the target AMT</p>
 </template>
 
 <style scoped></style>
-- 
GitLab