Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release list #353

Open
wants to merge 6 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/incl/searchbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class="action resptable-cell">List Categories
</div>
<div class="release-filter">
<select id="api-list" class="release-filter-select">
<option value="All API versions" <?= isset($this->preferApi) ? "" : "selected" ?>>Choose API</option>
<option value="All API versions" <?= $this->preferApi === "any" ? "" : "selected" ?>>Any API</option>
<?php
foreach(array_reverse(PocketMineApi::$VERSIONS) as $apiversion => $description) { ?>
<option <?= isset($this->preferApi) && $this->preferApi === $apiversion ? "selected" : "" ?>
value="<?= $apiversion ?>"><?= $apiversion ?></option>
value="<?= $apiversion ?>">API <?= $apiversion ?></option>
<?php }
?>
</select>
Expand Down
5 changes: 5 additions & 0 deletions doc/20240617.patch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP TABLE IF EXISTS `spoon_desc`;
ALTER TABLE `known_spoons` DROP COLUMN `php`,
DROP COLUMN `indev`,
DROP COLUMN `supported`,
DROP COLUMN `pharDefault`;
50 changes: 10 additions & 40 deletions doc/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ DROP TABLE IF EXISTS `known_spoons`;
CREATE TABLE `known_spoons` (
`id` smallint NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` varchar(16) UNIQUE,
`php` varchar(5) DEFAULT '7.2',
`incompatible` tinyint(1) NOT NULL,
`indev` tinyint(1) NOT NULL,
`supported` tinyint(1) NOT NULL DEFAULT '0',
`pharDefault` varchar(255)
`incompatible` tinyint(1) NOT NULL
);
DROP TABLE IF EXISTS `releases`;
CREATE TABLE `releases` (
Expand Down Expand Up @@ -222,12 +218,6 @@ CREATE TABLE `spoon_prom` (
KEY `value` (`value`),
FOREIGN KEY (`value`) REFERENCES `known_spoons` (`name`)
);
DROP TABLE IF EXISTS `spoon_desc`;
CREATE TABLE `spoon_desc` (
`api` varchar(20),
`value` varchar(500),
KEY `api` (`api`)
);
DROP TABLE IF EXISTS `release_spoons`;
CREATE TABLE `release_spoons` (
`releaseId` int unsigned,
Expand Down Expand Up @@ -326,37 +316,17 @@ CREATE TABLE `ext_refs` (
);

-- Default data needed for out of the box to work, use spoons.edit to add/edit more
INSERT INTO `known_spoons` (`id`, `name`, `php`, `incompatible`, `indev`, `supported`, `pharDefault`) VALUES
(0, '3.0.0', '7.2', true, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.0.0/PocketMine-MP.phar'),
(1, '3.1.0', '7.2', false, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.1.0/PocketMine-MP.phar'),
(2, '3.2.0', '7.2', false, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.2.0/PocketMine-MP.phar'),
(3, '3.3.0', '7.2', false, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.3.0/PocketMine-MP.phar'),
(4, '3.4.0', '7.2', false, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.4.0/PocketMine-MP.phar'),
(5, '3.5.0', '7.2', false, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.5.0/PocketMine-MP.phar'),
(6, '3.6.0', '7.2', false, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.6.0/PocketMine-MP.phar'),
(7, '3.7.0', '7.2', false, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.7.0/PocketMine-MP.phar'),
(8, '3.8.0', '7.2', false, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.8.0/PocketMine-MP.phar'),
(9, '3.9.0', '7.2', false, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.9.0/PocketMine-MP.phar'),
(10, '3.10.0', '7.2', false, false, false, 'https://github.com/pmmp/PocketMine-MP/releases/download/3.10.0/PocketMine-MP.phar');

INSERT INTO `spoon_desc` (`api`, `value`) VALUES
('3.0.0', 'MCPE 1.4 Support'),
('3.1.0', 'MCPE 1.5 Support'),
('3.2.0', 'MCPE 1.6 Support'),
('3.3.0', 'MCPE 1.7 Support'),
('3.4.0', ''),
('3.5.0', 'MCPE 1.8 Support'),
('3.6.0', 'MCPE 1.9 Support'),
('3.7.0', 'MCPE 1.10 Support'),
('3.8.0', 'MCPE 1.11 Support'),
('3.9.0', 'MCPE 1.12 Support'),
('3.10.0', 'MCPE 1.13 Support');
INSERT INTO `known_spoons` (`id`, `name`, `incompatible`) VALUES
(0, '5.0.0', true),
(1, '5.1.0', false),
(2, '5.2.0', false),
(3, '5.15.0', false);

INSERT INTO `spoon_prom` (`name`, `value`) VALUES
('poggit.pmapis.promoted', '3.10.0'),
('poggit.pmapis.promotedCompat', '3.10.0'),
('poggit.pmapis.latest', '3.10.0'),
('poggit.pmapis.latestCompat', '3.0.0');
('poggit.pmapis.promoted', '5.15.0'),
('poggit.pmapis.promotedCompat', '5.0.0'),
('poggit.pmapis.latest', '5.15.0'),
('poggit.pmapis.latestCompat', '5.0.0');

DELIMITER $$
CREATE FUNCTION `IncRsrDlCnt`(p_resourceId BIGINT UNSIGNED, p_ip VARCHAR(56)) RETURNS int
Expand Down
16 changes: 1 addition & 15 deletions js/admin.spoon.edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,19 @@ $(() => {
buttons: {
Submit: () => {
const name = $("#dialog-name").val();
const php = $("#dialog-php").val();
const incompatible = document.getElementById("dialog-incompatible").checked;
const indev = document.getElementById("dialog-indev").checked;
const supported = document.getElementById("dialog-supported").checked;
const desc = $("#dialog-description").val();

if(!confirm(`Confirm submit?
Name: ${name}
PHP: ${php}
Incompatible: ${incompatible ? "yes" : "no"}
Indev: ${indev ? "yes" : "no"}
Supported: ${supported ? "yes" : "no"}

Description:
${desc.split("\n").map(line => "- " + line.trim()).join("\n")}
`)) {
return;
}

ajax("spoon.add.ajax", {
data: {
name: name,
php: php,
incompatible: incompatible ? 1 : 0,
indev: indev ? 1 : 0,
supported: supported ? 1 : 0,
desc: desc,
incompatible: incompatible ? 1 : 0
},
success: (data) => {
alert(`Added API ${name} as #${data.id}`);
Expand Down
7 changes: 3 additions & 4 deletions js/admin.spoon.edit.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use poggit\admin\SpoonEditAjax;
use poggit\admin\SpoonEditModule;
use poggit\admin\RulesEditModule;
use poggit\admin\SpoonWebhookModule;
use poggit\ci\api\AbsoluteBuildIdModule;
use poggit\ci\api\BuildBadgeModule;
use poggit\ci\api\BuildDataRequestAjax;
Expand Down Expand Up @@ -193,6 +194,7 @@
register_module("spoon.edit", SpoonEditModule::class);
register_module("spoon.edit.ajax", SpoonEditAjax::class);
register_module("spoon.add.ajax", SpoonAddAjax::class);
register_module("spoon.add.webhook", SpoonWebhookModule::class);

foreach(["", ".json", ".yml", ".xml"] as $type) {
foreach($type === ".yml" ? [""] : ["", ".min"] as $min) {
Expand Down
22 changes: 9 additions & 13 deletions src/poggit/admin/SpoonAddAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,19 @@ protected function impl() {
return;
}

apcu_delete(PocketMineApi::KEY_VERSIONS);
apcu_delete(PocketMineApi::KEY_PROMOTED_COMPAT);

$name = $this->param("name");
$php = $this->param("php");
$incompatible = (int) $this->param("incompatible");
$indev = (int) $this->param("indev");
$supported = (int) $this->param("supported");
$desc = $this->param("desc");

$last = Mysql::query("SELECT name FROM known_spoons ORDER BY id DESC LIMIT 1")[0]["name"];
echo json_encode(["id" => self::addSpoon($name, $incompatible)]);
}

$id = Mysql::query("INSERT INTO known_spoons (name, php, incompatible, indev, supported) VALUES (?, ?, ?, ?, ?)", "ssiii", $name, $php, $incompatible, $indev, $supported)->insert_id;
public static function addSpoon(string $name, int $incompatible): int {
apcu_delete(PocketMineApi::KEY_VERSIONS);
apcu_delete(PocketMineApi::KEY_PROMOTED_COMPAT);

$last = Mysql::query("SELECT name FROM known_spoons ORDER BY id DESC LIMIT 1")[0]["name"];

Mysql::insertBulk("spoon_desc", ["api" => "s", "value" => "s"], array_filter(explode("\n", $desc)), function(string $line) use ($name): array {
return [$name, trim($line)];
});
$id = Mysql::query("INSERT INTO known_spoons (name, incompatible) VALUES (?, ?)", "si", $name, $incompatible)->insert_id;

Mysql::query("UPDATE spoon_prom SET value = ? WHERE name = ?", "ss", $name, PocketMineApi::KEY_PROMOTED);
Mysql::query("UPDATE spoon_prom SET value = ? WHERE name = ?", "ss", $name, PocketMineApi::KEY_LATEST);
Expand All @@ -68,6 +64,6 @@ protected function impl() {
Mysql::query("UPDATE release_spoons SET till = ? WHERE till = ?", "ss", $name, $last);
}

echo json_encode(["id" => $id]);
return $id;
}
}
4 changes: 1 addition & 3 deletions src/poggit/admin/SpoonEditAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ protected function impl() {
$field = $this->param("field");
$to = $this->param("to");

if($field === "php" || $field === "pharDefault") {
$to = $this->param("to");
} elseif($field === "incompatible" || $field === "indev" || $field === "supported") {
if($field === "incompatible") {
$to = (int) $this->param("to");
}else{
$this->errorBadRequest("Unknown field $field");
Expand Down
27 changes: 2 additions & 25 deletions src/poggit/admin/SpoonEditModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,16 @@ public function output() {
<?php foreach(array_reverse(PocketMineApi::$VERSIONS, true) as $version => $data) { ?>
<h3><?= Mbd::esq($version) ?> (#<?= $data["id"] ?>)</h3>
<div class="spoon-holder" data-spoon-id="<?= $data["id"] ?>">
<p>PHP: <span class="editable" data-field="php"><?= $data["php"][0] ?></span><br/>
<p>
Incompatible: <input type="checkbox" class="editable" data-field="incompatible"
<?= $data["incompatible"] ? "checked" : "" ?>/><br/>
Indev (deprecated): <input type="checkbox" class="editable" data-field="indev"
<?= $data["indev"] ? "checked" : "" ?>/><br/>
Supported: <input type="checkbox" class="editable" data-field="supported"
<?= $data["supported"] ? "checked" : "" ?>/><br/>
Phar link (default): <?php if($data["phar"]["default"] !== null) { ?>
<span class="editable" data-field="pharDefault"><?= $data["phar"]["default"] ?></span>
<?php } else { ?>
<span class="editable" data-field="pharDefault">null</span>
<?php } ?>
<?= $data["incompatible"] ? "checked" : "" ?>/>
</p>
<h4>Description</h4>
<ul>
<?php foreach($data["description"] as $line) { ?>
<li><?= htmlspecialchars($line) ?></li>
<?php } ?>
<?php if(empty($data["description"])) { ?>
(empty)
<?php } ?>
</ul>
</div>
<?php } ?>
</div>
<div id="add-version-dialog" style="display: none;" title="Add version">
<label for="dialog-name">Name</label> <input type="text" id="dialog-name"/><br/>
<label for="dialog-php">PHP</label> <input type="text" id="dialog-php" value="8.2"/><br/>
<label for="dialog-incompatible">Incompatible</label> <input type="checkbox" id="dialog-incompatible"/><br/>
<label for="dialog-indev">Indev</label> <input type="checkbox" id="dialog-indev"/><br/>
<label for="dialog-supported">Supported</label> <input type="checkbox" id="dialog-supported" checked/><br/>
<label for="dialog-description">Description (delimited by newlines)</label><br/>
<textarea id="dialog-description" cols="200" rows="10"></textarea>
</div>
<?php $this->bodyFooter() ?>
<?php Module::queueJs("admin.spoon.edit") ?>
Expand Down
91 changes: 91 additions & 0 deletions src/poggit/admin/SpoonWebhookModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

/*
* poggit
*
* Copyright (C) 2018 SOFe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace poggit\admin;

use poggit\Meta;
use poggit\module\Module;
use poggit\utils\PocketMineApi;

class SpoonWebhookModule extends Module {
public function output() {
// only allow POST method.
if($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo "Method Not Allowed";
return;
}

// verify the request token.
$raw_secret = Meta::getSecret("meta.pocketmineSecret");
$hash = $_SERVER["HTTP_X_HUB_SIGNATURE_256"];
$body = file_get_contents("php://input");
$expected = "sha256=" . hash_hmac("sha256", $body, $raw_secret);
if(!hash_equals($expected, $hash)) {
http_response_code(403);
echo "Forbidden";
return;
}

// decode payload.
$data = json_decode($body);
if($data === null || json_last_error() !== JSON_ERROR_NONE) {
http_response_code(400);
echo "Bad Request";
return;
}

// verify the payload is event we need.
if($data->action !== "published" || $data->release->draft !== false) {
http_response_code(200);
echo "Ignoring, not a published release.";
return;
}

// handle the payload.
Meta::getLog()->i("Handling spoon add webhook event from GitHub.");
$version = $data->release->tag_name;
$latest = PocketMineApi::$LATEST;

// Ignore any versions that has a prefix or suffix.
if(str_contains($version, "-") || str_contains($version, "+")) {
http_response_code(200);
echo "PocketMine API $version is ignored, suffix/prefix detected.";
return;
}

// If the version is already added or before latest, return.
if(version_compare($version, $latest, "<=")) {
http_response_code(200);
echo "PocketMine API $version is already added or before the latest version.";
return;
}

// Incompatible if the version is the next major.
$incompatible = (int)explode(".", $version)[0] > (int)explode(".", $latest)[0];
$id = SpoonAddAjax::addSpoon($version, $incompatible ? 1 : 0);

// Complete.
Meta::getLog()->i("PocketMine API $version has been added to Poggit.");
echo "PocketMine API $version has been added to Poggit.\nID: $id\nIncompatible: " . ($incompatible ? "true" : "false");
}
}
24 changes: 0 additions & 24 deletions src/poggit/help/PmApiListModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,6 @@ private function xmlResponse(bool $full, bool $min) {
$writer->startElement("api");
$writer->writeAttribute("name", $name);
$writer->writeAttribute("incompatible", $version["incompatible"] ? "true" : "false");
$writer->writeAttribute("indev", $version["indev"] ? "true" : "false");

$writer->startElement("description");
foreach($version["description"] as $summary) {
$writer->startElement("summary");
$writer->text($summary);
$writer->endElement();
}
$writer->endElement();

$writer->startElement("php");
foreach($version["php"] as $php) {
$writer->writeElement("version", $php);
}
$writer->endElement();

$writer->startElement("phar");
foreach($version["phar"] as $pharType => $url) {
if($url !== null) {
$writer->writeElement($pharType, $url);
}
}
$writer->endElement();

$writer->endElement();
}
$writer->endElement();
Expand Down
Loading