. // }}} namespace Plugin\FileQuota; use App\Core\Cache; use App\Core\DB\DB; use App\Core\Event; use App\Core\Modules\Plugin; use App\Util\Common; use App\Util\Exception\ClientException; /** * Check attachment file size quotas * * @package GNUsocial * @ccategory Attachment * * @authir Hugo Sales * * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ class FileQuota extends Plugin { /** * Check file size to ensure it repects configured file size * quotas. Handles per file, per user and per user-month quotas. * Throws on quota violations */ public function onEnforceQuota(int $user_id, int $filesize): bool { return Event::stop; /* $file_quota = Common::config('attachments', 'file_quota'); if ($filesize > $file_quota) { // TRANS: Message given if an upload is larger than the configured maximum. throw new ClientException(_m('No file may be larger than {quota} bytes and the file you sent was {size} bytes. ' . 'Try to upload a smaller version.', ['quota' => $file_quota, 'size' => $filesize])); } $query = << DB::dql($query, ['actor_id' => $user_id])[0]['total']); Cache::set($cache_key_user_total, $user_total + $filesize); if ($user_total + $filesize > $user_quota) { // TRANS: Message given if an upload would exceed user quota. throw new ClientException(_m('A file this large would exceed your user quota of {quota} bytes.', ['quota' => $user_quota])); } } $query .= ' AND MONTH(at.modified) = MONTH(CURRENT_DATE())' . ' AND YEAR(at.modified) = YEAR(CURRENT_DATE())'; $monthly_quota = Common::config('attachments', 'monthly_quota'); if ($monthly_quota != false) { $cache_key_user_monthly = 'user-' . $user_id . 'monthly-file-quota'; $monthly_total = Cache::get($cache_key_user_monthly, fn () => DB::dql($query, ['actor_id' => $user_id])[0]['total']); Cache::set($cache_key_user_monthly, $monthly_total + $filesize); if ($monthly_total + $filesize > $monthly_quota) { // TRANS: Message given if an upload would exceed user quota. throw new ClientException(_m('A file this large would exceed your monthly quota of {quota} bytes.', ['quota' => $monthly_quota])); } }*/ } }