mirror of
https://github.com/sphildreth/roadie
synced 2024-11-22 12:13:10 +00:00
Several bug fixes.
This commit is contained in:
parent
d25524a741
commit
ed4030dcda
11 changed files with 203 additions and 149 deletions
|
@ -95,13 +95,29 @@ namespace Roadie.Library.Engines
|
|||
Data = resultInCache
|
||||
};
|
||||
}
|
||||
|
||||
var searchName = metaData.Release.NormalizeName().ToLower();
|
||||
var specialSearchName = metaData.Release.ToAlphanumericName();
|
||||
|
||||
var altStart = $"{ searchName }|";
|
||||
var altIn = $"|{ searchName }|";
|
||||
var altEnds = $"|{ searchName }";
|
||||
|
||||
var altStartSpecial = $"{ specialSearchName }|";
|
||||
var altInSpecial = $"|{ specialSearchName }|";
|
||||
var altEndsSpecial = $"|{ specialSearchName }";
|
||||
|
||||
var release = (from r in this.DbContext.Releases
|
||||
where (r.ArtistId == artist.Id)
|
||||
where (r.Title.Contains(searchName) ||
|
||||
r.AlternateNames.Contains(searchName) ||
|
||||
r.AlternateNames.Contains(specialSearchName))
|
||||
where (r.Title.ToLower() == searchName ||
|
||||
r.AlternateNames.ToLower() == searchName ||
|
||||
r.AlternateNames.ToLower() == specialSearchName ||
|
||||
r.AlternateNames.ToLower().Contains(altStart) ||
|
||||
r.AlternateNames.ToLower().Contains(altIn) ||
|
||||
r.AlternateNames.ToLower().Contains(altEnds) ||
|
||||
r.AlternateNames.ToLower().Contains(altStartSpecial) ||
|
||||
r.AlternateNames.ToLower().Contains(altInSpecial) ||
|
||||
r.AlternateNames.ToLower().Contains(altEndsSpecial))
|
||||
select r
|
||||
).FirstOrDefault();
|
||||
|
||||
|
|
|
@ -536,7 +536,7 @@ namespace Roadie.Api.Services
|
|||
return await this.ScanFolder(d, dest, user, isReadOnly);
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> ScanRelease(ApplicationUser user, Guid releaseId, bool isReadOnly = false)
|
||||
public async Task<OperationResult<bool>> ScanRelease(ApplicationUser user, Guid releaseId, bool isReadOnly = false, bool wasDoneForInvalidTrackPlay = false)
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
@ -563,6 +563,7 @@ namespace Roadie.Api.Services
|
|||
errors.Add(ex);
|
||||
}
|
||||
sw.Stop();
|
||||
|
||||
this.DbContext.ScanHistories.Add(new data.ScanHistory
|
||||
{
|
||||
UserId = user.Id,
|
||||
|
@ -571,7 +572,7 @@ namespace Roadie.Api.Services
|
|||
TimeSpanInSeconds = (int)sw.Elapsed.TotalSeconds
|
||||
});
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
await this.LogAndPublish($"ScanRelease `{release}`, By User `{user}`", LogLevel.Information);
|
||||
await this.LogAndPublish($"ScanRelease `{release}`, By User `{user}`, WasDoneForInvalidTrackPlay [{ wasDoneForInvalidTrackPlay }]", LogLevel.Information);
|
||||
return new OperationResult<bool>
|
||||
{
|
||||
IsSuccess = !errors.Any(),
|
||||
|
|
|
@ -695,6 +695,8 @@ namespace Roadie.Api.Services
|
|||
result.Releases = dtoReleases;
|
||||
}
|
||||
if (includes.Contains("stats"))
|
||||
{
|
||||
try
|
||||
{
|
||||
tsw.Restart();
|
||||
var artistTracks = (from r in this.DbContext.Releases
|
||||
|
@ -709,7 +711,7 @@ namespace Roadie.Api.Services
|
|||
isMissing = t.Hash == null
|
||||
});
|
||||
var validCartistTracks = artistTracks.Where(x => !x.isMissing);
|
||||
var trackTime = validCartistTracks.Sum(x => x.time);
|
||||
long? trackTime = validCartistTracks.Sum(x => (long?)x.time);
|
||||
result.Statistics = new CollectionStatistics
|
||||
{
|
||||
FileSize = artistTracks.Sum(x => (long?)x.size).ToFileSize(),
|
||||
|
@ -725,6 +727,12 @@ namespace Roadie.Api.Services
|
|||
};
|
||||
tsw.Stop();
|
||||
timings.Add("stats", tsw.ElapsedMilliseconds);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex, $"Error Getting Statistics for Artist `{ artist }`");
|
||||
}
|
||||
}
|
||||
if (includes.Contains("images"))
|
||||
{
|
||||
|
|
|
@ -28,6 +28,6 @@ namespace Roadie.Api.Services
|
|||
|
||||
Task<OperationResult<bool>> ScanLibraryFolder(ApplicationUser user, bool isReadOnly = false);
|
||||
|
||||
Task<OperationResult<bool>> ScanRelease(ApplicationUser user, Guid releaseId, bool isReadOnly = false);
|
||||
Task<OperationResult<bool>> ScanRelease(ApplicationUser user, Guid releaseId, bool isReadOnly = false, bool wasDoneForInvalidTrackPlay = false);
|
||||
}
|
||||
}
|
|
@ -16,6 +16,6 @@ namespace Roadie.Api.Services
|
|||
|
||||
OperationResult<Track> StreamCheckAndInfo(User roadieUser, Guid id);
|
||||
|
||||
Task<OperationResult<TrackStreamInfo>> TrackStreamInfo(Guid trackId, long beginBytes, long endBytes);
|
||||
Task<OperationResult<TrackStreamInfo>> TrackStreamInfo(Guid trackId, long beginBytes, long endBytes, User roadieUser);
|
||||
}
|
||||
}
|
|
@ -37,6 +37,8 @@ namespace Roadie.Api.Services
|
|||
}
|
||||
|
||||
public async Task<OperationResult<PlayActivityList>> CreatePlayActivity(User roadieUser, TrackStreamInfo streamInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
var track = this.DbContext.Tracks
|
||||
|
@ -57,7 +59,9 @@ namespace Roadie.Api.Services
|
|||
var now = DateTime.UtcNow;
|
||||
track.PlayedCount = (track.PlayedCount ?? 0) + 1;
|
||||
track.LastPlayed = now;
|
||||
var user = this.GetUser(roadieUser?.UserId);
|
||||
var user = roadieUser != null ? this.DbContext.Users
|
||||
.Include(x => x.TrackRatings)
|
||||
.FirstOrDefault(x => x.RoadieId == roadieUser.UserId) : null;
|
||||
if (user != null)
|
||||
{
|
||||
userTrack = user.TrackRatings.FirstOrDefault(x => x.TrackId == track.Id);
|
||||
|
@ -71,7 +75,6 @@ namespace Roadie.Api.Services
|
|||
this.DbContext.UserTracks.Add(userTrack);
|
||||
}
|
||||
userTrack.LastPlayed = now;
|
||||
userTrack.PlayedCount++;
|
||||
userTrack.PlayedCount = (userTrack.PlayedCount ?? 0) + 1;
|
||||
this.CacheManager.ClearRegion(user.CacheRegion);
|
||||
}
|
||||
|
@ -155,6 +158,12 @@ namespace Roadie.Api.Services
|
|||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex, $"CreatePlayActivity RoadieUser `{ roadieUser }` StreamInfo `{ streamInfo }`");
|
||||
}
|
||||
return new OperationResult<PlayActivityList>();
|
||||
}
|
||||
|
||||
public Task<Library.Models.Pagination.PagedResult<PlayActivityList>> List(PagedRequest request, User roadieUser = null, DateTime? newerThan = null)
|
||||
{
|
||||
|
|
|
@ -813,7 +813,7 @@ namespace Roadie.Api.Services
|
|||
rm.Id,
|
||||
rm.MediaNumber
|
||||
});
|
||||
var releaseTime = releaseTracks?.Sum(x => x.time) ?? 0;
|
||||
long releaseTime = releaseTracks?.Sum(x => (long?)x.time) ?? 0;
|
||||
var releaseStats = new ReleaseStatistics
|
||||
{
|
||||
MediaCount = release.MediaCount,
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace Roadie.Api.Services
|
|||
public class TrackService : ServiceBase, ITrackService
|
||||
{
|
||||
private IBookmarkService BookmarkService { get; } = null;
|
||||
private IAdminService AdminService { get; }
|
||||
|
||||
public TrackService(IRoadieSettings configuration,
|
||||
IHttpEncoder httpEncoder,
|
||||
|
@ -35,10 +36,12 @@ namespace Roadie.Api.Services
|
|||
data.IRoadieDbContext dbContext,
|
||||
ICacheManager cacheManager,
|
||||
ILogger<TrackService> logger,
|
||||
IBookmarkService bookmarkService)
|
||||
IBookmarkService bookmarkService,
|
||||
IAdminService adminService)
|
||||
: base(configuration, httpEncoder, dbContext, cacheManager, logger, httpContext)
|
||||
{
|
||||
this.BookmarkService = bookmarkService;
|
||||
this.AdminService = adminService;
|
||||
}
|
||||
|
||||
public static long DetermineByteEndFromHeaders(IHeaderDictionary headers, long fileLength)
|
||||
|
@ -587,13 +590,29 @@ namespace Roadie.Api.Services
|
|||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<TrackStreamInfo>> TrackStreamInfo(Guid trackId, long beginBytes, long endBytes)
|
||||
public async Task<OperationResult<TrackStreamInfo>> TrackStreamInfo(Guid trackId, long beginBytes, long endBytes, User roadieUser)
|
||||
{
|
||||
var track = this.GetTrack(trackId);
|
||||
var track = this.DbContext.Tracks.FirstOrDefault(x => x.RoadieId == trackId);
|
||||
if (track == null)
|
||||
{
|
||||
// Not Found try recanning release
|
||||
var release = (from r in this.DbContext.Releases
|
||||
join rm in this.DbContext.ReleaseMedias on r.Id equals rm.ReleaseId
|
||||
where rm.Id == track.ReleaseMediaId
|
||||
select r).FirstOrDefault();
|
||||
if (!release.IsLocked ?? false)
|
||||
{
|
||||
await this.AdminService.ScanRelease(new Library.Identity.ApplicationUser
|
||||
{
|
||||
Id = roadieUser.Id.Value
|
||||
}, release.RoadieId, false, true);
|
||||
}
|
||||
track = this.DbContext.Tracks.FirstOrDefault(x => x.RoadieId == trackId);
|
||||
if(track == null)
|
||||
{
|
||||
return new OperationResult<TrackStreamInfo>($"TrackStreamInfo: Unable To Find Track [{ trackId }]");
|
||||
}
|
||||
}
|
||||
if (!track.IsValid)
|
||||
{
|
||||
return new OperationResult<TrackStreamInfo>($"TrackStreamInfo: Invalid Track. Track Id [{trackId}], FilePath [{track.FilePath}], Filename [{track.FileName}]");
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex, "Error in CreateToken");
|
||||
this.Logger.LogError(ex, $"Error in CreateToken For User [{ model.Username }]");
|
||||
return BadRequest();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,8 +98,9 @@ namespace Roadie.Api.Controllers
|
|||
tsw.Restart();
|
||||
|
||||
var info = await trackService.TrackStreamInfo(id,
|
||||
Services.TrackService.DetermineByteStartFromHeaders(this.Request.Headers),
|
||||
Services.TrackService.DetermineByteEndFromHeaders(this.Request.Headers, track.Data.FileSize));
|
||||
TrackService.DetermineByteStartFromHeaders(this.Request.Headers),
|
||||
TrackService.DetermineByteEndFromHeaders(this.Request.Headers, track.Data.FileSize),
|
||||
user);
|
||||
if (!info?.IsSuccess ?? false || info?.Data == null)
|
||||
{
|
||||
if (info?.Errors != null && (info?.Errors.Any() ?? false))
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"Roadie.Api": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
"ASPNETCORE_ENVIRONMENT": "Production"
|
||||
},
|
||||
"applicationUrl": "http://localhost:5123/"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue