gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

media.go (2422B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package admin
     19 
     20 import (
     21 	"context"
     22 	"fmt"
     23 
     24 	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
     25 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     26 	"github.com/superseriousbusiness/gotosocial/internal/log"
     27 )
     28 
     29 // MediaRefetch forces a refetch of remote emojis.
     30 func (p *Processor) MediaRefetch(ctx context.Context, requestingAccount *gtsmodel.Account, domain string) gtserror.WithCode {
     31 	transport, err := p.transportController.NewTransportForUsername(ctx, requestingAccount.Username)
     32 	if err != nil {
     33 		err = fmt.Errorf("error getting transport for user %s during media refetch request: %w", requestingAccount.Username, err)
     34 		return gtserror.NewErrorInternalError(err)
     35 	}
     36 
     37 	go func() {
     38 		log.Info(ctx, "starting emoji refetch")
     39 		refetched, err := p.mediaManager.RefetchEmojis(context.Background(), domain, transport.DereferenceMedia)
     40 		if err != nil {
     41 			log.Errorf(ctx, "error refetching emojis: %s", err)
     42 		} else {
     43 			log.Infof(ctx, "refetched %d emojis from remote", refetched)
     44 		}
     45 	}()
     46 
     47 	return nil
     48 }
     49 
     50 // MediaPrune triggers a non-blocking prune of remote media, local unused media, etc.
     51 func (p *Processor) MediaPrune(ctx context.Context, mediaRemoteCacheDays int) gtserror.WithCode {
     52 	if mediaRemoteCacheDays < 0 {
     53 		err := fmt.Errorf("MediaPrune: invalid value for mediaRemoteCacheDays prune: value was %d, cannot be less than 0", mediaRemoteCacheDays)
     54 		return gtserror.NewErrorBadRequest(err, err.Error())
     55 	}
     56 
     57 	if err := p.mediaManager.PruneAll(ctx, mediaRemoteCacheDays, false); err != nil {
     58 		err = fmt.Errorf("MediaPrune: %w", err)
     59 		return gtserror.NewErrorInternalError(err)
     60 	}
     61 
     62 	return nil
     63 }