@@ -285,10 +285,31 @@ func getUid(c *gin.Context) uint64 {
285
285
return user .ID
286
286
}
287
287
288
+ type ginCustomWriter struct {
289
+ gin.ResponseWriter
290
+
291
+ customCode int
292
+ }
293
+
294
+ func newCustomWriter (c * gin.Context , code int ) * ginCustomWriter {
295
+ return & ginCustomWriter {
296
+ ResponseWriter : c .Writer ,
297
+ customCode : code ,
298
+ }
299
+ }
300
+
301
+ func (w * ginCustomWriter ) WriteHeader (code int ) {
302
+ w .ResponseWriter .WriteHeader (w .customCode )
303
+ }
304
+
305
+ func fileWithCustomStatusCode (c * gin.Context , filepath string , customCode int ) {
306
+ http .ServeFile (newCustomWriter (c , customCode ), c .Request , filepath )
307
+ }
308
+
288
309
func fallbackToFrontend (frontendDist fs.FS ) func (* gin.Context ) {
289
310
checkLocalFileOrFs := func (c * gin.Context , fs fs.FS , path string , customStatusCode int ) bool {
290
311
if _ , err := os .Stat (path ); err == nil {
291
- c . FileWithCustomStatusCode ( path , customStatusCode )
312
+ fileWithCustomStatusCode ( c , path , customStatusCode )
292
313
return true
293
314
}
294
315
f , err := fs .Open (path )
@@ -303,7 +324,7 @@ func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
303
324
if fileStat .IsDir () {
304
325
return false
305
326
}
306
- http .ServeContentCustomStatusCode ( c . Writer , c .Request , path , fileStat .ModTime (), f .(io.ReadSeeker ), customStatusCode )
327
+ http .ServeContent ( newCustomWriter ( c , customStatusCode ), c .Request , path , fileStat .ModTime (), f .(io.ReadSeeker ))
307
328
return true
308
329
}
309
330
return func (c * gin.Context ) {
0 commit comments