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:
parent
3d52cddc66
commit
6e64a93fd1
7 changed files with 33 additions and 39 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
badger-db
|
||||
farside
|
||||
deploy.sh
|
||||
|
|
43
README.md
43
README.md
|
@ -53,40 +53,20 @@ For example:
|
|||
<td>Page</td>
|
||||
<td>Farside Link</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>
|
||||
<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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="https://codeberg.org/teddit/teddit">Teddit</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>
|
||||
</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.
|
||||
|
||||
|
|
10
db/db.go
10
db/db.go
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -69,7 +69,7 @@ var regexMap = []RegexMapping{
|
|||
},
|
||||
{
|
||||
// Fandom
|
||||
Pattern: regexp.MustCompile(`fandom\.com|breezewiki`),
|
||||
Pattern: regexp.MustCompile(`.*fandom\.com|breezewiki`),
|
||||
Targets: []string{"breezewiki"},
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue