func GetAttachmentAction(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/plain")
	vars := mux.Vars(r)
	supportsAttachments := viper.GetString("app.attachments.driver") != ""
	loadedMessage, err := loadMessageFromRedis(vars["token"])
	if !supportsAttachments || err != nil || loadedMessage == nil {
		NotFound(w, r)
		return
	}
	visitorHash := getHashedIP(r, loadedMessage.Token)
	if loadedMessage.AccessibleIP != visitorHash {
		NotFound(w, r)
		return
	}
	var data string
	for _, att := range loadedMessage.Attachments {
		if att.Token != vars["attachmentToken"] {
			continue
		}
		attachmentHandler := attachment.NewAttachmentHandler(att.HostType)
		fmt.Println(attachmentHandler, att.HostType)
		data, err = attachmentHandler.Get(att.FileID)
		if err != nil {
			logger.LogError(err)
			NotFound(w, r)
		}
		break
	}
	fmt.Fprintf(w, data)
}
GetAttachmentAction handles attachment access
package handler
import (
	"crypto/md5"
	"encoding/json"
	"fmt"
	"github.com/Scribblerockerz/cryptletter/pkg/attachment"
	"github.com/Scribblerockerz/cryptletter/pkg/database"
	"github.com/Scribblerockerz/cryptletter/pkg/logger"
	"github.com/Scribblerockerz/cryptletter/pkg/message"
	"github.com/Scribblerockerz/cryptletter/pkg/utils"
	"net/http"
	"strconv"
	"strings"
	"time"
	"github.com/gorilla/mux"
	"github.com/spf13/viper"
)
func loadMessageFromRedis(token string) (*message.Message, error) {
	hasResults, err := database.RedisClient.Exists(token).Result()
	if err != nil {
		return nil, err
	}
	if hasResults == 0 {
		return nil, nil
	}
	result, err := database.RedisClient.Get(token).Result()
	if err != nil {
		return nil, err
	}
	loadedMessage := &message.Message{}
	err = json.Unmarshal([]byte(result), loadedMessage)
	if err != nil {
		return nil, err
	}
	return loadedMessage, nil
}
type responseAttachmentType struct {
	Token    string `json:"token"`
	Name     string `json:"name"`
	MimeType string `json:"mimeType"`
	Size     string `json:"size"`
}
type responseMessageType struct {
	Message              string                   `json:"message"`
	ActiveUntilTimestamp string                   `json:"activeUntilTimestamp"`
	Token                string                   `json:"token"`
	Attachments          []responseAttachmentType `json:"attachments"`
}
func ShowAction(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	vars := mux.Vars(r)
	loadedMessage, err := loadMessageFromRedis(vars["token"])
	if err != nil || loadedMessage == nil {
		NotFound(w, r)
		return
	}
	visitorHash := getHashedIP(r, loadedMessage.Token)
	if loadedMessage.AccessibleIP == "" {
		loadedMessage.AccessibleIP = visitorHash
		bytes, err := json.Marshal(&loadedMessage)
		if err != nil {
			panic(err)
		}
		err = database.RedisClient.Set(loadedMessage.Token, string(bytes), time.Duration(loadedMessage.Lifetime)*time.Minute).Err()
		hostType := ""
		if len(loadedMessage.Attachments) > 0 {
			hostType = loadedMessage.Attachments[0].HostType
		}
		attachmentHandler := attachment.NewAttachmentHandler(hostType)
		for _, att := range loadedMessage.Attachments {
			if attachmentHandler == nil {
				break
			}
			err2 := attachmentHandler.SetTTL(att.FileID, loadedMessage.Lifetime * 60)
			if err2 != nil {
				logger.LogError(err2)
			}
		}
		if err != nil {
			fmt.Printf("An error accoured %s", err)
		}
	}
	if loadedMessage.AccessibleIP != visitorHash {
		NotFound(w, r)
		return
	}
	duration, err := database.RedisClient.TTL(loadedMessage.Token).Result()
	if err != nil {
		panic(err)
	}
	var responseAttachments []responseAttachmentType
	for _, att := range loadedMessage.Attachments {
		responseAttachments = append(responseAttachments, responseAttachmentType{
			Token:    att.Token,
			Name:     att.Name,
			MimeType: att.MimeType,
			Size:     att.Size,
		})
	}
	res, err := json.Marshal(responseMessageType{
		Message:              loadedMessage.Content,
		ActiveUntilTimestamp: strconv.FormatInt(time.Now().Add(duration).Unix()*1000, 10),
		Token:                vars["token"],
		Attachments:          responseAttachments,
	})
	if err != nil {
		panic(err)
	}
	fmt.Fprintf(w, string(res))
}