|
|
|
@ -641,6 +641,40 @@ func (f *DBFS) GetFileFromDirectLink(ctx context.Context, dl *ent.DirectLink) (f
|
|
|
|
|
return file, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f *DBFS) TraverseFile(ctx context.Context, fileID int) (fs.File, error) {
|
|
|
|
|
fileModel, err := f.fileClient.GetByID(ctx, fileID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if fileModel.OwnerID != f.user.ID && !f.user.Edges.Group.Permissions.Enabled(int(types.GroupPermissionIsAdmin)) {
|
|
|
|
|
return nil, fs.ErrOwnerOnly.WithError(fmt.Errorf("only file owner can traverse file's uri"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file := newFile(nil, fileModel)
|
|
|
|
|
|
|
|
|
|
// Traverse to the root file
|
|
|
|
|
baseNavigator := newBaseNavigator(f.fileClient, defaultFilter, f.user, f.hasher, f.settingClient.DBFS(ctx))
|
|
|
|
|
root, err := baseNavigator.findRoot(ctx, file)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to find root file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rootUri := newMyUri()
|
|
|
|
|
if fileModel.OwnerID != f.user.ID {
|
|
|
|
|
rootUri = newMyIDUri(hashid.EncodeUserID(f.hasher, fileModel.OwnerID))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if root.Name() != inventory.RootFolderName {
|
|
|
|
|
rootUri = newTrashUri(root.Name())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
root.Path[pathIndexRoot] = rootUri
|
|
|
|
|
root.Path[pathIndexUser] = rootUri
|
|
|
|
|
|
|
|
|
|
return file, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f *DBFS) deleteEntity(ctx context.Context, target *File, entityId int) (inventory.StorageDiff, error) {
|
|
|
|
|
if target.PrimaryEntityID() == entityId {
|
|
|
|
|
return nil, fs.ErrNotSupportedAction.WithError(fmt.Errorf("cannot delete current version"))
|
|
|
|
|