Provide a platform override option during web based import (#94)

This commit is contained in:
Michael Green
2023-09-10 11:36:31 +10:00
committed by GitHub
parent d67c17528a
commit 73bcfe2458
3 changed files with 82 additions and 10 deletions

View File

@@ -23,7 +23,7 @@ namespace gaseous_server.Classes
// import files first
foreach (string importContent in importContents_Files) {
ImportGame.ImportGameFile(importContent);
ImportGame.ImportGameFile(importContent, null, false);
}
}
else
@@ -38,7 +38,7 @@ namespace gaseous_server.Classes
public class ImportGame
{
public static void ImportGameFile(string GameFileImportPath, bool IsDirectory = false, bool ForceImport = false)
public static void ImportGameFile(string GameFileImportPath, IGDB.Models.Platform? OverridePlatform, bool IsDirectory = false)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "";
@@ -50,7 +50,6 @@ namespace gaseous_server.Classes
}
else
{
//Logging.Log(Logging.LogType.Information, "Import Game", "Processing item " + GameFileImportPath);
if (IsDirectory == false)
{
FileInfo fi = new FileInfo(GameFileImportPath);
@@ -80,10 +79,20 @@ namespace gaseous_server.Classes
Models.Signatures_Games discoveredSignature = GetFileSignature(hash, fi, GameFileImportPath);
// get discovered platform
IGDB.Models.Platform determinedPlatform = Metadata.Platforms.GetPlatform(discoveredSignature.Flags.IGDBPlatformId);
if (determinedPlatform == null)
IGDB.Models.Platform? determinedPlatform = null;
if (OverridePlatform == null)
{
determinedPlatform = new IGDB.Models.Platform();
determinedPlatform = Metadata.Platforms.GetPlatform(discoveredSignature.Flags.IGDBPlatformId);
if (determinedPlatform == null)
{
determinedPlatform = new IGDB.Models.Platform();
}
}
else
{
determinedPlatform = OverridePlatform;
discoveredSignature.Flags.IGDBPlatformId = (long)determinedPlatform.Id;
discoveredSignature.Flags.IGDBPlatformName = determinedPlatform.Name;
}
IGDB.Models.Game determinedGame = SearchForGame(discoveredSignature.Game.Name, discoveredSignature.Flags.IGDBPlatformId);

View File

@@ -25,7 +25,7 @@ namespace gaseous_server.Controllers
[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)
public async Task<IActionResult> UploadRom(List<IFormFile> files, long? OverridePlatformId = null)
{
Guid sessionid = Guid.NewGuid();
@@ -61,12 +61,17 @@ namespace gaseous_server.Controllers
}
}
// Process uploaded files
// Don't rely on or trust the FileName property without validation.
// 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.ImportGameFile((string)UploadedFile["fullpath"]);
Classes.ImportGame.ImportGameFile((string)UploadedFile["fullpath"], OverridePlatform, false);
}
if (Directory.Exists(workPath))

View File

@@ -12,9 +12,20 @@
<div>
<div id="upload_target" class="dropzone"></div>
</div>
<table style="width: 100%;">
<tr>
<th style="width: 40%;">
Override automatic platform detection:
</th>
<td style="width: 60%;">
<select id="upload_platformoverride" style="width: 100%;"></select>
</td>
</tr>
</table>
<script type="text/javascript">
document.getElementById('modal-heading').innerHTML = "Upload";
document.getElementById('upload_platformoverride').innerHTML = "<option value='0' selected='selected'>Automatic Platform</option>";
var myDropzone = new Dropzone("div#upload_target", {
url: "/api/v1/Roms",
@@ -69,4 +80,51 @@
subModalContent.innerHTML = "";
subModalVariables = null;
}
$('#upload_platformoverride').select2({
minimumInputLength: 3,
ajax: {
url: '/api/v1/Search/Platform',
data: function (params) {
var query = {
SearchString: params.term
}
// Query parameters will be ?SearchString=[term]
return query;
},
processResults: function (data) {
var arr = [];
// insert automatic detection item
arr.push({
id: 0,
text: "Automatic Platform"
});
for (var i = 0; i < data.length; i++) {
arr.push({
id: data[i].id,
text: data[i].name
});
}
return {
results: arr
};
}
}
});
$('#upload_platformoverride').on('select2:select', function (e) {
var platformOverride = $('#upload_platformoverride').select2('data');
var queryString = '';
if (Number(platformOverride[0].id) != 0) {
queryString = "?OverridePlatformId=" + platformOverride[0].id;
}
console.log(queryString);
myDropzone.options.url = "/api/v1/Roms" + queryString;
});
</script>