| 161 | } |
| 162 | |
| 163 | func (d *IPFS) Put(ctx context.Context, dstDir model.Obj, s model.FileStreamer, up driver.UpdateProgress) (model.Obj, error) { |
| 164 | if d.Mode != "mfs" { |
| 165 | return nil, fmt.Errorf("only write in mfs mode") |
| 166 | } |
| 167 | outHash, err := d.sh.Add(driver.NewLimitedUploadStream(ctx, &driver.ReaderUpdatingProgress{ |
| 168 | Reader: s, |
| 169 | UpdateProgress: up, |
| 170 | })) |
| 171 | if err != nil { |
| 172 | return nil, err |
| 173 | } |
| 174 | dstPath := path.Join(dstDir.GetPath(), s.GetName()) |
| 175 | if s.GetExist() != nil { |
| 176 | d.sh.FilesRm(ctx, dstPath, true) |
| 177 | } |
| 178 | err = d.sh.FilesCp(ctx, path.Join("/ipfs/", outHash), dstPath, shell.FilesCp.Parents(true)) |
| 179 | gateurl := d.gateURL.JoinPath("/ipfs/", outHash) |
| 180 | gateurl.RawQuery = "filename=" + url.QueryEscape(s.GetName()) |
| 181 | return &model.Object{ID: outHash, Name: s.GetName(), Path: dstPath, Size: int64(s.GetSize()), IsFolder: s.IsDir()}, err |
| 182 | } |
| 183 | |
| 184 | //func (d *Template) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) { |
| 185 | // return nil, errs.NotSupport |