+ $throttle_week = DI::config()->get('system', 'throttle_limit_week');
+ if ($throttle_week > 0) {
+ $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
+
+ $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom];
+ $posts_week = Post::countThread($condition);
+
+ if ($posts_week > $throttle_week) {
+ Logger::info('Weekly posting limit reached', ['uid' => $uid, 'posts' => $posts_week, 'limit' => $throttle_week]);
+ $error = DI::l10n()->t('Too Many Requests');
+ $error_description = DI::l10n()->tt("Weekly posting limit of %d post reached. The post was rejected.", "Weekly posting limit of %d posts reached. The post was rejected.", $throttle_week);
+ $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
+ System::jsonError(429, $errorobj->toArray());
+ }
+ }
+
+ $throttle_month = DI::config()->get('system', 'throttle_limit_month');
+ if ($throttle_month > 0) {
+ $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
+
+ $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom];
+ $posts_month = Post::countThread($condition);
+
+ if ($posts_month > $throttle_month) {
+ Logger::info('Monthly posting limit reached', ['uid' => $uid, 'posts' => $posts_month, 'limit' => $throttle_month]);
+ $error = DI::l10n()->t('Too Many Requests');
+ $error_description = DI::l10n()->t("Monthly posting limit of %d post reached. The post was rejected.", "Monthly posting limit of %d posts reached. The post was rejected.", $throttle_month);
+ $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
+ System::jsonError(429, $errorobj->toArray());
+ }
+ }