(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress)
| 129 | } |
| 130 | |
| 131 | func (d *Terabox) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error { |
| 132 | resp, err := base.RestyClient.R(). |
| 133 | SetContext(ctx). |
| 134 | Get("https://" + d.url_domain_prefix + "-data.terabox.com/rest/2.0/pcs/file?method=locateupload") |
| 135 | if err != nil { |
| 136 | return err |
| 137 | } |
| 138 | var locateupload_resp LocateUploadResp |
| 139 | err = utils.Json.Unmarshal(resp.Body(), &locateupload_resp) |
| 140 | if err != nil { |
| 141 | log.Debugln(resp) |
| 142 | return err |
| 143 | } |
| 144 | log.Debugln(locateupload_resp) |
| 145 | |
| 146 | // precreate file |
| 147 | rawPath := stdpath.Join(dstDir.GetPath(), stream.GetName()) |
| 148 | path := encodeURIComponent(rawPath) |
| 149 | |
| 150 | var precreateBlockListStr string |
| 151 | if stream.GetSize() > initialChunkSize { |
| 152 | precreateBlockListStr = `["5910a591dd8fc18c32a8f3df4fdc1761","a5fc157d78e6ad1c7e114b056c92821e"]` |
| 153 | } else { |
| 154 | precreateBlockListStr = `["5910a591dd8fc18c32a8f3df4fdc1761"]` |
| 155 | } |
| 156 | |
| 157 | data := map[string]string{ |
| 158 | "path": rawPath, |
| 159 | "autoinit": "1", |
| 160 | "target_path": dstDir.GetPath(), |
| 161 | "block_list": precreateBlockListStr, |
| 162 | "local_mtime": strconv.FormatInt(stream.ModTime().Unix(), 10), |
| 163 | "file_limit_switch_v34": "true", |
| 164 | } |
| 165 | var precreateResp PrecreateResp |
| 166 | log.Debugln(data) |
| 167 | res, err := d.post_form("/api/precreate", nil, data, &precreateResp) |
| 168 | if err != nil { |
| 169 | return err |
| 170 | } |
| 171 | log.Debugf("%+v", precreateResp) |
| 172 | if precreateResp.Errno != 0 { |
| 173 | log.Debugln(string(res)) |
| 174 | return fmt.Errorf("[terabox] failed to precreate file, errno: %d", precreateResp.Errno) |
| 175 | } |
| 176 | if precreateResp.ReturnType == 2 { |
| 177 | return nil |
| 178 | } |
| 179 | |
| 180 | // upload chunks |
| 181 | tempFile, err := stream.CacheFullInTempFile() |
| 182 | if err != nil { |
| 183 | return err |
| 184 | } |
| 185 | |
| 186 | params := map[string]string{ |
| 187 | "method": "upload", |
| 188 | "path": path, |
nothing calls this directly
no test coverage detected