Add rewriting for twitter.com
This commit is contained in:
parent
5dfec51f41
commit
6ab26f9f7a
6 changed files with 32 additions and 6 deletions
|
@ -2,6 +2,7 @@ This project is a *fork* of [the original BirdsiteLIVE from NicolasConstant](htt
|
|||
|
||||
* Rework About page
|
||||
* Cache Tweets so that, for example, Announces do not hit rate limits
|
||||
* Allow replacing and redirecting to twitter.com in Tweets to other domains (i.e. Nitter instances)
|
||||
|
||||
This fork is also available as a Docker image as `pasture/birdsitelive`.
|
||||
|
||||
|
|
|
@ -46,7 +46,8 @@ If both whitelisting and blacklisting are set, only the whitelisting will be act
|
|||
* `Instance:Name` (default: BirdsiteLIVE) the name of the instance
|
||||
* `Instance:ResolveMentionsInProfiles` (default: true) to enable or disable mentions parsing in profile's description. Resolving it will consume more User's API calls since newly discovered account can also contain references to others accounts as well. On a big instance it is recommended to disable it.
|
||||
* `Instance:PublishReplies` (default: false) to enable or disable replies publishing.
|
||||
* `Instance:UnlistedTwitterAccounts` (default: null) to enable unlisted publication for selected twitter accounts, separated by `;` (please limit this to brands and other public profiles).
|
||||
* `Instance:UnlistedTwitterAccounts` (default: null) to enable unlisted publication for selected twitter accounts, separated by `;` (please limit this to brands and other public profiles).
|
||||
* `Instance:TwitterDomain` (default: twitter.com) redirect to a different domain (i.e. a Nitter instance) instead of Twitter
|
||||
|
||||
# Docker Compose full example
|
||||
|
||||
|
@ -60,7 +61,7 @@ networks:
|
|||
|
||||
services:
|
||||
server:
|
||||
image: nicolasconstant/birdsitelive:latest
|
||||
image: pasture/birdsitelive:latest
|
||||
[...]
|
||||
environment:
|
||||
- Instance:Domain=domain.name
|
||||
|
@ -78,11 +79,12 @@ services:
|
|||
+ - Instance:ResolveMentionsInProfiles=false
|
||||
+ - Instance:PublishReplies=true
|
||||
+ - Instance:UnlistedTwitterAccounts=cocacola;twitter
|
||||
+ - Instance:TwitterDomain=twiiit.com
|
||||
networks:
|
||||
[...]
|
||||
|
||||
db:
|
||||
image: postgres:9.6
|
||||
image: postgres:13
|
||||
[...]
|
||||
```
|
||||
|
||||
|
|
|
@ -10,5 +10,7 @@
|
|||
public int MaxUsersCapacity { get; set; }
|
||||
|
||||
public string UnlistedTwitterAccounts { get; set; }
|
||||
|
||||
public string TwitterDomain { get; set; }
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using BirdsiteLive.Common.Settings;
|
||||
using BirdsiteLive.Twitter.Models;
|
||||
using Tweetinvi.Models;
|
||||
using Tweetinvi.Models.Entities;
|
||||
|
@ -15,6 +16,15 @@ namespace BirdsiteLive.Twitter.Extractors
|
|||
|
||||
public class TweetExtractor : ITweetExtractor
|
||||
{
|
||||
private readonly InstanceSettings _instanceSettings;
|
||||
|
||||
#region Ctor
|
||||
public TweetExtractor(InstanceSettings instanceSettings)
|
||||
{
|
||||
this._instanceSettings = instanceSettings;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public ExtractedTweet Extract(ITweet tweet)
|
||||
{
|
||||
var extractedTweet = new ExtractedTweet
|
||||
|
@ -84,7 +94,17 @@ namespace BirdsiteLive.Twitter.Extractors
|
|||
|
||||
// Expand URLs
|
||||
foreach (var url in tweet.Urls.OrderByDescending(x => x.URL.Length))
|
||||
{
|
||||
var linkUri = new UriBuilder(url.ExpandedURL);
|
||||
|
||||
if (linkUri.Host == "twitter.com")
|
||||
{
|
||||
linkUri.Host = _instanceSettings.TwitterDomain;
|
||||
url.ExpandedURL = linkUri.Uri.ToString();
|
||||
}
|
||||
|
||||
message = message.Replace(url.URL, url.ExpandedURL);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ namespace BirdsiteLive.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
return Redirect($"https://twitter.com/{id}/status/{statusId}");
|
||||
return Redirect($"https://{_instanceSettings.TwitterDomain}/{id}/status/{statusId}");
|
||||
}
|
||||
|
||||
[Route("/users/{id}/inbox")]
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
"ResolveMentionsInProfiles": true,
|
||||
"PublishReplies": false,
|
||||
"MaxUsersCapacity": 1500,
|
||||
"UnlistedTwitterAccounts": null
|
||||
"UnlistedTwitterAccounts": null,
|
||||
"TwitterDomain": "twitter.com"
|
||||
},
|
||||
"Db": {
|
||||
"Type": "postgres",
|
||||
|
@ -39,5 +40,5 @@
|
|||
"FollowersBlackListing": null,
|
||||
"TwitterAccountsWhiteListing": null,
|
||||
"TwitterAccountsBlackListing": null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue