Add Instance:MaxStatusFetchAge

This commit is contained in:
Miss Pasture 2021-12-17 00:17:30 -05:00
parent b6670c47b5
commit bffbb616ef
4 changed files with 17 additions and 1 deletions

View File

@ -56,6 +56,7 @@ If both whitelisting and blacklisting are set, only the whitelisting will be act
* `Instance:UnlistedTwitterAccounts` (default: null) to enable unlisted publication for selected twitter accounts, separated by `;` (please limit this to brands and other public profiles).
* `Instance:SensitiveTwitterAccounts` (default: null) mark all media from given accounts as sensitive by default, separated by `;`.
* `Instance:FailingTwitterUserCleanUpThreshold` (default: 700) set the max allowed errors (due to a banned/deleted/private account) from a Twitter Account retrieval before auto-removal. (by default an account is called every 15 mins)
* `Instance:MaxStatusFetchAge` (default: 0 - no limit) statuses with a Snowflake older than this age in days will not be fetched by the service and will instead return 410 Gone
# Docker Compose full example

View File

@ -26,5 +26,7 @@
public string SensitiveTwitterAccounts { get; set; }
public int FailingTwitterUserCleanUpThreshold { get; set; }
public int MaxStatusFetchAge { get; set; }
}
}

View File

@ -118,6 +118,18 @@ namespace BirdsiteLive.Controllers
if (!long.TryParse(statusId, out var parsedStatusId))
return NotFound();
if (_instanceSettings.MaxStatusFetchAge > 0)
{
// I hate bitwise operators, corn syrup, and the antichrist
// shift 22 bits to the right to get milliseconds, add the twitter epoch, then divide by 1000 to get seconds
long secondsAgo = DateTimeOffset.UtcNow.ToUnixTimeSeconds() - (((parsedStatusId >> 22) + 1288834974657) / 1000);
if ( secondsAgo > _instanceSettings.MaxStatusFetchAge*60*60*24 )
{
return new StatusCodeResult(StatusCodes.Status410Gone);
}
}
var tweet = _twitterTweetService.GetTweet(parsedStatusId);
if (tweet == null)
return NotFound();

View File

@ -29,7 +29,8 @@
"MaxFollowsPerUser": 0,
"DiscloseInstanceRestrictions": false,
"SensitiveTwitterAccounts": null,
"FailingTwitterUserCleanUpThreshold": 700
"FailingTwitterUserCleanUpThreshold": 700,
"MaxStatusFetchAge": 0
},
"Db": {
"Type": "postgres",