1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/env tclsh
if {$argc < 2} { return -code error "Usage: bin/rmrepo.tcl DB ?-pds PDS? ?-feed FEED? REPO ?REPO ...?\n-feed may be passed repeatedly." }
cd [file dirname [file dirname [dict get [info frame [info frame]] file]]]
package require sqlite3
package require json
package require http
package require tls
::http::register https 443 ::tls::socket
set repos [lassign $argv db]
sqlite3 db $db
set pds "bsky.social"
if {[lindex $repos 0] == "-pds"} {
set repos [lassign $repos _ pds]
}
set block 1
while {[lindex $repos 0] == "-feed"} {
set block 0
set repos [lassign $repos _ feed]
lappend feeds $feed
}
if ![info exists feeds] {
set feeds [db eval {SELECT name FROM sqlite_master WHERE type = 'table' AND sql LIKE '%uri TEXT%'}]
}
foreach repo $repos {
switch -regexp -- $repo {
{^did:plc:.+} {}
default {
set endpoint "https://$pds/xrpc/com.atproto.repo.describeRepo"
set http_state [http::geturl "$endpoint?repo=$repo"]
if {[::http::ncode $http_state] != 200} { return -code error "couldn't resolve handle $repo!\n[::http::data $http_state]" }
set repo [dict get [::json::json2dict [::http::data $http_state]] did]
}
}
if $block {
db eval {INSERT OR IGNORE INTO blocked_repos VALUES (:repo);}
}
set repo_pat "%${repo}%"
foreach table $feeds {
db eval "DELETE FROM $table WHERE uri LIKE :repo_pat;"
}
}