|
| 1 | +package template |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/Xhofe/alist/conf" |
| 5 | + "github.com/Xhofe/alist/drivers/base" |
| 6 | + "github.com/Xhofe/alist/model" |
| 7 | + "github.com/Xhofe/alist/utils" |
| 8 | + "path/filepath" |
| 9 | +) |
| 10 | + |
| 11 | +type Template struct { |
| 12 | +} |
| 13 | + |
| 14 | +func (driver Template) Config() base.DriverConfig { |
| 15 | + return base.DriverConfig{ |
| 16 | + Name: "Template", |
| 17 | + OnlyProxy: false, |
| 18 | + OnlyLocal: false, |
| 19 | + ApiProxy: false, |
| 20 | + NoNeedSetLink: false, |
| 21 | + NoCors: false, |
| 22 | + LocalSort: false, |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func (driver Template) Items() []base.Item { |
| 27 | + // TODO fill need info |
| 28 | + return []base.Item{ |
| 29 | + { |
| 30 | + Name: "refresh_token", |
| 31 | + Label: "refresh token", |
| 32 | + Type: base.TypeString, |
| 33 | + Required: true, |
| 34 | + }, |
| 35 | + { |
| 36 | + Name: "root_folder", |
| 37 | + Label: "root folder path", |
| 38 | + Type: base.TypeString, |
| 39 | + Default: "/", |
| 40 | + Required: true, |
| 41 | + }, |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +func (driver Template) Save(account *model.Account, old *model.Account) error { |
| 46 | + // TODO test available or init |
| 47 | + return nil |
| 48 | +} |
| 49 | + |
| 50 | +func (driver Template) File(path string, account *model.Account) (*model.File, error) { |
| 51 | + path = utils.ParsePath(path) |
| 52 | + if path == "/" { |
| 53 | + return &model.File{ |
| 54 | + Id: account.RootFolder, |
| 55 | + Name: account.Name, |
| 56 | + Size: 0, |
| 57 | + Type: conf.FOLDER, |
| 58 | + Driver: driver.Config().Name, |
| 59 | + UpdatedAt: account.UpdatedAt, |
| 60 | + }, nil |
| 61 | + } |
| 62 | + dir, name := filepath.Split(path) |
| 63 | + files, err := driver.Files(dir, account) |
| 64 | + if err != nil { |
| 65 | + return nil, err |
| 66 | + } |
| 67 | + for _, file := range files { |
| 68 | + if file.Name == name { |
| 69 | + return &file, nil |
| 70 | + } |
| 71 | + } |
| 72 | + return nil, base.ErrPathNotFound |
| 73 | +} |
| 74 | + |
| 75 | +func (driver Template) Files(path string, account *model.Account) ([]model.File, error) { |
| 76 | + path = utils.ParsePath(path) |
| 77 | + cache, err := base.GetCache(path, account) |
| 78 | + if err == nil { |
| 79 | + files, _ := cache.([]model.File) |
| 80 | + return files, nil |
| 81 | + } |
| 82 | + var files []model.File |
| 83 | + // TODO get files |
| 84 | + if err != nil { |
| 85 | + return nil, err |
| 86 | + } |
| 87 | + if len(files) > 0 { |
| 88 | + _ = base.SetCache(path, files, account) |
| 89 | + } |
| 90 | + return files, nil |
| 91 | +} |
| 92 | + |
| 93 | +func (driver Template) Link(args base.Args, account *model.Account) (*base.Link, error) { |
| 94 | + // TODO get file link |
| 95 | + return nil, base.ErrNotImplement |
| 96 | +} |
| 97 | + |
| 98 | +func (driver Template) Path(path string, account *model.Account) (*model.File, []model.File, error) { |
| 99 | + path = utils.ParsePath(path) |
| 100 | + file, err := driver.File(path, account) |
| 101 | + if err != nil { |
| 102 | + return nil, nil, err |
| 103 | + } |
| 104 | + if !file.IsDir() { |
| 105 | + return file, nil, nil |
| 106 | + } |
| 107 | + files, err := driver.Files(path, account) |
| 108 | + if err != nil { |
| 109 | + return nil, nil, err |
| 110 | + } |
| 111 | + return nil, files, nil |
| 112 | +} |
| 113 | + |
| 114 | +func (driver Template) Preview(path string, account *model.Account) (interface{}, error) { |
| 115 | + //TODO preview interface if driver support |
| 116 | + return nil, base.ErrNotImplement |
| 117 | +} |
| 118 | + |
| 119 | +func (driver Template) MakeDir(path string, account *model.Account) error { |
| 120 | + //TODO make dir |
| 121 | + return base.ErrNotImplement |
| 122 | +} |
| 123 | + |
| 124 | +func (driver Template) Move(src string, dst string, account *model.Account) error { |
| 125 | + //TODO move file/dir |
| 126 | + return base.ErrNotImplement |
| 127 | +} |
| 128 | + |
| 129 | +func (driver Template) Rename(src string, dst string, account *model.Account) error { |
| 130 | + //TODO rename file/dir |
| 131 | + return base.ErrNotImplement |
| 132 | +} |
| 133 | + |
| 134 | +func (driver Template) Copy(src string, dst string, account *model.Account) error { |
| 135 | + //TODO copy file/dir |
| 136 | + return base.ErrNotImplement |
| 137 | +} |
| 138 | + |
| 139 | +func (driver Template) Delete(path string, account *model.Account) error { |
| 140 | + //TODO delete file/dir |
| 141 | + return base.ErrNotImplement |
| 142 | +} |
| 143 | + |
| 144 | +func (driver Template) Upload(file *model.FileStream, account *model.Account) error { |
| 145 | + //TODO upload file |
| 146 | + return base.ErrNotImplement |
| 147 | +} |
| 148 | + |
| 149 | +var _ base.Driver = (*Template)(nil) |
0 commit comments