Browse Source

Add Instance:MaxStatusFetchAge

master
Pasture Pastureson 1 month ago
parent
commit
bffbb616ef
4 changed files with 17 additions and 1 deletions
  1. +1
    -0
      VARIABLES.md
  2. +2
    -0
      src/BirdsiteLive.Common/Settings/InstanceSettings.cs
  3. +12
    -0
      src/BirdsiteLive/Controllers/UsersController.cs
  4. +2
    -1
      src/BirdsiteLive/appsettings.json

+ 1
- 0
VARIABLES.md 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


+ 2
- 0
src/BirdsiteLive.Common/Settings/InstanceSettings.cs View File

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

+ 12
- 0
src/BirdsiteLive/Controllers/UsersController.cs 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();


+ 2
- 1
src/BirdsiteLive/appsettings.json View File

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


Loading…
Cancel
Save