mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Create image migration code
This commit is contained in:
parent
0f42775282
commit
a8c7ecc865
@ -6,6 +6,8 @@
|
||||
|
||||
# Library root can either be an absolute path or a relative path to your docker-compose.yml file.
|
||||
LIBRARY_ROOT=./video
|
||||
# You should set this to a path where kyoo can write large amount of data, this is used as a cache by the transcoder.
|
||||
# It will automatically be cleaned up on kyoo's startup/shutdown/runtime.
|
||||
CACHE_ROOT=/tmp/kyoo_cache
|
||||
LIBRARY_LANGUAGES=en
|
||||
# A pattern (regex) to ignore video files.
|
||||
@ -61,8 +63,6 @@ OIDC_SERVICE_SCOPE="the list of scopes space separeted like email identity"
|
||||
|
||||
# To debug the front end, you can set the following to an external backend
|
||||
KYOO_URL=
|
||||
# The library root inside the container.
|
||||
KYOO_LIBRARY_ROOT=/video
|
||||
|
||||
# Database things
|
||||
POSTGRES_USER=KyooUser
|
||||
|
@ -179,8 +179,8 @@ public class ThumbnailsManager(
|
||||
string directory = item switch
|
||||
{
|
||||
IResource res
|
||||
=> Path.Combine("./metadata", item.GetType().Name.ToLowerInvariant(), res.Slug),
|
||||
_ => Path.Combine("./metadata", typeof(T).Name.ToLowerInvariant())
|
||||
=> Path.Combine("/metadata", item.GetType().Name.ToLowerInvariant(), res.Slug),
|
||||
_ => Path.Combine("/metadata", typeof(T).Name.ToLowerInvariant())
|
||||
};
|
||||
Directory.CreateDirectory(directory);
|
||||
return Path.Combine(directory, image);
|
||||
|
@ -27,7 +27,6 @@ using Kyoo.RabbitMq;
|
||||
using Kyoo.Swagger;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
@ -94,12 +93,41 @@ app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
app.MapControllers();
|
||||
|
||||
// Set current directory, used by thumbnails for example.
|
||||
string path = Path.GetFullPath(builder.Configuration.GetValue("DATADIR", "/kyoo")!);
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
||||
Environment.CurrentDirectory = path;
|
||||
Log.Information("Data directory: {DataDirectory}", Environment.CurrentDirectory);
|
||||
// TODO: wait 4.5.0 and delete this
|
||||
static void MoveAll(DirectoryInfo source, DirectoryInfo target)
|
||||
{
|
||||
if (source.FullName == target.FullName)
|
||||
return;
|
||||
|
||||
Directory.CreateDirectory(target.FullName);
|
||||
|
||||
foreach (FileInfo fi in source.GetFiles())
|
||||
fi.MoveTo(Path.Combine(target.ToString(), fi.Name), true);
|
||||
|
||||
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
|
||||
{
|
||||
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
|
||||
MoveAll(diSourceSubDir, nextTargetSubDir);
|
||||
}
|
||||
Directory.Delete(source.FullName);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string oldDir = "/kyoo/metadata";
|
||||
if (Path.Exists(oldDir))
|
||||
{
|
||||
MoveAll(new DirectoryInfo(oldDir), new DirectoryInfo("/metadata"));
|
||||
Log.Information("Old metadata directory migrated.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(
|
||||
ex,
|
||||
"Unhandled error while trying to migrate old metadata images to new directory. Giving up and continuing normal startup."
|
||||
);
|
||||
}
|
||||
|
||||
// Activate services that always run in the background
|
||||
app.Services.GetRequiredService<MeiliSync>();
|
||||
|
@ -34,27 +34,10 @@ namespace Kyoo.Core.Api;
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of resource to make CRUD and thumbnails apis for.</typeparam>
|
||||
[ApiController]
|
||||
public class CrudThumbsApi<T> : CrudApi<T>
|
||||
public class CrudThumbsApi<T>(IRepository<T> repository, IThumbnailsManager thumbs)
|
||||
: CrudApi<T>(repository)
|
||||
where T : class, IResource, IThumbnails, IQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// The thumbnail manager used to retrieve images paths.
|
||||
/// </summary>
|
||||
private readonly IThumbnailsManager _thumbs;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="CrudThumbsApi{T}"/> that handles crud requests and thumbnails.
|
||||
/// </summary>
|
||||
/// <param name="repository">
|
||||
/// The repository to use as a baking store for the type <typeparamref name="T"/>.
|
||||
/// </param>
|
||||
/// <param name="thumbs">The thumbnail manager used to retrieve images paths.</param>
|
||||
public CrudThumbsApi(IRepository<T> repository, IThumbnailsManager thumbs)
|
||||
: base(repository)
|
||||
{
|
||||
_thumbs = thumbs;
|
||||
}
|
||||
|
||||
private async Task<IActionResult> _GetImage(
|
||||
Identifier identifier,
|
||||
string image,
|
||||
@ -67,7 +50,7 @@ public class CrudThumbsApi<T> : CrudApi<T>
|
||||
);
|
||||
if (resource == null)
|
||||
return NotFound();
|
||||
string path = _thumbs.GetImagePath(resource, image, quality ?? ImageQuality.High);
|
||||
string path = thumbs.GetImagePath(resource, image, quality ?? ImageQuality.High);
|
||||
if (!System.IO.File.Exists(path))
|
||||
return NotFound();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user