diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 43 | ||||
| -rw-r--r-- | db/db.go | 10 | ||||
| -rw-r--r-- | server/server.go | 12 | ||||
| -rw-r--r-- | services-full.json | 2 | ||||
| -rw-r--r-- | services.json | 2 | ||||
| -rw-r--r-- | services/mappings.go | 2 |
7 files changed, 33 insertions, 39 deletions
@@ -1,2 +1,3 @@ badger-db farside +deploy.sh @@ -54,39 +54,19 @@ For example: <td>Farside Link</td> </tr> <tr> - <td><a href="https://github.com/spikecodes/libreddit">Libreddit</a></td> - <td>/r/popular</td> - <td><a href="https://farside.link/libreddit/r/popular">https://farside.link/libreddit/r/popular</a></td> + <td><a href="https://sr.ht/~edwardloveall/Scribe/">Scribe</a></td> + <td>View Medium post</td> + <td><a href="https://farside.link/scribe/@ftrain/big-data-small-effort-b62607a43a8c">https://farside.link/scribe/@ftrain/big-data-small-effort-b62607a43a8c</a></td> </tr> <tr> - <td><a href="https://codeberg.org/teddit/teddit">Teddit</a></td> + <td><a href="https://github.com/spikecodes/libreddit">Libreddit</a></td> <td>/r/popular</td> - <td><a href="https://farside.link/teddit/r/popular">https://farside.link/teddit/r/popular</a></td> - </tr> - <tr> - <td><a href="https://github.com/zedeus/nitter">Nitter</a></td> - <td>User Profile</td> - <td><a href="https://farside.link/nitter/josevalim">https://farside.link/nitter/josevalim</a></td> - </tr> - <tr> - <td><a href="https://github.com/iv-org/invidious">Invidious</a></td> - <td>Home Page</td> - <td><a href="https://farside.link/invidious">https://farside.link/invidious</a></td> - </tr> - <tr> - <td><a href="https://github.com/TeamPiped/Piped">Piped</a></td> - <td>Video Page</td> - <td><a href="https://farside.link/piped/watch?v=eBGIQ7ZuuiU">https://farside.link/piped/watch?v=eBGIQ7ZuuiU</a></td> - </tr> - <tr> - <td><a href="https://github.com/benbusby/whoogle-search">Whoogle</a></td> - <td>Search "Elixir"</td> - <td><a href="https://farside.link/whoogle/search?q=elixir&lang_interface=en">https://farside.link/whoogle/search?q=elixir&lang_interface=en</a></td> + <td><a href="https://farside.link/libreddit/r/popular">https://farside.link/libreddit/r/popular</a></td> </tr> <tr> - <td><a href="https://github.com/searx/searx">SearX</a></td> - <td>Search "Redis"</td> - <td><a href="https://farside.link/searx/search?q=redis">https://farside.link/searx/search?q=redis</a></td> + <td><a href="https://gitdab.com/cadence/breezewiki">BreezeWiki</a></td> + <td>Balatro Wiki</td> + <td><a href="https://farside.link/breezewiki/balatrogame">https://farside.link/https://balatrogame.fandom.com</a></td> </tr> <tr> <td><a href="https://github.com/searxng/searxng">SearXNG</a></td> @@ -108,18 +88,13 @@ For example: <td>View photo album</td> <td><a href="https://farside.link/rimgo/a/H8M4rcp">https://farside.link/rimgo/a/H8M4rcp</a></td> </tr> - <tr> - <td><a href="https://sr.ht/~edwardloveall/Scribe/">Scribe</a></td> - <td>View Medium post</td> - <td><a href="https://farside.link/scribe/@ftrain/big-data-small-effort-b62607a43a8c">https://farside.link/scribe/@ftrain/big-data-small-effort-b62607a43a8c</a></td> - </tr> </table> <sup>Note: This table doesn't include all available services. For a complete list of supported frontends, see: https://farside.link</sup> Farside also accepts URLs to "parent" services, and will redirect to an appropriate front end service, for example: -- https://farside.link/https://www.youtube.com/watch?v=dQw4w9WgXcQ will redirect to a [Piped](https://github.com/TeamPiped/Piped) or [Invidious](https://github.com/iv-org/invidious) instance +- https://farside.link/https://balatrogame.fandom.com/wiki/Abandoned_Deck will redirect to a [BreezeWiki](https://gitdab.com/cadence/breezewiki) instance - https://farside.link/reddit.com/r/popular will redirect to a [Libreddit](https://github.com/spikecodes/libreddit) or [Teddit](https://codeberg.org/teddit/teddit) instance - etc. @@ -3,10 +3,12 @@ package db import ( "encoding/json" "errors" + "fmt" "log" "math/rand" "os" "slices" + "strings" "time" "github.com/benbusby/farside/services" @@ -55,7 +57,7 @@ func SetInstances(service string, instances []string) error { return nil } -func GetInstance(service string) (string, error) { +func GetInstance(service, path string) (string, error) { instances, err := GetAllInstances(service) if err != nil || len(instances) == 0 { if err != nil { @@ -80,6 +82,12 @@ func GetInstance(service string) (string, error) { index := rand.Intn(len(instances)) value := instances[index] selectionMap[service] = value + + if len(path) > 0 { + value = strings.TrimSuffix(value, "/") + value = fmt.Sprintf("%s/%s", value, path) + } + return value, nil } diff --git a/server/server.go b/server/server.go index 0a0b683..74bfa6c 100644 --- a/server/server.go +++ b/server/server.go @@ -86,7 +86,17 @@ func routing(w http.ResponseWriter, r *http.Request, jsEnabled bool) { return } - instance, err := db.GetInstance(target) + var servicePath string + if target == "breezewiki" { + // Breezewiki requires the subdomain of the instance to be + // preserved for correct routing + splitDomain := strings.Split(path, ".") + if len(splitDomain) > 2 { + servicePath = strings.Split(path, ".")[0] + } + } + + instance, err := db.GetInstance(target, servicePath) if err != nil { log.Printf("Error fetching instance from db: %v\n", err) http.Error( diff --git a/services-full.json b/services-full.json index ad54de6..c03cc22 100644 --- a/services-full.json +++ b/services-full.json @@ -483,7 +483,7 @@ }, { "type": "breezewiki", - "test_url": "/undertale/wiki/Hot_Dog...%3F", + "test_url": "/balatrogame/wiki/Abandoned_Deck", "fallback": "https://breezewiki.com", "instances": [ "https://breezewiki.com", diff --git a/services.json b/services.json index beb411d..7e990c2 100644 --- a/services.json +++ b/services.json @@ -449,7 +449,7 @@ }, { "type": "breezewiki", - "test_url": "/undertale/wiki/Hot_Dog...%3F", + "test_url": "/balatrogame/wiki/Abandoned_Deck", "fallback": "https://breezewiki.com", "instances": [ "https://breezewiki.com", diff --git a/services/mappings.go b/services/mappings.go index 53731a6..172e1cd 100644 --- a/services/mappings.go +++ b/services/mappings.go @@ -69,7 +69,7 @@ var regexMap = []RegexMapping{ }, { // Fandom - Pattern: regexp.MustCompile(`fandom\.com|breezewiki`), + Pattern: regexp.MustCompile(`.*fandom\.com|breezewiki`), Targets: []string{"breezewiki"}, }, { |
