public static void FillWith(this WebCache_FileHash prov, WebCache_FileHash_Collision origin)
 {
     prov.CRC32    = origin.CRC32;
     prov.ED2K     = origin.ED2K;
     prov.FileSize = origin.FileSize;
     prov.MD5      = origin.MD5;
     prov.SHA1     = origin.SHA1;
 }
Exemple #2
0
        public async Task <IActionResult> ApproveCollision(string token, int id)
        {
            try
            {
                SessionInfoWithError s = await VerifyTokenAsync(token);

                if (s.Error != null)
                {
                    return(s.Error);
                }
                if ((s.Role & WebCache_RoleType.Admin) == 0)
                {
                    return(StatusCode(403, "Admin Only"));
                }
                WebCache_FileHash_Collision approved = await _db.WebCache_FileHash_Collisions.FirstOrDefaultAsync(a => a.WebCache_FileHash_Collision_Id == id);

                if (approved == null)
                {
                    return(StatusCode(404, "Collision Not Found"));
                }
                List <WebCache_FileHash_Collision> notapproved = await _db.WebCache_FileHash_Collisions.Where(a => a.WebCache_FileHash_Collision_Unique == approved.WebCache_FileHash_Collision_Unique && a.WebCache_FileHash_Collision_Id != id).ToListAsync();

                foreach (WebCache_FileHash_Collision n in notapproved)
                {
                    WebCache_FileHash_Info fc = await _db.WebCache_FileHashes.FirstOrDefaultAsync(a => a.CRC32 == n.CRC32 && a.ED2K == n.ED2K && a.MD5 == n.MD5 && a.SHA1 == n.SHA1 && a.FileSize == n.FileSize);

                    if (fc != null)
                    {
                        _db.Remove(fc);
                        await _db.SaveChangesAsync();
                    }
                }

                WebCache_FileHash_Info ap = await _db.WebCache_FileHashes.FirstOrDefaultAsync(a => a.CRC32 == approved.CRC32 && a.ED2K == approved.ED2K && a.MD5 == approved.MD5 && a.SHA1 == approved.SHA1 && a.FileSize == approved.FileSize);

                if (ap == null)
                {
                    ap = new WebCache_FileHash_Info();
                    ap.FillWith(approved);
                    _db.Add(ap);
                }

                ap.AniDBUserId       = s.AniDBUserId;
                ap.CollisionApproved = true;
                await _db.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"APPROVECOLLISION with Token={token} Id={id}");
                return(StatusCode(500));
            }
        }
        public static WebCache_FileHash_Collision ToCollision(this WebCache_FileHash_Info prov, string unique)
        {
            WebCache_FileHash_Collision col = new WebCache_FileHash_Collision();

            col.AniDBUserId  = prov.AniDBUserId;
            col.CRC32        = prov.CRC32;
            col.ED2K         = prov.ED2K;
            col.FileSize     = prov.FileSize;
            col.MD5          = prov.MD5;
            col.SHA1         = prov.SHA1;
            col.CreationDate = prov.CreationDate;
            col.WebCache_FileHash_Collision_Unique = unique;
            return(col);
        }