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 can either be an absolute path or a relative path to your docker-compose.yml file.
|
||||||
LIBRARY_ROOT=./video
|
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
|
CACHE_ROOT=/tmp/kyoo_cache
|
||||||
LIBRARY_LANGUAGES=en
|
LIBRARY_LANGUAGES=en
|
||||||
# A pattern (regex) to ignore video files.
|
# 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
|
# To debug the front end, you can set the following to an external backend
|
||||||
KYOO_URL=
|
KYOO_URL=
|
||||||
# The library root inside the container.
|
|
||||||
KYOO_LIBRARY_ROOT=/video
|
|
||||||
|
|
||||||
# Database things
|
# Database things
|
||||||
POSTGRES_USER=KyooUser
|
POSTGRES_USER=KyooUser
|
||||||
|
@ -179,8 +179,8 @@ public class ThumbnailsManager(
|
|||||||
string directory = item switch
|
string directory = item switch
|
||||||
{
|
{
|
||||||
IResource res
|
IResource res
|
||||||
=> Path.Combine("./metadata", item.GetType().Name.ToLowerInvariant(), res.Slug),
|
=> Path.Combine("/metadata", item.GetType().Name.ToLowerInvariant(), res.Slug),
|
||||||
_ => Path.Combine("./metadata", typeof(T).Name.ToLowerInvariant())
|
_ => Path.Combine("/metadata", typeof(T).Name.ToLowerInvariant())
|
||||||
};
|
};
|
||||||
Directory.CreateDirectory(directory);
|
Directory.CreateDirectory(directory);
|
||||||
return Path.Combine(directory, image);
|
return Path.Combine(directory, image);
|
||||||
|
@ -27,7 +27,6 @@ using Kyoo.RabbitMq;
|
|||||||
using Kyoo.Swagger;
|
using Kyoo.Swagger;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
@ -94,12 +93,41 @@ app.UseRouting();
|
|||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
// Set current directory, used by thumbnails for example.
|
// TODO: wait 4.5.0 and delete this
|
||||||
string path = Path.GetFullPath(builder.Configuration.GetValue("DATADIR", "/kyoo")!);
|
static void MoveAll(DirectoryInfo source, DirectoryInfo target)
|
||||||
if (!Directory.Exists(path))
|
{
|
||||||
Directory.CreateDirectory(path);
|
if (source.FullName == target.FullName)
|
||||||
Environment.CurrentDirectory = path;
|
return;
|
||||||
Log.Information("Data directory: {DataDirectory}", Environment.CurrentDirectory);
|
|
||||||
|
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
|
// Activate services that always run in the background
|
||||||
app.Services.GetRequiredService<MeiliSync>();
|
app.Services.GetRequiredService<MeiliSync>();
|
||||||
|
@ -34,27 +34,10 @@ namespace Kyoo.Core.Api;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The type of resource to make CRUD and thumbnails apis for.</typeparam>
|
/// <typeparam name="T">The type of resource to make CRUD and thumbnails apis for.</typeparam>
|
||||||
[ApiController]
|
[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
|
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(
|
private async Task<IActionResult> _GetImage(
|
||||||
Identifier identifier,
|
Identifier identifier,
|
||||||
string image,
|
string image,
|
||||||
@ -67,7 +50,7 @@ public class CrudThumbsApi<T> : CrudApi<T>
|
|||||||
);
|
);
|
||||||
if (resource == null)
|
if (resource == null)
|
||||||
return NotFound();
|
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))
|
if (!System.IO.File.Exists(path))
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user