Based on QuantumNous/new-api v1.0.0-rc.36 (shallow history squashed). - CNY quota display mode: RMB-denominated top-up and crediting across Epay/Waffo channels - New CheckinButton in both authenticated and public headers (Turnstile supported) - New /subscribe page with public plan snapshot, Alipay/balance payment, auto group upgrade/reset - New /docs 12-section beginner guide with anchor navigation - New home PromoBanner linking to /docs; i18n synced (en/zh/zh-TW/fr/ja/ru/vi) - README: document custom features, live demo https://ai.88531.cn
44 lines
845 B
Go
44 lines
845 B
Go
package common
|
|
|
|
import (
|
|
"embed"
|
|
"io/fs"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/gin-contrib/static"
|
|
)
|
|
|
|
// Credit: https://github.com/gin-contrib/static/issues/19
|
|
|
|
type embedFileSystem struct {
|
|
http.FileSystem
|
|
}
|
|
|
|
func (e *embedFileSystem) Exists(prefix string, path string) bool {
|
|
_, err := e.Open(path)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (e *embedFileSystem) Open(name string) (http.File, error) {
|
|
if name == "/" {
|
|
// This will make sure the index page goes to NoRouter handler,
|
|
// which will use the replaced index bytes with analytic codes.
|
|
return nil, os.ErrNotExist
|
|
}
|
|
return e.FileSystem.Open(name)
|
|
}
|
|
|
|
func EmbedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem {
|
|
efs, err := fs.Sub(fsEmbed, targetPath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return &embedFileSystem{
|
|
FileSystem: http.FS(efs),
|
|
}
|
|
}
|