Compare commits
No commits in common. "8437750a616b241c8cd0c9e4870d6bba0bc96474" and "d9941a0bc257b74b46899d211d88c8d945bae3ca" have entirely different histories.
8437750a61
...
d9941a0bc2
|
@ -22,9 +22,6 @@ namespace TessesDedup
|
|||
[JsonIgnore]
|
||||
public string PasswordSalt {get;set;}
|
||||
|
||||
[JsonIgnore]
|
||||
public long BlockCount {get;set;}=0;
|
||||
|
||||
public void NewSalt()
|
||||
{
|
||||
byte[] bytes=new byte[64];
|
||||
|
|
|
@ -12,7 +12,6 @@ using Tesses.WebServer;
|
|||
using System.Xml;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace TessesDedup
|
||||
{
|
||||
|
@ -250,34 +249,6 @@ namespace TessesDedup
|
|||
routeServer.Add("/api/v1/Registered",RegisteredAsync,"GET");
|
||||
|
||||
routeServer.Add("/api/v1/Stats",StatsAsync,"GET");
|
||||
|
||||
|
||||
using(var _db = Database)
|
||||
{
|
||||
if(_db.Accounts.Count() == 1)
|
||||
{
|
||||
var acnt = _db.Accounts.FindAll().First();
|
||||
if(acnt.BlockCount == 0)
|
||||
{
|
||||
|
||||
long blocks=0;
|
||||
foreach(var dir in fs.EnumerateDirectories(Special.Root))
|
||||
{
|
||||
foreach(var dir2 in fs.EnumerateDirectories(dir))
|
||||
{
|
||||
foreach(var file in fs.EnumerateFiles(dir2))
|
||||
{
|
||||
blocks++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
acnt.BlockCount = blocks;
|
||||
_db.Accounts.Update(acnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AccessKeyDeleteAsync(ServerContext ctx)
|
||||
|
@ -334,8 +305,7 @@ namespace TessesDedup
|
|||
private async Task StatsAsync(ServerContext ctx)
|
||||
{
|
||||
if(await Unauthenticated(ctx)) return;
|
||||
|
||||
/*
|
||||
long blocks = 0;
|
||||
await foreach(var dir in fs.EnumerateDirectoriesAsync(Special.Root))
|
||||
{
|
||||
await foreach(var dir2 in fs.EnumerateDirectoriesAsync(dir))
|
||||
|
@ -347,25 +317,10 @@ namespace TessesDedup
|
|||
|
||||
}
|
||||
|
||||
}*/
|
||||
using(var db = Database)
|
||||
{
|
||||
var key = GetAuthorizationKey(ctx);
|
||||
|
||||
var ak=db.AccessKeys.FindOne(e=>e.Key == key);
|
||||
|
||||
var user = db.Accounts.FindById(ak.UserId);
|
||||
|
||||
if(user != null)
|
||||
{
|
||||
long blocks = user.BlockCount;
|
||||
}
|
||||
long bytes = blocks*DedupStorage.BlockLength;
|
||||
|
||||
using(var db = Database)
|
||||
await ctx.SendJsonAsync(new{blocks,bytes,backups=db.Backups.Count(),label=BytesToUnited(bytes)});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public bool Registered()
|
||||
|
@ -594,14 +549,8 @@ namespace TessesDedup
|
|||
private async Task PutBlockAsync(ServerContext ctx)
|
||||
{
|
||||
if(await Unauthenticated(ctx)) return;
|
||||
|
||||
|
||||
var vals=await ctx.ReadBytesAsync();
|
||||
|
||||
long acntId=GetAccountId(ctx);
|
||||
|
||||
string res = Storage.WriteBlock(vals,this,acntId);
|
||||
await ctx.SendTextAsync(res,"text/plain");
|
||||
await ctx.SendTextAsync(Storage.WriteBlock(vals),"text/plain");
|
||||
}
|
||||
|
||||
private async Task HasBlockAsync(ServerContext ctx)
|
||||
|
@ -746,28 +695,18 @@ namespace TessesDedup
|
|||
return BitConverter.ToString(hash).ToLower().Replace("-","");
|
||||
}
|
||||
}
|
||||
|
||||
public string WriteBlock(byte[] data,Dedup dedup,long acntId)
|
||||
public string WriteBlock(byte[] data)
|
||||
{
|
||||
if(data.Length != BlockLength)
|
||||
mtx.WaitOne();
|
||||
string hash=Sha512Hash(data);
|
||||
|
||||
if(!HasBlock(hash))
|
||||
{
|
||||
|
||||
string hashSlice1 = hash.Substring(0,2);
|
||||
string hashSlice2 = hash.Substring(2,2);
|
||||
vfs.CreateDirectory(Special.Root / hashSlice1);
|
||||
vfs.CreateDirectory(Special.Root / hashSlice1 / hashSlice2);
|
||||
vfs.WriteAllBytes(GetHashPath(hash),data);
|
||||
|
||||
using(var db = dedup.Database)
|
||||
{
|
||||
var acnt=db.Accounts.FindById(acntId);
|
||||
acnt.BlockCount++;
|
||||
db.Accounts.Update(acnt);
|
||||
}
|
||||
}
|
||||
mtx.ReleaseMutex();
|
||||
return hash;
|
||||
|
|
|
@ -16,7 +16,6 @@ using Tesses.VirtualFilesystem;
|
|||
using Tesses.VirtualFilesystem.Extensions;
|
||||
using Tesses.WebServer;
|
||||
using System.Net;
|
||||
using System.Security;
|
||||
namespace TessesDedup
|
||||
{
|
||||
public class DedupClient : IDisposable
|
||||
|
@ -25,17 +24,14 @@ namespace TessesDedup
|
|||
string url;
|
||||
bool ownClient;
|
||||
public bool ShowProgress {get;set;}
|
||||
public bool IgnoreErrors {get;set;}
|
||||
public DedupClient(HttpClient client, string url,bool ownClient=true,bool showProgress=true,bool ignoreErrors=true)
|
||||
public DedupClient(HttpClient client, string url,bool ownClient=true,bool showProgress=true)
|
||||
{
|
||||
ShowProgress = showProgress;
|
||||
IgnoreErrors = ignoreErrors;
|
||||
this.clt = client;
|
||||
this.url = url.TrimEnd('/');
|
||||
this.ownClient = ownClient;
|
||||
|
||||
}
|
||||
public DedupClient(string url,bool showProgress=true,bool ignoreErrors=true) : this(new HttpClient(),url,true,showProgress,ignoreErrors)
|
||||
public DedupClient(string url,bool showProgress=true) : this(new HttpClient(),url,true,showProgress)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -163,14 +159,7 @@ namespace TessesDedup
|
|||
await foreach(var ent in fs.EnumerateFileSystemEntriesAsync(path))
|
||||
{
|
||||
if(token.IsCancellationRequested) return entry;
|
||||
try{
|
||||
entry.Entries.Add(await BackupPathAsync(authkey,fs,ent,token));
|
||||
}catch(Exception ex)
|
||||
{
|
||||
_=ex;
|
||||
if(!IgnoreErrors)
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue