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.go 1.3 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package object
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io"
  6. "mime/multipart"
  7. "strings"
  8. "github.com/casbin/casibase/storage"
  9. )
  10. func UpdateFile(storeId string, key string, file *File) bool {
  11. return true
  12. }
  13. func AddFile(storeId string, key string, isLeaf bool, filename string, file multipart.File) (bool, []byte) {
  14. store := GetStore(storeId)
  15. if store == nil {
  16. return false, nil
  17. }
  18. var objectKey string
  19. var fileBuffer *bytes.Buffer
  20. if isLeaf {
  21. objectKey = fmt.Sprintf("%s/%s", key, filename)
  22. objectKey = strings.TrimLeft(objectKey, "/")
  23. fileBuffer = bytes.NewBuffer(nil)
  24. if _, err := io.Copy(fileBuffer, file); err != nil {
  25. panic(err)
  26. }
  27. } else {
  28. objectKey = fmt.Sprintf("%s/%s/_hidden.ini", key, filename)
  29. objectKey = strings.TrimLeft(objectKey, "/")
  30. fileBuffer = bytes.NewBuffer(nil)
  31. }
  32. bs := fileBuffer.Bytes()
  33. storage.PutObject(store.Bucket, objectKey, fileBuffer)
  34. return true, bs
  35. }
  36. func DeleteFile(storeId string, key string, isLeaf bool) bool {
  37. store := GetStore(storeId)
  38. if store == nil {
  39. return false
  40. }
  41. if isLeaf {
  42. storage.DeleteObject(store.Bucket, key)
  43. } else {
  44. objects := storage.ListObjects(store.Bucket, key)
  45. for _, object := range objects {
  46. storage.DeleteObject(store.Bucket, object.Key)
  47. }
  48. }
  49. return true
  50. }

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

Contributors (1)