Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
feature: add GetHTTPPath function for cdn mgr
Browse files Browse the repository at this point in the history
Signed-off-by: Starnop <[email protected]>
  • Loading branch information
starnop committed May 29, 2019
1 parent e8f36c8 commit dc968e3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
9 changes: 9 additions & 0 deletions supernode/daemon/mgr/cdn/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ func (cm *Manager) TriggerCDN(ctx context.Context, task *types.TaskInfo) (*types
}, nil
}

// GetHTTPPath returns the http download path of taskID.
func (cm *Manager) GetHTTPPath(ctx context.Context, taskID string) (string, error) {
info, err := cm.cacheStore.Stat(ctx, getDownloadRawFunc(taskID))
if err != nil {
return "", err
}
return info.Path, nil
}

// GetStatus get the status of the file.
func (cm *Manager) GetStatus(ctx context.Context, taskID string) (cdnStatus string, err error) {
return "", nil
Expand Down
3 changes: 3 additions & 0 deletions supernode/daemon/mgr/cdn_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type CDNMgr interface {
// In addition, it's not thread-safe.
TriggerCDN(ctx context.Context, taskInfo *types.TaskInfo) (*types.TaskInfo, error)

// GetHTTPPath returns the http download path of taskID.
GetHTTPPath(ctx context.Context, taskID string) (path string, err error)

// GetStatus get the status of the file.
GetStatus(ctx context.Context, taskID string) (cdnStatus string, err error)

Expand Down
15 changes: 15 additions & 0 deletions supernode/daemon/mgr/mock/mock_cdn_mgr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions supernode/store/local_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (ls *localStorage) PutBytes(ctx context.Context, raw *Raw, data []byte) err

// Stat determine whether the file exists.
func (ls *localStorage) Stat(ctx context.Context, raw *Raw) (*StorageInfo, error) {
path, fileInfo, err := ls.statPath(raw.Bucket, raw.Key)
_, fileInfo, err := ls.statPath(raw.Bucket, raw.Key)
if err != nil {
return nil, err
}
Expand All @@ -257,7 +257,7 @@ func (ls *localStorage) Stat(ctx context.Context, raw *Raw) (*StorageInfo, error
return nil, fmt.Errorf("get create time error")
}
return &StorageInfo{
Path: path,
Path: path.Join(raw.Bucket, raw.Key),
Size: fileInfo.Size(),
CreateTime: util.Ctime(sys),
ModTime: fileInfo.ModTime(),
Expand Down
2 changes: 1 addition & 1 deletion supernode/store/local_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (s *LocalStorageSuite) checkStat(raw *Raw, c *check.C) {
sys, _ := util.GetSys(f)

c.Assert(info, check.DeepEquals, &StorageInfo{
Path: pathTemp,
Path: path.Join(raw.Bucket, raw.Key),
Size: f.Size(),
ModTime: f.ModTime(),
CreateTime: util.Ctime(sys),
Expand Down

0 comments on commit dc968e3

Please sign in to comment.