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

Commit dc968e3

Browse files
committed
feature: add GetHTTPPath function for cdn mgr
Signed-off-by: Starnop <starnop@163.com>
1 parent e8f36c8 commit dc968e3

5 files changed

Lines changed: 30 additions & 3 deletions

File tree

supernode/daemon/mgr/cdn/manager.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ func (cm *Manager) TriggerCDN(ctx context.Context, task *types.TaskInfo) (*types
106106
}, nil
107107
}
108108

109+
// GetHTTPPath returns the http download path of taskID.
110+
func (cm *Manager) GetHTTPPath(ctx context.Context, taskID string) (string, error) {
111+
info, err := cm.cacheStore.Stat(ctx, getDownloadRawFunc(taskID))
112+
if err != nil {
113+
return "", err
114+
}
115+
return info.Path, nil
116+
}
117+
109118
// GetStatus get the status of the file.
110119
func (cm *Manager) GetStatus(ctx context.Context, taskID string) (cdnStatus string, err error) {
111120
return "", nil

supernode/daemon/mgr/cdn_mgr.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type CDNMgr interface {
1919
// In addition, it's not thread-safe.
2020
TriggerCDN(ctx context.Context, taskInfo *types.TaskInfo) (*types.TaskInfo, error)
2121

22+
// GetHTTPPath returns the http download path of taskID.
23+
GetHTTPPath(ctx context.Context, taskID string) (path string, err error)
24+
2225
// GetStatus get the status of the file.
2326
GetStatus(ctx context.Context, taskID string) (cdnStatus string, err error)
2427

supernode/daemon/mgr/mock/mock_cdn_mgr.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

supernode/store/local_storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func (ls *localStorage) PutBytes(ctx context.Context, raw *Raw, data []byte) err
247247

248248
// Stat determine whether the file exists.
249249
func (ls *localStorage) Stat(ctx context.Context, raw *Raw) (*StorageInfo, error) {
250-
path, fileInfo, err := ls.statPath(raw.Bucket, raw.Key)
250+
_, fileInfo, err := ls.statPath(raw.Bucket, raw.Key)
251251
if err != nil {
252252
return nil, err
253253
}
@@ -257,7 +257,7 @@ func (ls *localStorage) Stat(ctx context.Context, raw *Raw) (*StorageInfo, error
257257
return nil, fmt.Errorf("get create time error")
258258
}
259259
return &StorageInfo{
260-
Path: path,
260+
Path: path.Join(raw.Bucket, raw.Key),
261261
Size: fileInfo.Size(),
262262
CreateTime: util.Ctime(sys),
263263
ModTime: fileInfo.ModTime(),

supernode/store/local_storage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (s *LocalStorageSuite) checkStat(raw *Raw, c *check.C) {
323323
sys, _ := util.GetSys(f)
324324

325325
c.Assert(info, check.DeepEquals, &StorageInfo{
326-
Path: pathTemp,
326+
Path: path.Join(raw.Bucket, raw.Key),
327327
Size: f.Size(),
328328
ModTime: f.ModTime(),
329329
CreateTime: util.Ctime(sys),

0 commit comments

Comments
 (0)