
* Update to .net8.0 LTS (closes #271) * Add ARM docker container support (closes #245) * Library updates (closes #260 and #261) * Database updates to support changes in the latest IGDB client version * Version number will no longer be displayed when built from source
93 lines
3.3 KiB
C#
93 lines
3.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using gaseous_server.Classes;
|
|
using gaseous_server.Classes.Metadata;
|
|
using IGDB.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.CodeAnalysis.Scripting;
|
|
using static gaseous_server.Classes.Metadata.AgeRatings;
|
|
using Asp.Versioning;
|
|
|
|
namespace gaseous_server.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/[controller]")]
|
|
[ApiVersion("1.0")]
|
|
[ApiVersion("1.1")]
|
|
[Authorize]
|
|
[ApiController]
|
|
public class RomsController : Controller
|
|
{
|
|
[MapToApiVersion("1.0")]
|
|
[MapToApiVersion("1.1")]
|
|
[HttpPost]
|
|
[Authorize(Roles = "Admin,Gamer")]
|
|
[ProducesResponseType(typeof(List<IFormFile>), StatusCodes.Status200OK)]
|
|
[RequestSizeLimit(long.MaxValue)]
|
|
[DisableRequestSizeLimit, RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue, ValueLengthLimit = int.MaxValue)]
|
|
public async Task<IActionResult> UploadRom(List<IFormFile> files, long? OverridePlatformId = null)
|
|
{
|
|
Guid sessionid = Guid.NewGuid();
|
|
|
|
string workPath = Path.Combine(Config.LibraryConfiguration.LibraryUploadDirectory, sessionid.ToString());
|
|
|
|
long size = files.Sum(f => f.Length);
|
|
|
|
List<Dictionary<string, object>> UploadedFiles = new List<Dictionary<string, object>>();
|
|
|
|
foreach (IFormFile formFile in files)
|
|
{
|
|
if (formFile.Length > 0)
|
|
{
|
|
Guid FileId = Guid.NewGuid();
|
|
|
|
string filePath = Path.Combine(workPath, Path.GetFileName(formFile.FileName));
|
|
|
|
if (!Directory.Exists(workPath))
|
|
{
|
|
Directory.CreateDirectory(workPath);
|
|
}
|
|
|
|
using (var stream = System.IO.File.Create(filePath))
|
|
{
|
|
await formFile.CopyToAsync(stream);
|
|
|
|
Dictionary<string, object> UploadedFile = new Dictionary<string, object>();
|
|
UploadedFile.Add("id", FileId.ToString());
|
|
UploadedFile.Add("originalname", Path.GetFileName(formFile.FileName));
|
|
UploadedFile.Add("fullpath", filePath);
|
|
UploadedFiles.Add(UploadedFile);
|
|
}
|
|
}
|
|
}
|
|
|
|
// get override platform if specified
|
|
IGDB.Models.Platform? OverridePlatform = null;
|
|
if (OverridePlatformId != null)
|
|
{
|
|
OverridePlatform = Platforms.GetPlatform((long)OverridePlatformId);
|
|
}
|
|
|
|
// Process uploaded files
|
|
foreach (Dictionary<string, object> UploadedFile in UploadedFiles)
|
|
{
|
|
Classes.ImportGame uploadImport = new ImportGame();
|
|
uploadImport.ImportGameFile((string)UploadedFile["fullpath"], OverridePlatform);
|
|
}
|
|
|
|
if (Directory.Exists(workPath))
|
|
{
|
|
Directory.Delete(workPath, true);
|
|
}
|
|
|
|
return Ok(new { count = files.Count, size });
|
|
}
|
|
}
|
|
} |