Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 10, 2023
1 parent 670a6dc commit a6409e9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
18 changes: 16 additions & 2 deletions cloud/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,25 @@ func (s3 *S3) UploadObject(filePath string, overwrite bool) (length int64, err e
return
}
defer file.Close()
key := path.Join("repo", filePath)
_, err = svc.PutObjectWithContext(ctx, &as3.PutObjectInput{
Bucket: aws.String(s3.Conf.S3.Bucket),
Key: aws.String(path.Join("repo", filePath)),
Key: aws.String(key),
Body: file,
})

logging.LogInfof("uploaded object [%s]", key)
return
}

func (s3 *S3) DownloadObject(filePath string) (data []byte, err error) {
svc := s3.getService()
ctx, cancelFn := context.WithTimeout(context.Background(), time.Duration(s3.S3.Timeout)*time.Second)
defer cancelFn()
key := path.Join("repo", filePath)
input := &as3.GetObjectInput{
Bucket: aws.String(s3.Conf.S3.Bucket),
Key: aws.String(path.Join("repo", filePath)),
Key: aws.String(key),
}
resp, err := svc.GetObjectWithContext(ctx, input)
if nil != err {
Expand All @@ -105,6 +109,11 @@ func (s3 *S3) DownloadObject(filePath string) (data []byte, err error) {
}
defer resp.Body.Close()
data, err = io.ReadAll(resp.Body)
if nil != err {
return
}

logging.LogInfof("downloaded object [%s]", key)
return
}

Expand All @@ -117,6 +126,11 @@ func (s3 *S3) RemoveObject(key string) (err error) {
Bucket: aws.String(s3.Conf.S3.Bucket),
Key: aws.String(key),
})
if nil != err {
return
}

logging.LogInfof("removed object [%s]", key)
return
}

Expand Down
14 changes: 13 additions & 1 deletion cloud/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,31 @@ func (webdav *WebDAV) UploadObject(filePath string, overwrite bool) (length int6
if nil != err {
logging.LogErrorf("upload object [%s] failed: %s", key, err)
}
logging.LogInfof("uploaded object [%s]", key)
return
}

func (webdav *WebDAV) DownloadObject(filePath string) (data []byte, err error) {
data, err = webdav.Client.Read(path.Join(webdav.Dir, "siyuan", "repo", filePath))
key := path.Join(webdav.Dir, "siyuan", "repo", filePath)
data, err = webdav.Client.Read(key)
err = webdav.parseErr(err)
if nil != err {
return
}

logging.LogInfof("downloaded object [%s]", key)
return
}

func (webdav *WebDAV) RemoveObject(filePath string) (err error) {
key := path.Join(webdav.Dir, "siyuan", "repo", filePath)
err = webdav.Client.Remove(key)
err = webdav.parseErr(err)
if nil != err {
return
}

logging.LogInfof("removed object [%s]", key)
return
}

Expand Down
2 changes: 2 additions & 0 deletions sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,8 @@ func (repo *Repo) downloadCloudLatest(context map[string]interface{}) (downloadB
return
}
downloadBytes += int64(len(data))

logging.LogInfof("got cloud latest [%s, %s]", index.ID, time.UnixMilli(index.Created).Format("2006-01-02 15:04:05"))
return
}

Expand Down

0 comments on commit a6409e9

Please sign in to comment.