You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: dfs.uploadGifDocumentMedia_handler.go
    path of file: ./repos/teamgram-server/app/service/dfs/internal/core
    
    the code of the file until where you have to start completion: /*
 * Created from 'scheme.tl' by 'mtprotoc'
 *
 * Copyright (c) 2021-present,  Teamgram Studio (https://teamgram.io).
 *  All rights reserved.
 *
 * Author: teamgramio (teamgram.io@gmail.com)
 */

package core

import (
	"bytes"
	"crypto/md5"
	"fmt"
	"image"
	"math/rand"
	"time"

	"github.com/teamgram/marmota/pkg/bytes2"
	"github.com/teamgram/proto/mtproto"
	"github.com/teamgram/teamgram-server/app/service/dfs/dfs"
	"github.com/teamgram/teamgram-server/app/service/dfs/internal/imaging"
	"github.com/teamgram/teamgram-server/app/service/dfs/internal/model"
)

const (
	GifNeedConvertSize = 10240
)

// DfsUploadGifDocumentMedia
// dfs.uploadGifDocumentMedia creator:long media:InputMedia = Document;
func (c *DfsCore) DfsUploadGifDocumentMedia(in *dfs.TLDfsUploadGifDocumentMedia) (*mtproto.Document, error) {
	var (
		media    = in.GetMedia()
		file     = in.GetMedia().GetFile()
		thumb    = media.GetThumb()
		err      error
		document *mtproto.Document
	)

	if media == nil {
		err = mtproto.ErrMediaEmpty
		c.Logger.Errorf("dfs.uploadGifDocumentMedia - error: %v", err)
		return nil, err
	}

	if file == nil {
		err = mtproto.ErrMediaInvalid
		c.Logger.Errorf("dfs.uploadGifDocumentMedia - error: %v", err)
		return nil, err
	}

	if err := model.CheckFileParts(file.Parts); err != nil {
		c.Logger.Errorf("dfs.uploadGifDocumentMedia - %v", err)
		return nil, err
	}

	if thumb != nil {
    
func (c *DfsCore) uploadHasThumbGifMp4Media(creatorId int64, media *mtproto.InputMedia) (*mtproto.Document, error) {
	var (
		documentId = c.svcCtx.Dao.IDGenClient2.NextId(c.ctx)
		ext        = model.GetFileExtName(media.GetFile().GetName())
		extType    = model.GetStorageFileTypeConstructor(ext)
		accessHash = int64(extType)<<32 | int64(rand.Uint32())
	)

	// 1. thumb
	thumbFile := media.GetThumb()

	if err := model.CheckFileParts(thumbFile.Parts); err != nil {
		c.Logger.Errorf("dfs.uploadPhotoFile - %v", err)
		return nil, err
	}

	r, err := c.svcCtx.Dao.OpenFile(c.ctx, creatorId, thumbFile.Id, thumbFile.Parts)
	if err != nil {
		c.Logger.Errorf("dfs.uploadGifDocumentMedia - %v", err)
		return nil, mtproto.ErrMediaInvalid
	}

	thumbFileData, err := r.ReadAll(c.ctx)
	if err != nil {
		c.Logger.Errorf("dfs.uploadGifDocumentMedia - %v", err)
		return nil, mtproto.ErrMediaInvalid
	}

	if len(thumbFile.Md5Checksum) > 0 {
		digest := fmt.Sprintf("%x", md5.Sum(thumbFileData))
		if digest != thumbFile.Md5Checksum {
			c.Logger.Errorf("dfs.uploadGifDocumentMedia - (%s, %s) error: %v", digest, thumbFile.Md5Checksum, err)
			return nil, mtproto.ErrCheckSumInvalid
		}
	}

	// TODO(@benqi): if x or y < 320
	thumb, err := imaging.Decode(bytes.NewReader(thumbFileData))
	if err != nil {
		c.Logger.Errorf("dfs.uploadGifDocumentMedia - %v", err)
		return nil, mtproto.ErrMediaInvalid
	}

	szList, err := c.uploadGifThumb(documentId, thumb)
	if err != nil {
		c.Logger.Errorf("dfs.uploadGifDocumentMedia - error: %v", err)
		return nil, err
	}

	dstW := (szList[1].W * 2) / 2
	if dstW%2 != 0 {
		dstW += 1
	}
	dstH := (szList[1].H * 2) / 2
	if dstH%2 != 0 {
		dstH += 1
	}
	gifMp4Data, duration, err := c.svcCtx.FFmpegUtil.ConvertToMp4ByPipe(
		fmt.Sprintf("http://127.0.0.1:11701/dfs/file/%d_%d.gif",
			creatorId,
			media.GetFile().GetId()),
		int(dstW), int(dstH))
	if err != nil {
		c.Logger.Errorf("dfs.uploadGifDocumentMedia - %v", err)
		return nil, err
	}
	// build file
	path := fmt.Sprintf("%d.dat", documentId)
	gifFileSize, err := c.svcCtx.Dao.PutDocumentFile(c.ctx, path, bytes.NewReader(gifMp4Data))
	if err != nil {
		c.Logger.Errorf("dfs.uploadGifDocumentMedia - %v", err)
		return nil, err
	}

	// build document
	document := mtproto.MakeTLDocument(&mtproto.Document{
		Id:            documentId,
		AccessHash:    accessHash,
		FileReference: []byte{}, // TODO(@benqi): gen file_reference
		Date:          int32(time.Now().Unix()),
		MimeType:      "video/mp4",
		Size2_INT32:   int32(gifFileSize.Size),
		Size2_INT64:   gifFileSize.Size,
		Thumbs:        szList,
		VideoThumbs:   nil,
		DcId:          1,
		Attributes: []*mtproto.DocumentAttribute{
			//mtproto.MakeTLDocumentAttributeImageSize(&mtproto.DocumentAttribute{
			//	W: int32(thumb.Bounds().Dx()),
			//	H: int32(thumb.Bounds().Dy()),
			//}).To_DocumentAttribute(),
			mtproto.MakeTLDocumentAttributeVideo(&mtproto.DocumentAttribute{
				RoundMessage:      false,
				SupportsStreaming: true,
				Duration:          float64(duration), // gif.mp4's duration
				Duration_INT32:    duration,
				Duration_FLOAT64:  float64(duration),
				W:                 dstW,
				H:                 dstH,
			}).To_DocumentAttribute(),
			mtproto.MakeTLDocumentAttributeFilename(&mtproto.DocumentAttribute{
				FileName: media.GetFile().GetName() + ".mp4",
			}).To_DocumentAttribute(),
			mtproto.MakeTLDocumentAttributeAnimated(&mtproto.DocumentAttribute{}).To_DocumentAttribute(),
		},
	}).To_Document()

	return document, nil

}