diff --git a/supernode/daemon/mgr/cdn/manager.go b/supernode/daemon/mgr/cdn/manager.go index 4449c311a..61720bb71 100644 --- a/supernode/daemon/mgr/cdn/manager.go +++ b/supernode/daemon/mgr/cdn/manager.go @@ -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 diff --git a/supernode/daemon/mgr/cdn_mgr.go b/supernode/daemon/mgr/cdn_mgr.go index 6e385e34d..6dd6ddf5f 100644 --- a/supernode/daemon/mgr/cdn_mgr.go +++ b/supernode/daemon/mgr/cdn_mgr.go @@ -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) diff --git a/supernode/daemon/mgr/mock/mock_cdn_mgr.go b/supernode/daemon/mgr/mock/mock_cdn_mgr.go index 80d8dfb9e..208b5922c 100644 --- a/supernode/daemon/mgr/mock/mock_cdn_mgr.go +++ b/supernode/daemon/mgr/mock/mock_cdn_mgr.go @@ -51,6 +51,21 @@ func (mr *MockCDNMgrMockRecorder) TriggerCDN(ctx, taskInfo interface{}) *gomock. return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TriggerCDN", reflect.TypeOf((*MockCDNMgr)(nil).TriggerCDN), ctx, taskInfo) } +// GetHTTPPath mocks base method +func (m *MockCDNMgr) GetHTTPPath(ctx context.Context, taskID string) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetHTTPPath", ctx, taskID) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetHTTPPath indicates an expected call of GetHTTPPath +func (mr *MockCDNMgrMockRecorder) GetHTTPPath(ctx, taskID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHTTPPath", reflect.TypeOf((*MockCDNMgr)(nil).GetHTTPPath), ctx, taskID) +} + // GetStatus mocks base method func (m *MockCDNMgr) GetStatus(ctx context.Context, taskID string) (string, error) { m.ctrl.T.Helper() diff --git a/supernode/store/local_storage.go b/supernode/store/local_storage.go index aae58fc48..6f08d7b4d 100644 --- a/supernode/store/local_storage.go +++ b/supernode/store/local_storage.go @@ -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 } @@ -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(), diff --git a/supernode/store/local_storage_test.go b/supernode/store/local_storage_test.go index b657511b9..02e7b2e52 100644 --- a/supernode/store/local_storage_test.go +++ b/supernode/store/local_storage_test.go @@ -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),