|
| 1 | +import FNV1 |
| 2 | +import HTML |
| 3 | +import UnidocAPI |
| 4 | +import UnidocServer |
| 5 | + |
| 6 | +extension Unidoc.GraphLinker |
| 7 | +{ |
| 8 | + @frozen public |
| 9 | + enum Event:Sendable |
| 10 | + { |
| 11 | + case uplinked(Unidoc.UplinkStatus) |
| 12 | + case unlinked(Unidoc.UnlinkStatus) |
| 13 | + case deleted(Unidoc.DeleteStatus) |
| 14 | + case failed(Unidoc.Edition, action:Unidoc.LinkerAction) |
| 15 | + } |
| 16 | +} |
| 17 | +extension Unidoc.GraphLinker.Event:Unidoc.PluginEvent |
| 18 | +{ |
| 19 | + public |
| 20 | + func h3(_ h3:inout HTML.ContentEncoder) |
| 21 | + { |
| 22 | + switch self |
| 23 | + { |
| 24 | + case .uplinked: h3 += "Volume uplinked" |
| 25 | + case .unlinked: h3 += "Volume unlinked" |
| 26 | + case .deleted: h3 += "Volume deleted" |
| 27 | + case .failed: h3 += "Action failed" |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + public |
| 32 | + func dl(_ dl:inout HTML.ContentEncoder) |
| 33 | + { |
| 34 | + switch self |
| 35 | + { |
| 36 | + case .uplinked(let uplinked): |
| 37 | + dl[.dt] = "Edition" |
| 38 | + dl[.dd] = "\(uplinked.edition)" |
| 39 | + |
| 40 | + dl[.dt] = "Volume" |
| 41 | + dl[.dd] = "\(uplinked.volume)" |
| 42 | + |
| 43 | + dl[.dt] = "Hidden?" |
| 44 | + dl[.dd] = uplinked.hidden ? "yes" : "no" |
| 45 | + |
| 46 | + guard |
| 47 | + let delta:Unidoc.SurfaceDelta = uplinked.delta |
| 48 | + else |
| 49 | + { |
| 50 | + return |
| 51 | + } |
| 52 | + |
| 53 | + dl[.dt] = "Delta" |
| 54 | + |
| 55 | + let api:Unidoc.SitemapDelta? |
| 56 | + |
| 57 | + switch delta |
| 58 | + { |
| 59 | + case .initial: |
| 60 | + dl[.dd] = "Initial" |
| 61 | + return |
| 62 | + |
| 63 | + case .ignoredHistorical: |
| 64 | + dl[.dd] = "Ignored historical" |
| 65 | + return |
| 66 | + |
| 67 | + case .ignoredPrivate: |
| 68 | + dl[.dd] = "Ignored private" |
| 69 | + return |
| 70 | + |
| 71 | + case .ignoredRepeated(let delta): |
| 72 | + dl[.dd] = "Ignored repeated" |
| 73 | + api = delta |
| 74 | + |
| 75 | + case .replaced(let delta): |
| 76 | + dl[.dd] = "Replaced" |
| 77 | + api = delta |
| 78 | + } |
| 79 | + |
| 80 | + guard |
| 81 | + let api:Unidoc.SitemapDelta |
| 82 | + else |
| 83 | + { |
| 84 | + return |
| 85 | + } |
| 86 | + |
| 87 | + for (list, name):([Unidoc.Shoot], String) in [ |
| 88 | + (api.deletions, "Deletions"), |
| 89 | + (api.additions, "Additions") |
| 90 | + ] where !list.isEmpty |
| 91 | + { |
| 92 | + dl[.dt] = name |
| 93 | + dl[.dd] |
| 94 | + { |
| 95 | + $0[.ol] |
| 96 | + { |
| 97 | + for shoot:Unidoc.Shoot in list |
| 98 | + { |
| 99 | + if let hash:FNV24 = shoot.hash |
| 100 | + { |
| 101 | + $0[.li] = "\(shoot.stem) [\(hash)]" |
| 102 | + } |
| 103 | + else |
| 104 | + { |
| 105 | + $0[.li] = "\(shoot.stem)" |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + case .unlinked(let unlinked): |
| 113 | + switch unlinked |
| 114 | + { |
| 115 | + case .unlinked(let edition): |
| 116 | + dl[.dt] = "Unlinked" |
| 117 | + dl[.dd] = "\(edition)" |
| 118 | + |
| 119 | + case .declined(let edition): |
| 120 | + dl[.dt] = "Declined" |
| 121 | + dl[.dd] = "\(edition)" |
| 122 | + } |
| 123 | + |
| 124 | + case .deleted(let deleted): |
| 125 | + switch deleted |
| 126 | + { |
| 127 | + case .deleted(let edition, let fromS3): |
| 128 | + dl[.dt] = "Deleted" |
| 129 | + dl[.dd] = "\(edition)" |
| 130 | + |
| 131 | + dl[.dt] = "From S3?" |
| 132 | + dl[.dd] = fromS3 ? "yes" : "no" |
| 133 | + |
| 134 | + case .declined(let edition): |
| 135 | + dl[.dt] = "Declined" |
| 136 | + dl[.dd] = "\(edition)" |
| 137 | + } |
| 138 | + |
| 139 | + case .failed(let edition, action: let action): |
| 140 | + dl[.dt] = "Edition" |
| 141 | + dl[.dd] = "\(edition)" |
| 142 | + |
| 143 | + dl[.dt] = "Action" |
| 144 | + dl[.dd] = "\(action)" |
| 145 | + } |
| 146 | + } |
| 147 | +} |
0 commit comments