/* Copyright © 2023 Seednode */ package formats import ( "bytes" "embed" "fmt" "net/http" "strconv" "strings" "github.com/julienschmidt/httprouter" ) //go:embed ruffle/* var ruffle embed.FS func RegisterFlashFormats() *SupportedFormat { return &SupportedFormat{ Name: `flash`, Css: ``, Title: func(queryParams, fileUri, filePath, fileName, mime string) string { return fmt.Sprintf(`%s`, fileName) }, Body: func(queryParams, fileUri, filePath, fileName, mime string) string { var html strings.Builder html.WriteString(fmt.Sprintf(``, fileUri)) html.WriteString(fmt.Sprintf(`
`, queryParams)) return html.String() }, Extensions: []string{ `.swf`, }, MimeTypes: []string{ `application/x-shockwave-flash`, }, Validate: func(filePath string) bool { return true }, } } func ServeRuffle() httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { fname := strings.TrimPrefix(r.URL.Path, "/") data, err := ruffle.ReadFile(fname) if err != nil { return } w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data)))) w.Write(data) } }