fix windows ci (#934)

* fix windows ci

* perm

* use custom writer

* remove patches

* fuck codeql
This commit is contained in:
UUBulb
2025-01-01 00:58:57 +08:00
committed by GitHub
parent 7662471c2f
commit 3c72d6ce64
5 changed files with 29 additions and 131 deletions

View File

@@ -285,10 +285,31 @@ func getUid(c *gin.Context) uint64 {
return user.ID
}
type ginCustomWriter struct {
gin.ResponseWriter
customCode int
}
func newCustomWriter(c *gin.Context, code int) *ginCustomWriter {
return &ginCustomWriter{
ResponseWriter: c.Writer,
customCode: code,
}
}
func (w *ginCustomWriter) WriteHeader(code int) {
w.ResponseWriter.WriteHeader(w.customCode)
}
func fileWithCustomStatusCode(c *gin.Context, filepath string, customCode int) {
http.ServeFile(newCustomWriter(c, customCode), c.Request, path.Clean(filepath))
}
func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
checkLocalFileOrFs := func(c *gin.Context, fs fs.FS, path string, customStatusCode int) bool {
if _, err := os.Stat(path); err == nil {
c.FileWithCustomStatusCode(path, customStatusCode)
fileWithCustomStatusCode(c, path, customStatusCode)
return true
}
f, err := fs.Open(path)
@@ -303,7 +324,7 @@ func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
if fileStat.IsDir() {
return false
}
http.ServeContentCustomStatusCode(c.Writer, c.Request, path, fileStat.ModTime(), f.(io.ReadSeeker), customStatusCode)
http.ServeContent(newCustomWriter(c, customStatusCode), c.Request, path, fileStat.ModTime(), f.(io.ReadSeeker))
return true
}
return func(c *gin.Context) {
@@ -323,7 +344,7 @@ func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
}
return
}
localFilePath := path.Join(singleton.Conf.UserTemplate, c.Request.URL.Path)
localFilePath := path.Join(singleton.Conf.UserTemplate, path.Clean(c.Request.URL.Path))
if checkLocalFileOrFs(c, frontendDist, localFilePath, http.StatusOK) {
return
}