mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
Changed cache control on tracks to disabled, causing issues with playbakc on some devices trying to cache partial streams.
This commit is contained in:
parent
51e647f7ef
commit
14a7119993
4 changed files with 44 additions and 9 deletions
|
@ -18,6 +18,7 @@
|
|||
public bool IsEndRangeRequest { get; set; }
|
||||
public bool IsFullRequest { get; set; }
|
||||
public string LastModified { get; set; }
|
||||
public string Pragma { get; set; }
|
||||
public DataToken Track { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
|
|
|
@ -650,6 +650,15 @@ namespace Roadie.Api.Services
|
|||
return new OperationResult<bool>($"Artist already exists with name [{ model.Name }].");
|
||||
}
|
||||
}
|
||||
// If artist sortname is being modified, see if artist already exists with new model supplied sort name
|
||||
if ((artist.SortName?.ToAlphanumericName() ?? string.Empty) != (model.SortName?.ToAlphanumericName() ?? string.Empty))
|
||||
{
|
||||
var existingArtist = DbContext.Artists.FirstOrDefault(x => x.SortName == model.SortName);
|
||||
if (existingArtist != null)
|
||||
{
|
||||
return new OperationResult<bool>($"Artist already exists with sort name [{ model.SortName }].");
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
|
@ -689,12 +698,20 @@ namespace Roadie.Api.Services
|
|||
// If folder already exists for new artist name that means another artist has that folder (usually sort name)
|
||||
if (Directory.Exists(newArtistFolder))
|
||||
{
|
||||
return new OperationResult<bool>($"Artist Folder [{ newArtistFolder }] already exists.");
|
||||
// Set sortname to be unique and try again
|
||||
var oldSortName = artist.SortName;
|
||||
artist.SortName = $"{ artist.SortName} [{ artist.Id }]";
|
||||
Logger.LogTrace($"Updated Artist SortName From [{ oldSortName }] to [{ artist.SortName }]");
|
||||
newArtistFolder = artist.ArtistFileFolder(Configuration);
|
||||
if (Directory.Exists(newArtistFolder))
|
||||
{
|
||||
return new OperationResult<bool>($"Artist Folder [{ newArtistFolder }] already exists.");
|
||||
}
|
||||
}
|
||||
didRenameArtist = true;
|
||||
if (Directory.Exists(originalArtistFolder))
|
||||
{
|
||||
Logger.LogTrace("Moving Artist From Folder [{0}] -> [{1}]", originalArtistFolder, newArtistFolder);
|
||||
Logger.LogTrace($"Moving Artist From Folder [{originalArtistFolder}] -> [{newArtistFolder}]");
|
||||
Directory.Move(originalArtistFolder, newArtistFolder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -778,6 +778,8 @@ namespace Roadie.Api.Services
|
|||
}
|
||||
}
|
||||
|
||||
var disableCaching = true;
|
||||
|
||||
var contentDurationTimeSpan = TimeSpan.FromMilliseconds(track.Duration ?? 0);
|
||||
var info = new TrackStreamInfo
|
||||
{
|
||||
|
@ -786,7 +788,6 @@ namespace Roadie.Api.Services
|
|||
$"attachment; filename=\"{HttpEncoder.UrlEncode(track.FileName).ToContentDispositionFriendly()}\"",
|
||||
ContentDuration = contentDurationTimeSpan.TotalSeconds.ToString()
|
||||
};
|
||||
var cacheTimeout = 86400; // 24 hours
|
||||
var contentLength = endBytes - beginBytes + 1;
|
||||
info.Track = new DataToken
|
||||
{
|
||||
|
@ -800,9 +801,19 @@ namespace Roadie.Api.Services
|
|||
info.IsFullRequest = beginBytes == 0 && endBytes == trackFileInfo.Length - 1;
|
||||
info.IsEndRangeRequest = beginBytes > 0 && endBytes != trackFileInfo.Length - 1;
|
||||
info.LastModified = (track.LastUpdated ?? track.CreatedDate).ToString("R");
|
||||
info.Etag = track.Etag;
|
||||
info.CacheControl = $"public, max-age={cacheTimeout.ToString()} ";
|
||||
info.Expires = DateTime.UtcNow.AddMinutes(cacheTimeout).ToString("R");
|
||||
if (!disableCaching)
|
||||
{
|
||||
var cacheTimeout = 86400; // 24 hours
|
||||
info.CacheControl = $"public, max-age={cacheTimeout.ToString()} ";
|
||||
info.Expires = DateTime.UtcNow.AddMinutes(cacheTimeout).ToString("R");
|
||||
info.Etag = track.Etag;
|
||||
}
|
||||
else
|
||||
{
|
||||
info.CacheControl = "no-store, must-revalidate, no-cache, max-age=0";
|
||||
info.Pragma = "no-cache";
|
||||
info.Expires = "Mon, 01 Jan 1990 00:00:00 GMT";
|
||||
}
|
||||
var bytesToRead = (int)(endBytes - beginBytes) + 1;
|
||||
var trackBytes = new byte[bytesToRead];
|
||||
using (var fs = trackFileInfo.OpenRead())
|
||||
|
|
|
@ -117,11 +117,17 @@ namespace Roadie.Api.Controllers
|
|||
|
||||
Response.Headers.Add("Content-Length", info.Data.ContentLength);
|
||||
Response.ContentType = info.Data.ContentType;
|
||||
Response.StatusCode =
|
||||
info.Data.IsFullRequest ? (int)HttpStatusCode.OK : (int)HttpStatusCode.PartialContent;
|
||||
Response.StatusCode = info.Data.IsFullRequest ? (int)HttpStatusCode.OK : (int)HttpStatusCode.PartialContent;
|
||||
Response.Headers.Add("Last-Modified", info.Data.LastModified);
|
||||
Response.Headers.Add("ETag", info.Data.Etag);
|
||||
if (!string.IsNullOrEmpty(info.Data.Etag))
|
||||
{
|
||||
Response.Headers.Add("ETag", info.Data.Etag);
|
||||
}
|
||||
Response.Headers.Add("Cache-Control", info.Data.CacheControl);
|
||||
if (!string.IsNullOrEmpty(info.Data.Pragma))
|
||||
{
|
||||
Response.Headers.Add("Pragma", info.Data.Pragma);
|
||||
}
|
||||
Response.Headers.Add("Expires", info.Data.Expires);
|
||||
|
||||
await Response.Body.WriteAsync(info.Data.Bytes, 0, info.Data.Bytes.Length);
|
||||
|
|
Loading…
Reference in a new issue