Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930
  1. package files
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. "io/fs"
  7. "os"
  8. "path/filepath"
  9. )
  10. type localFile struct {
  11. root fs.FS
  12. name string
  13. }
  14. func (l localFile) Open(ctx context.Context) (io.ReadCloser, error) {
  15. return l.root.Open(l.name)
  16. }
  17. func NewLocal(path string) (File, error) {
  18. if stat, err := os.Stat(path); os.IsNotExist(err) || stat.IsDir() || stat.Mode().Perm()&0o400 == 0 {
  19. return nil, fmt.Errorf("%s is not a readable file", path)
  20. }
  21. return localFile{
  22. root: os.DirFS(filepath.Dir(path)),
  23. name: filepath.Base(path),
  24. }, nil
  25. }