tangled
alpha
login
or
join now
margin.at
/
margin
87
fork
atom
Write on the margins of the internet. Powered by the AT Protocol.
margin.at
extension
web
atproto
comments
87
fork
atom
overview
issues
4
pulls
1
pipelines
add repair-on-read for missing annotation cids
scanash.com
1 month ago
6d019a50
ae1828a5
+90
-12
4 changed files
expand all
collapse all
unified
split
backend
internal
api
handler.go
web
src
api
client.js
components
AnnotationCard.jsx
pages
Login.jsx
+86
backend/internal/api/handler.go
···
619
619
}
620
620
621
621
if annotation, err := h.db.GetAnnotationByURI(uri); err == nil {
622
622
+
if annotation.CID == nil || *annotation.CID == "" {
623
623
+
parts := parseATURI(uri)
624
624
+
if len(parts) >= 3 {
625
625
+
did := parts[0]
626
626
+
collection := parts[1]
627
627
+
rkey := parts[2]
628
628
+
629
629
+
session, err := h.refresher.GetSessionWithAutoRefresh(r)
630
630
+
if err == nil {
631
631
+
_ = h.refresher.ExecuteWithAutoRefresh(r, session, func(client *xrpc.Client, _ string) error {
632
632
+
record, getErr := client.GetRecord(r.Context(), did, collection, rkey)
633
633
+
if getErr == nil {
634
634
+
h.db.UpdateAnnotation(uri, *annotation.BodyValue, *annotation.TagsJSON, record.CID)
635
635
+
cid := record.CID
636
636
+
annotation.CID = &cid
637
637
+
}
638
638
+
return nil
639
639
+
})
640
640
+
}
641
641
+
}
642
642
+
}
643
643
+
622
644
if enriched, _ := hydrateAnnotations(h.db, []db.Annotation{*annotation}, h.getViewerDID(r)); len(enriched) > 0 {
623
645
serveResponse(enriched[0], "http://www.w3.org/ns/anno.jsonld")
624
646
return
···
626
648
}
627
649
628
650
if highlight, err := h.db.GetHighlightByURI(uri); err == nil {
651
651
+
if highlight.CID == nil || *highlight.CID == "" {
652
652
+
parts := parseATURI(uri)
653
653
+
if len(parts) >= 3 {
654
654
+
did := parts[0]
655
655
+
collection := parts[1]
656
656
+
rkey := parts[2]
657
657
+
658
658
+
session, err := h.refresher.GetSessionWithAutoRefresh(r)
659
659
+
if err == nil {
660
660
+
_ = h.refresher.ExecuteWithAutoRefresh(r, session, func(client *xrpc.Client, _ string) error {
661
661
+
record, getErr := client.GetRecord(r.Context(), did, collection, rkey)
662
662
+
if getErr == nil {
663
663
+
tagsJSON := ""
664
664
+
if highlight.TagsJSON != nil {
665
665
+
tagsJSON = *highlight.TagsJSON
666
666
+
}
667
667
+
color := ""
668
668
+
if highlight.Color != nil {
669
669
+
color = *highlight.Color
670
670
+
}
671
671
+
h.db.UpdateHighlight(uri, color, tagsJSON, record.CID)
672
672
+
cid := record.CID
673
673
+
highlight.CID = &cid
674
674
+
}
675
675
+
return nil
676
676
+
})
677
677
+
}
678
678
+
}
679
679
+
}
680
680
+
629
681
if enriched, _ := hydrateHighlights(h.db, []db.Highlight{*highlight}, h.getViewerDID(r)); len(enriched) > 0 {
630
682
serveResponse(enriched[0], "http://www.w3.org/ns/anno.jsonld")
631
683
return
···
670
722
}
671
723
672
724
if bookmark, err := h.db.GetBookmarkByURI(uri); err == nil {
725
725
+
if bookmark.CID == nil || *bookmark.CID == "" {
726
726
+
parts := parseATURI(uri)
727
727
+
if len(parts) >= 3 {
728
728
+
did := parts[0]
729
729
+
collection := parts[1]
730
730
+
rkey := parts[2]
731
731
+
732
732
+
session, err := h.refresher.GetSessionWithAutoRefresh(r)
733
733
+
if err == nil {
734
734
+
_ = h.refresher.ExecuteWithAutoRefresh(r, session, func(client *xrpc.Client, _ string) error {
735
735
+
record, getErr := client.GetRecord(r.Context(), did, collection, rkey)
736
736
+
if getErr == nil {
737
737
+
tagsJSON := ""
738
738
+
if bookmark.TagsJSON != nil {
739
739
+
tagsJSON = *bookmark.TagsJSON
740
740
+
}
741
741
+
title := ""
742
742
+
if bookmark.Title != nil {
743
743
+
title = *bookmark.Title
744
744
+
}
745
745
+
desc := ""
746
746
+
if bookmark.Description != nil {
747
747
+
desc = *bookmark.Description
748
748
+
}
749
749
+
h.db.UpdateBookmark(uri, title, desc, tagsJSON, record.CID)
750
750
+
cid := record.CID
751
751
+
bookmark.CID = &cid
752
752
+
}
753
753
+
return nil
754
754
+
})
755
755
+
}
756
756
+
}
757
757
+
}
758
758
+
673
759
if enriched, _ := hydrateBookmarks(h.db, []db.Bookmark{*bookmark}, h.getViewerDID(r)); len(enriched) > 0 {
674
760
serveResponse(enriched[0], "http://www.w3.org/ns/anno.jsonld")
675
761
return
-2
web/src/api/client.js
···
501
501
export async function deleteAPIKey(id) {
502
502
return request(`${API_BASE}/keys/${id}`, { method: "DELETE" });
503
503
}
504
504
-
505
505
-
+2
-2
web/src/components/AnnotationCard.jsx
···
382
382
{data.tags.map((tag, i) => (
383
383
<Link
384
384
key={i}
385
385
-
to={`/?tag=${encodeURIComponent(tag)}`}
385
385
+
to={`/home?tag=${encodeURIComponent(tag)}`}
386
386
className="annotation-tag"
387
387
>
388
388
#{tag}
···
637
637
{data.tags.map((tag, i) => (
638
638
<Link
639
639
key={i}
640
640
-
to={`/?tag=${encodeURIComponent(tag)}`}
640
640
+
to={`/home?tag=${encodeURIComponent(tag)}`}
641
641
className="annotation-tag"
642
642
>
643
643
#{tag}
+2
-8
web/src/pages/Login.jsx
···
247
247
)}
248
248
</div>
249
249
250
250
-
251
251
-
252
250
{error && <p className="login-error">{error}</p>}
253
251
254
252
<button
255
253
type="submit"
256
254
className="btn btn-primary login-submit"
257
257
-
disabled={
258
258
-
loading || !handle.trim()
259
259
-
}
255
255
+
disabled={loading || !handle.trim()}
260
256
>
261
261
-
{loading
262
262
-
? "Connecting..."
263
263
-
: "Continue"}
257
257
+
{loading ? "Connecting..." : "Continue"}
264
258
</button>
265
259
266
260
<p className="login-legal">