mirror of
https://github.com/godotengine/godot-asset-library.git
synced 2026-01-05 18:10:50 +03:00
Add a "Custom" download provider, which can be used by moderators only
It would allow us to link demos in the asset library. Refs godotengine/godot-demo-projects#33
This commit is contained in:
@@ -49,6 +49,11 @@ class Utils
|
||||
}
|
||||
$warning .= "Since cgit might be self-hosted, we can't be sure that \"$repo_url\" is a valid cgit URL. $light_warning_suffix\n";
|
||||
return "$repo_url/snapshot/$commit.zip";
|
||||
case 'Custom':
|
||||
if (sizeof(preg_grep('/^https?:\/\/.+?.zip$/', [$commit])) == 0) {
|
||||
$warning .= "\"$commit\" doesn't look correct; it should be similar to \"http<s>://<url>.zip\". $warning_suffix\n";
|
||||
}
|
||||
return "$commit";
|
||||
default:
|
||||
return "$repo_url/$commit.zip"; // Obviously incorrect, but we would like to have some default case...
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ return $constants = [
|
||||
'admin' => 100,
|
||||
]),
|
||||
'download_provider' => double_map([
|
||||
'Custom' => -1,
|
||||
'GitHub' => 0,
|
||||
'GitLab' => 1,
|
||||
'BitBucket' => 2,
|
||||
|
||||
@@ -76,10 +76,19 @@ function _insert_asset_edit_fields($c, $error, &$response, $query, $body, $requi
|
||||
if (isset($c->constants['download_provider'][$body['download_provider']])) {
|
||||
$body['download_provider'] = (string) ((int) $c->constants['download_provider'][$body['download_provider']]);
|
||||
} else {
|
||||
$body['download_provider'] = 0;
|
||||
$body['download_provider'] = '0';
|
||||
}
|
||||
|
||||
if ($body['download_provider'] == $c->constants['download_provider']['Custom'] && ($bare_asset === null || $bare_asset['download_provider'] != $body['download_provider'])) {
|
||||
$error = $c->utils->ensureLoggedIn($error, $response, $body, $user);
|
||||
$error = $c->utils->errorResponseIfNotUserHasLevel($error, $response, $user, 'moderator', 'You are not authorized to use the Custom provider');
|
||||
if ($error) {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($body['issues_url'])) {
|
||||
$default_issues_url = null;
|
||||
if (isset($body['browse_url']) && isset($body['download_provider'])) {
|
||||
@@ -489,25 +498,18 @@ $get_edit = function ($request, $response, $args) {
|
||||
}
|
||||
}
|
||||
|
||||
if (($asset_edit['download_provider'] ?: $asset_edit['original']['download_provider']) != 'Custom') {
|
||||
if ($asset_edit['download_commit'] == 'master') {
|
||||
$warning .= "Giving 'master' (or any other branch name) as the commit to be downloaded is not recommended, since it would invalidate the asset when you push a new version (since we ensure the version is kept the same via a sha256 hash of the zip). You can try using tags instead.\n";
|
||||
}
|
||||
if (sizeof(preg_grep('/\/|\\|\:|^\.|\ |\^|\~|\?|\*|\[|^\@$|\@\{/', [$asset_edit['download_commit']])) != 0) {
|
||||
$warning .= "The inputted download commit is not a valid git ref, please ensure you aren't giving a full URL. (If your tag includes '/' in its name, consider escaping it as '%2F')\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($warning != null) {
|
||||
$asset_edit['warning'] = $warning;
|
||||
}
|
||||
if ($asset_edit['download_commit'] == 'master') {
|
||||
if (isset($asset_edit['warning'])) {
|
||||
$asset_edit['warning'] .= "\n\n";
|
||||
} else {
|
||||
$asset_edit['warning'] = '';
|
||||
}
|
||||
$asset_edit['warning'] .= "Giving 'master' (or any other branch name) as the commit to be downloaded is not recommended, since it would invalidate the asset when you push a new version (since we ensure the version is kept the same via a sha256 hash of the zip). You can try using tags instead.";
|
||||
}
|
||||
if (sizeof(preg_grep('/\/|\\|\:|^\.|\ |\^|\~|\?|\*|\[|^\@$|\@\{/', [$asset_edit['download_commit']])) != 0) {
|
||||
if (isset($asset_edit['warning'])) {
|
||||
$asset_edit['warning'] .= "\n\n";
|
||||
} else {
|
||||
$asset_edit['warning'] = '';
|
||||
}
|
||||
$asset_edit['warning'] .= "The inputted download commit is not a valid git ref, please ensure you aren't giving a full URL. (If your tag includes '/' in its name, consider escaping it as '%2F')";
|
||||
}
|
||||
|
||||
|
||||
return $response->withJson($asset_edit, 200);
|
||||
|
||||
@@ -68,11 +68,16 @@ $_asset_values = array_merge([
|
||||
<label class="col-md-4 control-label required_mark" for="download_provider">Repository host</label>
|
||||
<div class="col-md-5">
|
||||
<select id="download_provider" name="download_provider" class="form-control">
|
||||
<?php foreach($constants['download_provider'] as $id => $name) if(is_int($id)) { ?>
|
||||
<?php foreach($constants['download_provider'] as $id => $name) if(is_int($id) && $id >= 0) { ?>
|
||||
<option value="<?php echo esc($name) ?>" <?php if($name == $_asset_values['download_provider']) echo 'selected=""'; ?>>
|
||||
<?php echo esc($name) ?>
|
||||
</option>
|
||||
<?php } ?>
|
||||
<?php if((isset($user) && ($user['type'] >= $constants['user_type']['moderator'])) || "Custom" == $_asset_values['download_provider']) { ?>
|
||||
<option value="Custom" <?php if("Custom" == $_asset_values['download_provider']) echo 'selected=""'; ?>>
|
||||
Custom (Moderator-only)
|
||||
</option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<span class="help-block">We need to know where your repository is hosted in order to compute the final download URL. If your Git repository provider is missing, you might like to <a href="https://github.com/godotengine/asset-library/issues">open an issue</a> about it.</span>
|
||||
</div>
|
||||
@@ -83,6 +88,9 @@ $_asset_values = array_merge([
|
||||
<div class="col-md-5">
|
||||
<input id="browse" name="browse_url" type="text" placeholder="Repository URL" class="form-control input-md" required="" value="<?php echo esc($_asset_values['browse_url']) ?>">
|
||||
<span class="help-block">The url to browse the asset's files (webpage). Should be similar to <code>https://github.com/<user>/<project></code> (Might be different depending on your "provider")</span>
|
||||
<?php if(isset($user) && ($user['type'] >= $constants['user_type']['moderator'])) { ?>
|
||||
<span class="help-block">When using the Custom provider, this is used for browsing only.</span>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -99,6 +107,9 @@ $_asset_values = array_merge([
|
||||
<div class="col-md-5">
|
||||
<input id="commit" name="download_commit" type="text" placeholder="Download Commit/tag" class="form-control input-md" required="" value="<?php echo esc($_asset_values['download_commit']) ?>">
|
||||
<span class="help-block">The commit or tag to download the asset. Should be similar to <code>b1d3172f89b86e52465a74f63a74ac84c491d3e1</code> or <code>v1.0</code>. The final download url would be computed from this.</span>
|
||||
<?php if(isset($user) && ($user['type'] >= $constants['user_type']['moderator'])) { ?>
|
||||
<span class="help-block">When using the Custom provider, this is the download URL.</span>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user