Files
waf-platform/EdgeUser/internal/web/actions/default/qrcode/index.go
2026-02-04 20:27:13 +08:00

39 lines
875 B
Go

// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package qrcode
import (
"github.com/TeaOSLab/EdgeUser/internal/ttlcache"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/types"
"net/http"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct {
Key string
}) {
var item = ttlcache.DefaultCache.Read(params.Key)
if item == nil || item.Value == nil {
this.ResponseWriter.WriteHeader(http.StatusNotFound)
return
}
data, ok := item.Value.([]byte)
if !ok {
this.ResponseWriter.WriteHeader(http.StatusNotFound)
return
}
this.AddHeader("Content-Type", "image/png")
this.AddHeader("Content-Length", types.String(len(data)))
_, _ = this.Write(data)
}