Skip to content

Commit

Permalink
Merge branch 'develop2'
Browse files Browse the repository at this point in the history
  • Loading branch information
yar229 committed Mar 5, 2019
2 parents b1ea350 + 9fb2ebf commit caae4c3
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 20 deletions.
2 changes: 1 addition & 1 deletion MailRuCloud/MailRuCloudApi/Base/Credentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Credentials(string login, string password)
public string Login { get; }
public string Password { get; }

public string PasswordCrypt { get; }
public string PasswordCrypt { get; set; }

public bool CanCrypt => !string.IsNullOrEmpty(PasswordCrypt);

Expand Down
24 changes: 23 additions & 1 deletion MailRuCloud/MailRuCloudApi/Base/Repos/WebM1RequestRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,28 @@ private async Task<IEntry> FolderInfo(string path, int depth = 1)
{
datares = await new Requests.WebBin.ListRequest(HttpSettings, Authent, ShardManager.MetaServer.Url, path, depth)
.MakeRequestAsync();

// если файл разбит или зашифрован - то надо взять все куски
// в протоколе V2 на запрос к файлу сразу приходит листинг каталога, в котором он лежит
// здесь (протокол Bin) приходит информация именно по указанному файлу
// поэтому вот такой костыль с двойным запросом
//TODO: переделать двойной запрос к файлу
if (datares.Item is Requests.WebBin.Types.FsFile fsfile && fsfile.Size < 2048)
{
string name = WebDavPath.Name(path);
path = WebDavPath.Parent(path);

datares = await new Requests.WebBin.ListRequest(HttpSettings, Authent, ShardManager.MetaServer.Url, path, 1)
.MakeRequestAsync();

var zz = datares.ToFolder();

return zz.Files.First(f => f.Name == name);
}
}
catch (RequestException re) when (re.StatusCode == HttpStatusCode.NotFound)
{
return null;
}
catch (WebException e) when ((e.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound)
{
Expand All @@ -239,7 +261,7 @@ public async Task<IEntry> FolderInfo(string path, Link ulink, int offset = 0, in
if (_creds.IsAnonymous)
return await AnonymousRepo.FolderInfo(path, ulink, offset, limit);

if (null == ulink)
if (null == ulink && depth > 1)
return await FolderInfo(path, depth);

FolderInfoResult datares;
Expand Down
16 changes: 2 additions & 14 deletions MailRuCloud/MailRuCloudApi/Base/Requests/WebBin/ListRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ protected override RequestResponse<Result> DeserializeMessage(ResponseBodyStream
case OperationResult.Ok:
break;
case OperationResult.NotExists:
throw new FooWebException($"{nameof(ListRequest)} failed with result code {data.OperationResult}", HttpStatusCode.NotFound);
//throw new NotFoundException($"{nameof(ListRequest)} failed with result code {data.OperationResult}", HttpStatusCode.NotFound);
throw new RequestException(_fullPath) {StatusCode = HttpStatusCode.NotFound};
default:
throw new Exception($"{nameof(ListRequest)} failed with result code {data.OperationResult}");
}
Expand Down Expand Up @@ -264,17 +265,4 @@ public class Result : RevisionResponseResult
public FsItem Item { get; set; }
}
}

//TODO: refact with WebException?
internal class FooWebException : Exception
{
public FooWebException(string message, HttpStatusCode statusCode)
{
Message = message;
StatusCode = statusCode;
}

public string Message { get; }
public HttpStatusCode StatusCode { get; }
}
}
4 changes: 2 additions & 2 deletions MailRuCloud/MailRuCloudApi/MailRuCloudApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFrameworks>netcoreapp2.0;net452</TargetFrameworks>
<RootNamespace>YaR.MailRuCloud.Api</RootNamespace>
<AssemblyName>MailRuCloud.Api</AssemblyName>
<AssemblyVersion>1.10.4.0</AssemblyVersion>
<FileVersion>1.10.4.0</FileVersion>
<AssemblyVersion>1.10.4.1</AssemblyVersion>
<FileVersion>1.10.4.1</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 28 additions & 0 deletions MailRuCloud/MailRuCloudApi/SpecialCommands/CryptPasswdCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace YaR.MailRuCloud.Api.SpecialCommands
{
/// <summary>
/// Ïàðîëü äëÿ (äå)øèôðîâàíèÿ
/// </summary>
public class CryptPasswdCommand : SpecialCommand
{
public CryptPasswdCommand(MailRuCloud cloud, string path, IList<string> parames) : base(cloud, path, parames)
{
}

protected override MinMax<int> MinMaxParamsCount { get; } = new MinMax<int>(1);

public override async Task<SpecialCommandResult> Execute()
{
var newPasswd = Parames[0];
if (string.IsNullOrEmpty(newPasswd))
return new SpecialCommandResult(false, "Crypt password is empty");

Cloud.Account.Credentials.PasswordCrypt = newPasswd;

return SpecialCommandResult.Success;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public class SpecialCommandFabric
CreateFunc = (cloud, path, param) => new CryptInitCommand(cloud, path, param)
},
new SpecialCommandContainer
{
Commands = new [] {"crypt", "passwd"},
CreateFunc = (cloud, path, param) => new CryptPasswdCommand(cloud, path, param)
},
new SpecialCommandContainer
{
Commands = new [] {"share"},
CreateFunc = (cloud, path, param) => new ShareCommand(cloud, path, false, false, param)
Expand Down
4 changes: 2 additions & 2 deletions WDMRC.Console/WDMRC.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<Copyright>[email protected]</Copyright>
<Description>WebDAV emulator for Cloud.mail.ru</Description>
<PackageId>WebDAVCloudMailRu</PackageId>
<AssemblyVersion>1.10.4.0</AssemblyVersion>
<FileVersion>1.10.4.0</FileVersion>
<AssemblyVersion>1.10.4.1</AssemblyVersion>
<FileVersion>1.10.4.1</FileVersion>
<AssemblyName>wdmrc</AssemblyName>
<RootNamespace>YaR.CloudMailRu.Console</RootNamespace>
<StartupObject></StartupObject>
Expand Down

0 comments on commit caae4c3

Please sign in to comment.