Commit 8905bee234248703ba30c218618022d453d48dee
Implement offline browsing "last" mode
cel committed on 12/17/2019, 4:20:57 AMParent: db27d78788c79045c2250b824da6224adf277b6b
Files changed
Makefile | changed |
README.md | changed |
history.filter.dpi | changed |
Makefile | ||
---|---|---|
@@ -10,8 +10,11 @@ | ||
10 | 10 … | cp /etc/dillo/dpidrc $@ |
11 | 11 … | |
12 | 12 … | install-proto: $(DPIDRC) |
13 | 13 … | echo 'proto.history=$(NAME)/$(BIN)' >> $< |
14 … | + echo 'proto.last=$(NAME)/$(BIN)' >> $< | |
15 … | + echo 'proto.last-http=$(NAME)/$(BIN)' >> $< | |
16 … | + echo 'proto.last-https=$(NAME)/$(BIN)' >> $< | |
14 | 17 … | |
15 | 18 … | install: $(BIN) install-proto |
16 | 19 … | mkdir -p $(DPI_DIR)/$(NAME) |
17 | 20 … | cp -f $(BIN) $(DPI_DIR)/$(NAME) |
README.md | ||
---|---|---|
@@ -9,8 +9,10 @@ | ||
9 | 9 … | The history file is `~/.dillo/history.txt` and its format is TSV. Each entry contains a timestamp, SHA256 content hash, and URL. |
10 | 10 … | |
11 | 11 … | The plugin serves requests of the form `history:[<limit>][/<pattern>]` where `<limit>` is the number of entries to show (default is 35) and `<pattern>` is a regex to grep for the history files (for URL, hash, and/or timestamp) (default is to show all entries). |
12 | 12 … | |
13 … | +The plugin also serves request of the form `last:<url>`, or `last-<url>` for schemas `http` and `https`. These are served with the contents of the last blob recorded for the given URL (with the "last:" or "last-" prefix removed). This is effectively an offline browsing mode. Relative URLs work when using the "last-" prefix but not with the "last:" prefix. | |
14 … | + | |
13 | 15 … | ## Screenshot |
14 | 16 … | |
15 | 17 … |  |
16 | 18 … | |
@@ -24,11 +26,7 @@ | ||
24 | 26 … | |
25 | 27 … | Install the plugin with `make install && dpidc stop`. |
26 | 28 … | Install the patch by downloading Dillo's source code, applying the patch and compiling dillo. |
27 | 29 … | |
28 | -## Future work | |
29 | - | |
30 | -Make a HTTP proxy or patch for dillo to allow for navigating the web in an offine mode, by serving requests with the last known content for their URL from the history file. Similarly, make a time travel mode where it would use only history entries before a certain date. It could allow for navigating between different versions of the same URL that were recorded at different times. | |
31 | - | |
32 | 30 … | ## License |
33 | 31 … | |
34 | 32 … | MIT |
history.filter.dpi | |||
---|---|---|---|
@@ -7,18 +7,21 @@ | |||
7 | 7 … | esac | |
8 | 8 … | url=${cmd#"<cmd='open_url' url='"} | |
9 | 9 … | url=${url%"' '"} | |
10 | 10 … | ||
11 … | +dillo_dir=${0%/*/*/*} | ||
12 … | +history_file=$dillo_dir/history.txt | ||
13 … | + | ||
11 | 14 … | serve_404() { | |
12 | - printf "<cmd='start_send_page' url='' '>\n" | ||
15 … | + printf "<cmd='start_send_page' url='' '>" | ||
13 | 16 … | printf "Content-type: text/plain\r\n\r\n" | |
14 | 17 … | echo Not found | |
15 | 18 … | } | |
16 | 19 … | ||
17 | 20 … | serve_history() { | |
18 | 21 … | limit=${1:-35} | |
19 | 22 … | grep=$2 | |
20 | - printf "<cmd='start_send_page' url='' '>\n" | ||
23 … | + printf "<cmd='start_send_page' url='' '>" | ||
21 | 24 … | printf "Content-type: text/html\r\n\r\n" | |
22 | 25 … | cat <<-EOF | |
23 | 26 … | <!doctype html> | |
24 | 27 … | <html> | |
@@ -28,10 +31,8 @@ | |||
28 | 31 … | </head> | |
29 | 32 … | <body> | |
30 | 33 … | EOF | |
31 | 34 … | exec 2>&1 | |
32 | - dillo_dir=${0%/*/*/*} | ||
33 | - history_file=$dillo_dir/history.txt | ||
34 | 35 … | if [ -n "$grep" ]; then grep "$grep"; else cat | |
35 | 36 … | fi < "$history_file" | tail -n $limit | tac | awk ' | |
36 | 37 … | { | |
37 | 38 … | timestamp = $1 " " $2 | |
@@ -46,9 +47,35 @@ | |||
46 | 47 … | </html> | |
47 | 48 … | EOF | |
48 | 49 … | } | |
49 | 50 … | ||
51 … | +serve_last() { | ||
52 … | + url=$1 | ||
53 … | + blob=$(tac "$history_file" | awk -v url="$url" '$5 == url {print $4; exit}') | ||
54 … | + if [ -z "$blob" ] | ||
55 … | + then | ||
56 … | + printf "<cmd='send_status_message' msg='Not found' '>" | ||
57 … | + printf "<cmd='start_send_page' url='' '>" | ||
58 … | + printf "\r\n\r\n" | ||
59 … | + printf "Not found" | ||
60 … | + return | ||
61 … | + fi | ||
62 … | + if ! file="$(ssb-blob-path "$blob")" | ||
63 … | + then | ||
64 … | + printf "<cmd='send_status_message' msg='Unable to get blob id' '>" | ||
65 … | + printf "<cmd='start_send_page' url='' '>" | ||
66 … | + printf "\r\n\r\n" | ||
67 … | + printf "Unable to get blob id" | ||
68 … | + return | ||
69 … | + fi | ||
70 … | + printf "<cmd='start_send_page' url='' '>" | ||
71 … | + printf "\r\n\r\n" | ||
72 … | + cat "$file" | ||
73 … | +} | ||
74 … | + | ||
50 | 75 … | case "$url" in | |
51 | 76 … | history:*/*) a="${url#history:}"; serve_history "${a%/*}" "${a#*/}";; | |
52 | 77 … | history:*) serve_history "${url#history:}";; | |
78 … | + last:*) serve_last "${url#last:}";; | ||
79 … | + last-*) serve_last "${url#last-}";; | ||
53 | 80 … | *) serve_404;; | |
54 | 81 … | esac |
Built with git-ssb-web