mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-03-07 15:16:40 +08:00
add function of renaming texture
This commit is contained in:
parent
eb3c2f01b3
commit
5f63daf075
@ -169,29 +169,37 @@ class SkinlibController extends BaseController
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (is_numeric(Utils::getValue('tid', $_POST))) {
|
||||
$result = Texture::find($_POST['tid']);
|
||||
\Utils::checkPost(['tid']);
|
||||
|
||||
if (!$result)
|
||||
throw new E('Unexistent texture.', 1);
|
||||
$result = Texture::find($_POST['tid']);
|
||||
|
||||
// check if file occupied
|
||||
if (Texture::where('hash', $result['hash'])->count() == 1)
|
||||
\Storage::remove("./textures/".$result['hash']);
|
||||
if (!$result)
|
||||
View::json('Unexistent texture.', 1);
|
||||
|
||||
$this->user->setScore($result->size, 'plus');
|
||||
if ($result->uploader != $this->user->uid && !$this->user->is_admin)
|
||||
View::json('你不是这个材质的上传者哦', 1);
|
||||
|
||||
if ($result->delete())
|
||||
View::json('材质已被成功删除', 0);
|
||||
// check if file occupied
|
||||
if (Texture::where('hash', $result['hash'])->count() == 1)
|
||||
\Storage::remove("./textures/".$result['hash']);
|
||||
|
||||
} else {
|
||||
throw new E('Invalid parameters.', 1);
|
||||
}
|
||||
$this->user->setScore($result->size, 'plus');
|
||||
|
||||
if ($result->delete())
|
||||
View::json('材质已被成功删除', 0);
|
||||
}
|
||||
|
||||
public function privacy($tid)
|
||||
{
|
||||
\Utils::checkPost(['tid']);
|
||||
|
||||
$t = Texture::find($tid);
|
||||
|
||||
if (!$t) View::json('Unexistent texture.', 1);
|
||||
|
||||
if ($t->uploader != $this->user->uid && !$this->user->is_admin)
|
||||
View::json('你不是这个材质的上传者哦', 1);
|
||||
|
||||
if ($t->setPrivacy(!$t->public)) {
|
||||
View::json([
|
||||
'errno' => 0,
|
||||
@ -201,40 +209,58 @@ class SkinlibController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
public function rename() {
|
||||
\Utils::checkPost(['tid', 'new_name']);
|
||||
\Validate::checkValidTextureName($_POST['new_name']);
|
||||
|
||||
$t = Texture::find($_POST['tid']);
|
||||
|
||||
if (!$t) View::json('材质不存在', 1);
|
||||
|
||||
if ($t->uploader != $this->user->uid && !$this->user->is_admin)
|
||||
View::json('你不是这个材质的上传者哦', 1);
|
||||
|
||||
$t->name = $_POST['new_name'];
|
||||
|
||||
if ($t->save()) {
|
||||
View::json('材质名称已被成功设置为'.$_POST['new_name'], 0);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkUpload($type)
|
||||
{
|
||||
\Validate::checkValidTextureName(Utils::getValue('name', $_POST));
|
||||
|
||||
if (!Utils::getValue('file', $_FILES))
|
||||
throw new E('你还没有选择任何文件哟', 1);
|
||||
View::json('你还没有选择任何文件哟', 1);
|
||||
|
||||
if (!isset($_POST['public']) || ($_POST['public'] != 0 && $_POST['public'] != 1))
|
||||
throw new E('Invalid parameters.', 1);
|
||||
View::json('Invalid parameters.', 1);
|
||||
|
||||
if ($_FILES['file']['type'] == "image/png" || $_FILES['file']['type'] == "image/x-png")
|
||||
{
|
||||
// if error occured while uploading file
|
||||
if ($_FILES['file']["error"] > 0)
|
||||
throw new E($_FILES['file']["error"], 1);
|
||||
View::json($_FILES['file']["error"], 1);
|
||||
|
||||
$size = getimagesize($_FILES['file']["tmp_name"]);
|
||||
$ratio = $size[0] / $size[1];
|
||||
|
||||
if ($type == "steve" || $type == "alex") {
|
||||
if ($ratio != 2 && $ratio != 1)
|
||||
throw new E("不是有效的皮肤文件(宽 {$size[0]},高 {$size[1]})", 1);
|
||||
View::json("不是有效的皮肤文件(宽 {$size[0]},高 {$size[1]})", 1);
|
||||
} elseif ($type == "cape") {
|
||||
if ($ratio != 2)
|
||||
throw new E("不是有效的披风文件(宽 {$size[0]},高 {$size[1]})", 1);
|
||||
View::json("不是有效的披风文件(宽 {$size[0]},高 {$size[1]})", 1);
|
||||
} else {
|
||||
throw new E('Invalid parameters.', 1);
|
||||
View::json('Invalid parameters.', 1);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (Utils::getValue('file', $_FILES)) {
|
||||
throw new E('文件格式不对哦', 1);
|
||||
View::json('文件格式不对哦', 1);
|
||||
} else {
|
||||
throw new E('No file selected.', 1);
|
||||
View::json('No file selected.', 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Exceptions\E;
|
||||
|
||||
class Validate
|
||||
{
|
||||
public static function checkValidPlayerName($player_name) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: prpr
|
||||
* @Date: 2016-07-19 10:46:38
|
||||
* @Last Modified by: printempw
|
||||
* @Last Modified time: 2016-07-23 15:23:19
|
||||
* @Last Modified time: 2016-07-24 15:38:22
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@ -193,6 +193,28 @@ function upload() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function changeTextureName(tid) {
|
||||
var new_name = prompt("请输入新的材质名称:");
|
||||
|
||||
if (!new_name) return;
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "./rename",
|
||||
dataType: "json",
|
||||
data: { 'tid': tid, 'new_name': new_name },
|
||||
success: function(json) {
|
||||
if (json.errno == 0) {
|
||||
$('#name').text(new_name);
|
||||
toastr.success(json.msg);
|
||||
} else {
|
||||
toastr.warning(json.msg);
|
||||
}
|
||||
},
|
||||
error: showAjaxError
|
||||
});
|
||||
}
|
||||
|
||||
function changePrivacy(tid) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
|
@ -77,16 +77,15 @@ Route::group(['prefix' => 'skinlib'], function()
|
||||
Route::get ('', 'SkinlibController@index');
|
||||
Route::all ('/info/{tid}', 'SkinlibController@info');
|
||||
Route::all ('/show', 'SkinlibController@show');
|
||||
Route::post('/save', 'SkinlibController@save');
|
||||
Route::all ('/search', 'SkinlibController@search');
|
||||
|
||||
Route::post('/privacy/{tid}', 'SkinlibController@privacy');
|
||||
|
||||
Route::group(['middleware' => 'App\Middlewares\CheckLoggedInMiddleware'], function()
|
||||
{
|
||||
Route::get ('/upload', 'SkinlibController@upload');
|
||||
Route::post('/upload', 'SkinlibController@handleUpload');
|
||||
|
||||
Route::post('/rename', 'SkinlibController@rename');
|
||||
Route::post('/privacy/{tid}', 'SkinlibController@privacy');
|
||||
Route::post('/delete', 'SkinlibController@delete');
|
||||
});
|
||||
});
|
||||
|
@ -59,7 +59,13 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>名称</td>
|
||||
<td>{{ $texture->name }}</td>
|
||||
<td id="name">{{ $texture->name }}
|
||||
@if (!is_null($user) && ($texture->uploader == $user->uid || $user->is_admin))
|
||||
<small>
|
||||
<a href="javascript:changeTextureName({{ $texture->tid }});">修改名称</a>
|
||||
</small>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>适用模型</td>
|
||||
@ -89,7 +95,8 @@
|
||||
</div><!-- /.box-body -->
|
||||
</div><!-- /.box -->
|
||||
|
||||
@if (!is_null($user) && $texture->uploader == $user->uid)
|
||||
@if (!is_null($user))
|
||||
@if ($texture->uploader == $user->uid)
|
||||
<div class="box box-danger">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">删除材质 / 设置隐私</h3>
|
||||
@ -124,6 +131,7 @@
|
||||
</div><!-- /.box-footer -->
|
||||
</div><!-- /.box -->
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user