impoort stuff!

This commit is contained in:
Lars Behrends
2025-10-24 16:04:34 +02:00
parent 73d8441787
commit 218d0c28c0
17 changed files with 3043 additions and 277 deletions

View File

@@ -0,0 +1,190 @@
{% extends "admin/layout.twig" %}
{% block content %}
<div class="px-4 py-6 sm:px-6 lg:px-8">
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1 class="text-2xl font-semibold text-gray-900">Import Playnite Games</h1>
<p class="mt-2 text-sm text-gray-700">
Import games from Playnite export files. Playnite is a game library management application that can export your game library to JSON format.
</p>
</div>
</div>
{% if error %}
<div class="mt-6 rounded-md bg-red-50 p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">Import Error</h3>
<div class="mt-2 text-sm text-red-700">
<p>{{ error }}</p>
</div>
</div>
</div>
</div>
{% endif %}
<div class="mt-8 bg-white shadow rounded-lg">
<div class="px-6 py-6">
<div class="space-y-6">
<!-- Import Instructions -->
<div class="bg-blue-50 border border-blue-200 rounded-md p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-blue-400" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-blue-800">How to Export from Playnite</h3>
<div class="mt-2 text-sm text-blue-700">
<ol class="list-decimal list-inside space-y-1">
<li>Open Playnite and go to Library → Export Library</li>
<li>Choose "JSON" as the export format</li>
<li>Select the games you want to export (or export all)</li>
<li>Save the JSON file to your computer</li>
<li>Upload the file using the form below</li>
</ol>
</div>
</div>
</div>
</div>
<!-- Upload Form -->
<form action="{{ path_for('admin.playnite.upload') }}" method="post" enctype="multipart/form-data" class="space-y-6">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<div>
<label for="playnite_file" class="block text-sm font-medium text-gray-700">
Playnite Export File
</label>
<div class="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-md">
<div class="space-y-1 text-center">
<svg class="mx-auto h-12 w-12 text-gray-400" stroke="currentColor" fill="none" viewBox="0 0 48 48">
<path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
</svg>
<div class="flex text-sm text-gray-600">
<label for="playnite_file" class="relative cursor-pointer bg-white rounded-md font-medium text-indigo-600 hover:text-indigo-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-indigo-500">
<span>Upload a file</span>
<input id="playnite_file" name="playnite_file" type="file" class="sr-only" accept=".json">
</label>
<p class="pl-1">or drag and drop</p>
</div>
<p class="text-xs text-gray-500">JSON files only</p>
</div>
</div>
</div>
<!-- Import Options -->
<div class="bg-gray-50 rounded-lg p-4">
<h3 class="text-sm font-medium text-gray-900 mb-3">Import Options</h3>
<div class="space-y-3">
<div class="flex items-start">
<div class="flex items-center h-5">
<input id="update_existing" name="update_existing" type="checkbox" class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" checked>
</div>
<div class="ml-3 text-sm">
<label for="update_existing" class="font-medium text-gray-700">Update existing games</label>
<p class="text-gray-500">If a game with the same Playnite ID already exists, update it with the new data instead of creating a duplicate.</p>
</div>
</div>
</div>
</div>
<!-- Submit Button -->
<div class="flex justify-end space-x-3">
<a href="{{ path_for('admin.index') }}" class="bg-white py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Cancel
</a>
<button type="submit" class="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Upload & Preview
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Recent Imports -->
<div class="mt-8">
<h2 class="text-lg font-medium text-gray-900 mb-4">Recent Playnite Imports</h2>
<div class="bg-white shadow rounded-lg">
<div class="px-6 py-4">
<p class="text-sm text-gray-500">No recent imports found. Import history will appear here.</p>
</div>
</div>
</div>
</div>
<script>
// File upload preview
document.getElementById('playnite_file').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const fileName = file.name;
const fileSize = (file.size / 1024 / 1024).toFixed(2) + ' MB';
// Update the UI to show file info without destroying the file input
const uploadArea = document.querySelector('.border-dashed');
const textElements = uploadArea.querySelectorAll('span, p');
// Update the text content instead of replacing HTML
if (textElements.length >= 2) {
textElements[0].textContent = fileName;
textElements[1].textContent = `${fileSize} - Ready to import`;
}
// Change the SVG to a success icon
const svg = uploadArea.querySelector('svg');
if (svg) {
svg.innerHTML = '<path d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />';
svg.className = 'mx-auto h-12 w-12 text-green-400';
}
}
});
// Drag and drop functionality
const uploadArea = document.querySelector('.border-dashed');
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
uploadArea.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false);
});
['dragenter', 'dragover'].forEach(eventName => {
uploadArea.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
uploadArea.addEventListener(eventName, unhighlight, false);
});
uploadArea.addEventListener('drop', handleDrop, false);
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
function highlight(e) {
uploadArea.classList.add('border-indigo-500');
}
function unhighlight(e) {
uploadArea.classList.remove('border-indigo-500');
}
function handleDrop(e) {
const dt = e.dataTransfer;
const files = dt.files;
if (files.length > 0) {
document.getElementById('playnite_file').files = files;
document.getElementById('playnite_file').dispatchEvent(new Event('change'));
}
}
</script>
{% endblock %}