Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter Datapod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
Duniter Datapod
Commits
3b400f34
Commit
3b400f34
authored
1 year ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
improve ipns view
parent
c47c5710
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/consts.ts
+1
-1
1 addition, 1 deletion
src/consts.ts
src/views/IpnsView.vue
+44
-59
44 additions, 59 deletions
src/views/IpnsView.vue
with
45 additions
and
60 deletions
src/consts.ts
+
1
−
1
View file @
3b400f34
...
@@ -14,4 +14,4 @@ export const KEYSIZE = (64 * Math.log(2)) / Math.log(BASE)
...
@@ -14,4 +14,4 @@ export const KEYSIZE = (64 * Math.log(2)) / Math.log(BASE)
export
const
EMPTY_NODE_CID
=
CID
.
parse
(
'
bafyreicvlp2p65agkxpzcboedba7zit55us4zvtyyq2wesvsdedy6irwfy
'
)
export
const
EMPTY_NODE_CID
=
CID
.
parse
(
'
bafyreicvlp2p65agkxpzcboedba7zit55us4zvtyyq2wesvsdedy6irwfy
'
)
// document kind of old cesium plus profile imported in the indexer
// document kind of old cesium plus profile imported in the indexer
export
const
CESIUM_PLUS_PROFILE_IMPORT
=
CID
.
parse
(
'
/ipfs/
bafkreiawtammeqc55cssr2zepfpaxbmp7kquhikkagipvtefeadsw4mqvq
'
)
export
const
CESIUM_PLUS_PROFILE_IMPORT
=
CID
.
parse
(
'
bafkreiawtammeqc55cssr2zepfpaxbmp7kquhikkagipvtefeadsw4mqvq
'
)
This diff is collapsed.
Click to expand it.
src/views/IpnsView.vue
+
44
−
59
View file @
3b400f34
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
kubo
}
from
'
@/kubo
'
import
{
kubo
}
from
'
@/kubo
'
import
{
emptyInode
,
type
IndexHist
}
from
'
../types
'
import
{
emptyInode
,
type
IndexHist
}
from
'
../types
'
import
{
IPNS
,
IPNS_HIST
}
from
'
../consts
'
import
{
IPNS
,
IPNS_HIST
,
EMPTY_NODE_CID
}
from
'
../consts
'
import
{
CID
}
from
'
multiformats
'
import
{
CID
}
from
'
multiformats
'
import
{
ref
,
type
Ref
,
computed
,
onMounted
}
from
'
vue
'
import
{
ref
,
type
Ref
,
computed
,
onMounted
}
from
'
vue
'
const
msg
=
ref
(
''
)
const
targetMsg
=
ref
(
''
)
const
rootnodeipns
=
ref
(
''
)
const
targetCID
:
Ref
<
CID
|
null
>
=
ref
(
null
)
const
historyipns
=
ref
(
''
)
const
histCID
:
Ref
<
CID
|
null
>
=
ref
(
null
)
const
ipnsTarget
=
ref
(
''
)
const
targetCid
:
Ref
<
CID
|
null
>
=
ref
(
null
)
const
histCid
:
Ref
<
CID
|
null
>
=
ref
(
null
)
const
isValid
=
computed
(()
=>
{
const
isValid
=
computed
(()
=>
{
try
{
try
{
CID
.
parse
(
m
sg
.
value
)
CID
.
parse
(
targetM
sg
.
value
)
return
true
return
true
}
catch
{
}
catch
{
return
false
return
false
...
@@ -23,99 +20,87 @@ const isValid = computed(() => {
...
@@ -23,99 +20,87 @@ const isValid = computed(() => {
// inits indexing and publishes ipns entry for it
// inits indexing and publishes ipns entry for it
async
function
initIndex
()
{
async
function
initIndex
()
{
// initialize index to empty inode
targetCID
.
value
=
EMPTY_NODE_CID
const
rootnode
=
emptyInode
()
const
rootcid
=
await
kubo
.
dag
.
put
(
rootnode
)
// publish result to ipns
// publish result to ipns
const
res
=
await
kubo
.
name
.
publish
(
rootcid
,
{
ttl
:
'
1s
'
})
kubo
.
name
.
publish
(
EMPTY_NODE_CID
,
{
ttl
:
'
1s
'
}).
then
(
console
.
log
)
console
.
log
(
res
)
// track it on the history
rootnodeipns
.
value
=
res
.
name
updateHist
(
EMPTY_NODE_CID
)
// resolve again to confirm publish result
resolve
()
// update history accordingly
updateHist
(
rootcid
as
CID
)
}
}
// inits indexing and publishes ipns entry for it
// inits indexing and publishes ipns entry for it
async
function
initIndexHist
()
{
async
function
initIndexHist
()
{
const
firstHist
:
IndexHist
=
{
const
firstHist
:
IndexHist
=
{
last_history
:
null
,
last_history
:
null
,
current_index
:
targetC
id
.
value
!
,
current_index
:
targetC
ID
.
value
!
,
number
:
0
,
number
:
0
,
timestamp
:
Date
.
now
()
timestamp
:
Date
.
now
()
}
}
const
histcid
=
await
kubo
.
dag
.
put
(
firstHist
)
const
firstHistCID
=
await
kubo
.
dag
.
put
(
firstHist
)
const
res
=
await
kubo
.
name
.
publish
(
histcid
,
{
ttl
:
'
1s
'
,
key
:
'
index_history
'
})
kubo
.
name
.
publish
(
firstHistCID
,
{
ttl
:
'
1s
'
,
key
:
'
index_history
'
}).
then
(
console
.
log
)
console
.
log
(
res
)
historyipns
.
value
=
res
.
name
}
}
async
function
resolve
()
{
// resolve given ipns
for
await
(
const
name
of
kubo
.
name
.
resolve
(
IPNS
,
{
nocache
:
true
}))
{
async
function
resolveIPNS
(
ipns
:
string
):
Promise
<
CID
>
{
ipnsTarget
.
value
=
name
targetCid
.
value
=
CID
.
parse
(
name
.
slice
(
6
))
}
}
async
function
resolveHist
():
Promise
<
CID
>
{
let
cid
=
null
let
cid
=
null
for
await
(
const
name
of
kubo
.
name
.
resolve
(
IPNS_HIST
,
{
nocache
:
true
}))
{
for
await
(
const
name
of
kubo
.
name
.
resolve
(
ipns
,
{
nocache
:
true
}))
{
cid
=
CID
.
parse
(
name
.
slice
(
6
))
cid
=
CID
.
parse
(
name
.
slice
(
6
))
histCid
.
value
=
cid
}
}
return
cid
!
return
cid
!
}
}
// update history chain with new cid
async
function
updateHist
(
cid
:
CID
)
{
async
function
updateHist
(
cid
:
CID
)
{
const
lastHist
=
await
kubo
.
dag
.
get
(
cid
)
const
lastHistCID
=
await
resolveIPNS
(
IPNS_HIST
)
const
hist
:
IndexHist
=
{
const
lastHist
=
(
await
kubo
.
dag
.
get
(
lastHistCID
)).
value
last_history
:
await
resolveHist
(),
const
newHist
:
IndexHist
=
{
last_history
:
lastHistCID
,
current_index
:
cid
,
current_index
:
cid
,
number
:
lastHist
.
value
.
number
+
1
,
number
:
lastHist
.
number
+
1
,
timestamp
:
Date
.
now
()
timestamp
:
Date
.
now
()
}
}
const
histcid
=
await
kubo
.
dag
.
put
(
h
ist
)
const
newHistCID
=
await
kubo
.
dag
.
put
(
newH
ist
)
const
res
=
await
kubo
.
name
.
publish
(
histcid
,
{
ttl
:
'
1s
'
,
key
:
'
index_history
'
})
kubo
.
name
.
publish
(
newHistCID
,
{
ttl
:
'
1s
'
,
key
:
'
index_history
'
})
}
}
// publish cid to IPNS
function
setTargetCid
()
{
function
setTargetCid
()
{
if
(
isValid
.
value
)
{
if
(
isValid
.
value
)
{
const
cid
=
CID
.
parse
(
m
sg
.
value
)
const
cid
=
CID
.
parse
(
targetM
sg
.
value
)
targetC
id
.
value
=
cid
targetC
ID
.
value
=
cid
kubo
.
name
.
publish
(
cid
,
{
ttl
:
'
1s
'
})
.
then
((
_
)
=>
resolve
())
kubo
.
name
.
publish
(
cid
,
{
ttl
:
'
1s
'
})
}
else
{
}
else
{
targetC
id
.
value
=
null
targetC
ID
.
value
=
null
}
}
}
}
onMounted
(()
=>
{
onMounted
(()
=>
{
resolve
(
)
resolve
IPNS
(
IPNS
).
then
((
c
)
=>
(
targetCID
.
value
=
c
)
)
resolve
Hist
(
)
resolve
IPNS
(
IPNS_HIST
).
then
((
c
)
=>
(
histCID
.
value
=
c
)
)
})
})
</
script
>
</
script
>
<
template
>
<
template
>
<div>
<div>
<h1>
IPNS
(TODO improve)
</h1>
<h1>
IPNS
</h1>
<p>
Info about IPNS entries
</p>
<p>
Info about IPNS entries
</p>
<p>
initialize empty index:
<button
@
click=
"initIndex"
>
reinitialize ⚠️
</button></p>
<h2>
Index root
</h2>
<p>
<p>
Root node IPNS
</p>
root node ipns:
<span
class=
"mono"
>
/ipns/
{{
rootnodeipns
}}
</span>
</p>
<p>
You can use it to configure root node instead of hardcoded one:
</p>
<p
class=
"mono"
>
{{
IPNS
}}
</p>
<p
class=
"mono"
>
{{
IPNS
}}
</p>
<p>
which is pointing to
<button
@
click=
"resolve"
>
resolve
</button></p>
<p>
is pointing to
</p>
<p
class=
"mono"
>
{{
ipnsTarget
}}
</p>
<p
class=
"mono"
>
{{
targetCID
}}
</p>
<p>
initialize empty index:
<button
@
click=
"initIndex"
>
reinitialize ⚠️
</button></p>
<p>
<p>
set
IPNS target cid
or
set
to custom CID
<br
/>
<input
v-model=
"
m
sg"
@
keyup.enter=
"setTargetCid"
/>
<input
v-model=
"
targetM
sg"
@
keyup.enter=
"setTargetCid"
size=
"50"
/>
<button
v-on:click=
"setTargetCid"
>
Set ⚠️
</button>
<button
v-on:click=
"setTargetCid"
>
Set ⚠️
</button>
</p>
</p>
<h2>
Index history
</h2>
<h2>
Index history
</h2>
<p>
<p>
History IPNS
</p>
initialize
<button
@
click=
"initIndexHist"
>
reinitialize history ⚠️
</button>
<p
class=
"mono"
>
{{
IPNS_HIST
}}
</p>
<span
class=
"mono"
>
/ipns/
{{
historyipns
}}
</span>
<p>
is pointing to
</p>
</p>
<p
class=
"mono"
>
{{
histCID
}}
</p>
<p>
reinitialize history to current target cid
<button
@
click=
"initIndexHist"
>
reinitialize ⚠️
</button></p>
<p>
and got to
<RouterLink
to=
"/index"
>
index
</RouterLink>
to see more about index history
</p>
</div>
</div>
</
template
>
</
template
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment