Upload via GUI (32 Dateien)

This commit is contained in:
2026-10-25 17:58:33 +00:00
parent 7f79c59ac4
commit a62971926b
12 changed files with 701 additions and 364 deletions
+49
View File
@@ -7,6 +7,7 @@ declare(strict_types=1);
*/
const SITE_MAX_PACKAGE_BYTES = 10 * 1024 * 1024;
const SITE_MAX_APP_BYTES = 300 * 1024 * 1024;
const SITE_MAX_PREVIEW_BYTES = 1024 * 1024;
const SITE_PLUGIN_EXTENSIONS = ['php', 'json', 'sql', 'js', 'css', 'png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'md', 'txt', 'html'];
const SITE_THEME_EXTENSIONS = ['css', 'png', 'jpg', 'jpeg', 'gif', 'webp', 'woff', 'woff2'];
@@ -95,6 +96,10 @@ function site_db(): PDO
signature TEXT NOT NULL DEFAULT '', size INTEGER NOT NULL, requires TEXT NOT NULL DEFAULT '', permissions TEXT NOT NULL DEFAULT '',
downloads INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL, UNIQUE (item_id, version),
FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE)");
$pdo->exec("CREATE TABLE IF NOT EXISTS app_releases (
id INTEGER PRIMARY KEY AUTOINCREMENT, platform TEXT NOT NULL, version TEXT NOT NULL, file TEXT NOT NULL,
sha256 TEXT NOT NULL, size INTEGER NOT NULL, notes TEXT NOT NULL DEFAULT '', created_at TEXT NOT NULL,
UNIQUE(platform, version))");
// Empfehlung (nachträglich ergänzt, damit bestehende Datenbanken ohne Handarbeit weiterlaufen)
$cols = array_column($pdo->query('PRAGMA table_info(items)')->fetchAll(), 'name');
if (!in_array('featured', $cols, true)) $pdo->exec('ALTER TABLE items ADD COLUMN featured INTEGER NOT NULL DEFAULT 0');
@@ -102,6 +107,50 @@ function site_db(): PDO
return $pdo;
}
/** Latest published app release per platform: the HIGHEST version, not the one uploaded last. */
function site_app_release(string $platform): ?array
{
if (!in_array($platform, ['android', 'windows', 'minecraft'], true)) return null;
$stmt = site_db()->prepare('SELECT * FROM app_releases WHERE platform = ?');
$stmt->execute([$platform]);
$rows = $stmt->fetchAll();
if (!$rows) return null;
usort($rows, fn($a, $b) => version_compare($b['version'], $a['version']) ?: ((int) $b['id'] <=> (int) $a['id']));
return $rows[0];
}
function site_app_releases(): array
{
$rows = site_db()->query('SELECT * FROM app_releases')->fetchAll();
usort($rows, fn($a, $b) => strcmp($a['platform'], $b['platform']) ?: (version_compare($b['version'], $a['version']) ?: ((int) $b['id'] <=> (int) $a['id'])));
return $rows;
}
function site_publish_app(string $platform, string $tmp, string $version, string $notes): array
{
$types = ['android' => ['apk', "PK"], 'windows' => ['exe', "MZ"], 'minecraft' => ['jar', "PK"]];
if (!isset($types[$platform])) return ['ok' => false, 'error' => 'Unbekannte Plattform.'];
if (!preg_match('/^\\d+\\.\\d+\\.\\d+(?:[-+][0-9A-Za-z.-]+)?$/', $version)) return ['ok' => false, 'error' => 'Bitte eine Versionsnummer wie 3.4.0 eingeben.'];
if (!is_uploaded_file($tmp)) return ['ok' => false, 'error' => 'Die hochgeladene Datei wurde nicht gefunden.'];
$size = (int) filesize($tmp);
if ($size < 1024 || $size > SITE_MAX_APP_BYTES) return ['ok' => false, 'error' => 'Die Datei muss zwischen 1 KB und 300 MB groß sein.'];
$head = (string) file_get_contents($tmp, false, null, 0, 2);
if ($head !== $types[$platform][1]) return ['ok' => false, 'error' => 'Dateityp passt nicht zur gewählten Plattform.'];
$dir = site_storage() . '/apps/' . $platform;
if (!is_dir($dir) && !@mkdir($dir, 0755, true)) return ['ok' => false, 'error' => 'App-Speicher konnte nicht angelegt werden.'];
$file = bin2hex(random_bytes(24)) . '.' . $types[$platform][0];
if (!move_uploaded_file($tmp, $dir . '/' . $file)) return ['ok' => false, 'error' => 'App-Datei konnte nicht gespeichert werden.'];
$sha = hash_file('sha256', $dir . '/' . $file);
try {
$stmt = site_db()->prepare('INSERT INTO app_releases(platform,version,file,sha256,size,notes,created_at) VALUES(?,?,?,?,?,?,?)');
$stmt->execute([$platform, $version, $file, $sha, $size, substr(trim($notes), 0, 2000), date('Y-m-d H:i:s')]);
} catch (PDOException $e) {
@unlink($dir . '/' . $file);
return ['ok' => false, 'error' => str_contains(strtolower($e->getMessage()), 'unique') ? 'Diese Version ist für diese Plattform bereits vorhanden.' : 'Release konnte nicht gespeichert werden.'];
}
return ['ok' => true];
}
/** Plugin bzw. Theme als „Empfohlen“ markieren oder die Markierung entfernen. */
function site_set_featured(int $itemId, bool $featured): bool
{