You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

file_cache.go 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package controllers
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/casbin/casbase/util"
  6. )
  7. var cacheDir = "C:/casbase_cache"
  8. var cacheMap = map[string]string{}
  9. func getCachePrefix(filename string) string {
  10. if !strings.HasPrefix(filename, "ECG_") && !strings.HasPrefix(filename, "EEG_") && !strings.HasPrefix(filename, "Impedance_") {
  11. return ""
  12. }
  13. tokens := strings.SplitN(filename, "_", 2)
  14. res := tokens[0]
  15. return res
  16. }
  17. func addFileToCache(key string, filename string, bs []byte) {
  18. prefix := getCachePrefix(filename)
  19. if prefix == "" {
  20. return
  21. }
  22. path := fmt.Sprintf("%s/%s/%s", cacheDir, key, filename)
  23. util.EnsureFileFolderExists(path)
  24. util.WriteBytesToPath(bs, path)
  25. }
  26. func (c *ApiController) ActivateFile() {
  27. _, ok := c.RequireSignedIn()
  28. if !ok {
  29. return
  30. }
  31. key := c.Input().Get("key")
  32. filename := c.Input().Get("filename")
  33. prefix := getCachePrefix(filename)
  34. if prefix == "" {
  35. c.Data["json"] = false
  36. c.ServeJSON()
  37. return
  38. }
  39. path := fmt.Sprintf("%s/%s", cacheDir, key)
  40. cacheMap[prefix] = path
  41. fmt.Printf("%v\n", cacheMap)
  42. c.Data["json"] = true
  43. c.ServeJSON()
  44. }
  45. func (c *ApiController) GetActiveFile() {
  46. prefix := c.Input().Get("prefix")
  47. res := ""
  48. if v, ok := cacheMap[prefix]; ok {
  49. res = v
  50. }
  51. c.Data["json"] = res
  52. c.ServeJSON()
  53. }

基于Casbin的开源AI领域知识库平台

Contributors (1)