Skip to content
Snippets Groups Projects
Commit 4932ac7c authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

allow changing index

parent 067179c2
Branches
No related tags found
No related merge requests found
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
font-weight: normal; font-weight: normal;
} }
.mono {
font-family: monospace;
}
a, a,
.green { .green {
text-decoration: none; text-decoration: none;
......
...@@ -31,8 +31,4 @@ props.dag.then((r) => { ...@@ -31,8 +31,4 @@ props.dag.then((r) => {
</tr> </tr>
</template> </template>
<style scoped> <style scoped></style>
.mono {
font-family: monospace;
}
</style>
...@@ -33,7 +33,7 @@ onload() ...@@ -33,7 +33,7 @@ onload()
<template v-if="inode"> <template v-if="inode">
<ul> <ul>
<li v-for="c in inode.children.filter((e) => e != null)"> <li v-for="c in inode.children.filter((e) => e != null)">
<div>{{ c![0] }} <a :href="exploreUrl(c![1])" target="_blank">cid</a></div> <div><span class="mono">{{ c![0] }}</span> <a :href="exploreUrl(c![1])" target="_blank">cid</a></div>
<div><IndexNode :key="c![1].toString()" :cid="c![1]"></IndexNode></div> <div><IndexNode :key="c![1].toString()" :cid="c![1]"></IndexNode></div>
</li> </li>
</ul> </ul>
...@@ -41,8 +41,4 @@ onload() ...@@ -41,8 +41,4 @@ onload()
<template v-if="leaf"> leaf ({{ leaf.leaf.length }}) </template> <template v-if="leaf"> leaf ({{ leaf.leaf.length }}) </template>
</template> </template>
<style scoped> <style scoped></style>
.mono {
font-family: monospace;
}
</style>
import { ref } from 'vue' import { ref, type Ref } from 'vue'
import type { Ref } from 'vue'
export const feed: Ref<string[]> = ref([]) export const feed: Ref<string[]> = ref([])
<script setup lang="ts"> <script setup lang="ts">
import { feed } from '@/global' import { feed } from '@/global'
import { ref } from 'vue' import { ref, type Ref } from 'vue'
import type { Ref } from 'vue'
import { TOPIC, pubsub } from '@/p2p' import { TOPIC, pubsub } from '@/p2p'
import type { PeerId } from '@libp2p/interface' import type { PeerId } from '@libp2p/interface'
import { CID } from 'multiformats' import { CID } from 'multiformats'
...@@ -60,4 +59,4 @@ function get_dag(cid: CID): Promise<IndexRequest> { ...@@ -60,4 +59,4 @@ function get_dag(cid: CID): Promise<IndexRequest> {
</div> </div>
</template> </template>
<style></style> <style scoped></style>
...@@ -8,3 +8,5 @@ ...@@ -8,3 +8,5 @@
<p>This UI is optional. It aims to help understand how the indexer part work and interacts with the local IPFS node (kubo for instance).</p> <p>This UI is optional. It aims to help understand how the indexer part work and interacts with the local IPFS node (kubo for instance).</p>
</main> </main>
</template> </template>
<style scoped></style>
\ No newline at end of file
...@@ -2,14 +2,23 @@ ...@@ -2,14 +2,23 @@
import { kubo } from '@/kubo' import { kubo } from '@/kubo'
import { emptyInode } from '../types' import { emptyInode } from '../types'
import { IPNS } from '../consts' import { IPNS } from '../consts'
import { ref } from 'vue'
import { CID } from 'multiformats' import { CID } from 'multiformats'
import type { Ref } from 'vue' import { ref, type Ref, computed } from 'vue'
import IndexNode from '../components/IndexNode.vue' import IndexNode from '../components/IndexNode.vue'
const msg = ref('')
const rootnodeipns = ref('') const rootnodeipns = ref('')
const ipnsTarget = ref('') const ipnsTarget = ref('')
const ipnsTargetCid: Ref<CID | null> = ref(null) const targetCid: Ref<CID | null> = ref(null)
const isValid = computed(() => {
try {
CID.parse(msg.value)
return true
} catch {
return false
}
})
// inits indexing and publishes ipns entry for it // inits indexing and publishes ipns entry for it
async function initIndex() { async function initIndex() {
...@@ -18,27 +27,49 @@ async function initIndex() { ...@@ -18,27 +27,49 @@ async function initIndex() {
const res = await kubo.name.publish(rootcid, { ttl: '1s' }) const res = await kubo.name.publish(rootcid, { ttl: '1s' })
console.log(res) console.log(res)
rootnodeipns.value = res.name rootnodeipns.value = res.name
resolve()
} }
async function resolve() { async function resolve() {
for await (const name of kubo.name.resolve(IPNS, { nocache: true })) { for await (const name of kubo.name.resolve(IPNS, { nocache: true })) {
console.log(name) console.log(name)
ipnsTarget.value = name ipnsTarget.value = name
ipnsTargetCid.value = CID.parse(name.slice(6)) targetCid.value = CID.parse(name.slice(6))
}
}
function setTargetCid() {
if (isValid.value) {
const cid = CID.parse(msg.value)
targetCid.value = cid
kubo.name.publish(cid, { ttl: '1s' }).then((_) => resolve())
} else {
targetCid.value = null
} }
} }
resolve()
</script> </script>
<template> <template>
<div> <div>
<h1>Index</h1> <h1>Index</h1>
<p>Info about the index</p> <p>Info about the index</p>
<p>initialize index: <button @click="initIndex">initialize</button></p> <p>initialize empty index: <button @click="initIndex">reinitialize ⚠️</button></p>
<p>root node ipns: /ipns/{{ rootnodeipns }}</p> <p>root node ipns: <span class="mono">/ipns/{{ rootnodeipns }}</span></p>
<p>IPNS {{ IPNS }}</p> <p>You can use it to configure root node instead of hardcoded one:</p>
<p>pointing to <button @click="resolve">resolve</button> {{ ipnsTarget }}</p> <p class="mono">{{ IPNS }}</p>
<p><IndexNode v-if="ipnsTargetCid" :key="ipnsTarget" :cid="ipnsTargetCid"></IndexNode></p> <p>which is pointing to <button @click="resolve">resolve</button></p>
<p class="mono">{{ ipnsTarget }}</p>
<p>
set IPNS target cid
<input v-model="msg" @keyup.enter="setTargetCid" />
<button v-on:click="setTargetCid">Set ⚠️</button>
</p>
<h2>Tree preview</h2>
<p class="mono">{{ targetCid }}</p>
<p><IndexNode v-if="targetCid" :key="ipnsTarget" :cid="targetCid"></IndexNode></p>
</div> </div>
</template> </template>
<style></style> <style scoped></style>
...@@ -5,4 +5,4 @@ ...@@ -5,4 +5,4 @@
</div> </div>
</template> </template>
<style></style> <style scoped></style>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment