1
0
Fork 0
mirror of https://github.com/benbusby/farside.git synced 2025-04-20 02:48:42 +00:00

Update breezewiki routing behavior, update readme

BreezeWiki requires the subdomain of a fandom link to be preserved when
routing, otherwise the redirect doesn't work correctly.

Cleaned up readme examples
This commit is contained in:
Ben Busby 2025-01-27 12:17:20 -07:00
parent 3d52cddc66
commit 6e64a93fd1
No known key found for this signature in database
GPG key ID: B9B7231E01D924A1
7 changed files with 33 additions and 39 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
badger-db badger-db
farside farside
deploy.sh

View file

@ -53,40 +53,20 @@ For example:
<td>Page</td> <td>Page</td>
<td>Farside Link</td> <td>Farside Link</td>
</tr> </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>
<tr> <tr>
<td><a href="https://github.com/spikecodes/libreddit">Libreddit</a></td> <td><a href="https://github.com/spikecodes/libreddit">Libreddit</a></td>
<td>/r/popular</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://farside.link/libreddit/r/popular">https://farside.link/libreddit/r/popular</a></td>
</tr> </tr>
<tr> <tr>
<td><a href="https://codeberg.org/teddit/teddit">Teddit</a></td> <td><a href="https://gitdab.com/cadence/breezewiki">BreezeWiki</a></td>
<td>/r/popular</td> <td>Balatro Wiki</td>
<td><a href="https://farside.link/teddit/r/popular">https://farside.link/teddit/r/popular</a></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/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>
</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>
</tr> </tr>
<tr> <tr>
<td><a href="https://github.com/searxng/searxng">SearXNG</a></td> <td><a href="https://github.com/searxng/searxng">SearXNG</a></td>
@ -108,18 +88,13 @@ For example:
<td>View photo album</td> <td>View photo album</td>
<td><a href="https://farside.link/rimgo/a/H8M4rcp">https://farside.link/rimgo/a/H8M4rcp</a></td> <td><a href="https://farside.link/rimgo/a/H8M4rcp">https://farside.link/rimgo/a/H8M4rcp</a></td>
</tr> </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> </table>
<sup>Note: This table doesn't include all available services. For a complete list of supported frontends, see: https://farside.link</sup> <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: 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 - 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. - etc.

View file

@ -3,10 +3,12 @@ package db
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"log" "log"
"math/rand" "math/rand"
"os" "os"
"slices" "slices"
"strings"
"time" "time"
"github.com/benbusby/farside/services" "github.com/benbusby/farside/services"
@ -55,7 +57,7 @@ func SetInstances(service string, instances []string) error {
return nil return nil
} }
func GetInstance(service string) (string, error) { func GetInstance(service, path string) (string, error) {
instances, err := GetAllInstances(service) instances, err := GetAllInstances(service)
if err != nil || len(instances) == 0 { if err != nil || len(instances) == 0 {
if err != nil { if err != nil {
@ -80,6 +82,12 @@ func GetInstance(service string) (string, error) {
index := rand.Intn(len(instances)) index := rand.Intn(len(instances))
value := instances[index] value := instances[index]
selectionMap[service] = value selectionMap[service] = value
if len(path) > 0 {
value = strings.TrimSuffix(value, "/")
value = fmt.Sprintf("%s/%s", value, path)
}
return value, nil return value, nil
} }

View file

@ -86,7 +86,17 @@ func routing(w http.ResponseWriter, r *http.Request, jsEnabled bool) {
return 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 { if err != nil {
log.Printf("Error fetching instance from db: %v\n", err) log.Printf("Error fetching instance from db: %v\n", err)
http.Error( http.Error(

View file

@ -483,7 +483,7 @@
}, },
{ {
"type": "breezewiki", "type": "breezewiki",
"test_url": "/undertale/wiki/Hot_Dog...%3F", "test_url": "/balatrogame/wiki/Abandoned_Deck",
"fallback": "https://breezewiki.com", "fallback": "https://breezewiki.com",
"instances": [ "instances": [
"https://breezewiki.com", "https://breezewiki.com",

View file

@ -449,7 +449,7 @@
}, },
{ {
"type": "breezewiki", "type": "breezewiki",
"test_url": "/undertale/wiki/Hot_Dog...%3F", "test_url": "/balatrogame/wiki/Abandoned_Deck",
"fallback": "https://breezewiki.com", "fallback": "https://breezewiki.com",
"instances": [ "instances": [
"https://breezewiki.com", "https://breezewiki.com",

View file

@ -69,7 +69,7 @@ var regexMap = []RegexMapping{
}, },
{ {
// Fandom // Fandom
Pattern: regexp.MustCompile(`fandom\.com|breezewiki`), Pattern: regexp.MustCompile(`.*fandom\.com|breezewiki`),
Targets: []string{"breezewiki"}, Targets: []string{"breezewiki"},
}, },
{ {