Skip to content

Commit

Permalink
Merge branches 'dev' and 'master' of https://github.com/wisp-x/lsky-pro
Browse files Browse the repository at this point in the history
… into dev
  • Loading branch information
0xxb committed Nov 5, 2019
3 parents a1680c8 + 519bc2f + a36d31e commit a3ff28d
Show file tree
Hide file tree
Showing 173 changed files with 4,723 additions and 2,086 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
[![PHP](https://img.shields.io/badge/PHP->=5.6-orange.svg)](http://php.net)
[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/wisp-x/lsky-pro.svg)](https://github.com/wisp-x/lsky-pro)

> 下载稳定版请点击[这里](https://github.com/wisp-x/lsky-pro/releases),发现 bug 可发送邮件至邮箱:[email protected],或提交 [issues](https://github.com/wisp-x/lsky-pro/issues),确认 bug 后我会及时修复,谢谢!
> 下载稳定版请点击[这里](https://github.com/wisp-x/lsky-pro/releases),发现 bug 可发送邮件至邮箱:[email protected],或提交 [issues](https://github.com/wisp-x/lsky-pro/issues)
> 下载速度慢的可以移步 Coding https://dev.tencent.com/u/wispx/p/lsky-pro-releases/git
![homepage.png](./public/static/app/images/demo/1.png)
![homepage.png](./public/static/app/images/demo/2.png)
Expand Down
2 changes: 1 addition & 1 deletion application/api/controller/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function initialize()
$this->response('API is not open yet.', [], 500);
}

$this->token = $this->request->header('token');
$this->token = $this->request->header('token', $this->param('token'));
$this->auth($this->token);

$format = $this->param('format');
Expand Down
67 changes: 67 additions & 0 deletions application/api/controller/Image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Created by WispX.
* User: WispX <[email protected]>
* Date: 2019/10/31
* Time: 11:10 上午
* Link: https://github.com/wisp-x
*/

namespace app\api\controller;

use app\common\model\Images;
use app\index\controller\User;

class Image extends Base
{
private $model;

public function initialize()
{
parent::initialize();
$this->model = new Images();
$this->model = $this->model->where('user_id', $this->user->id)->field(['user_id', 'folder_id'], true);
}

public function find()
{
$id = $this->param('id');
$image = $this->model->where(['id' => $id])->find();
$this->response('success', $this->parseData($image));
}

public function items()
{
$page = $this->param('page', 1);
$rows = $this->param('rows', 20);
$images = $this->model->paginate(null, false, [
'page' => $page,
'list_rows' => $rows,
])->each(function ($item) {
$item = $this->parseData($item);
unset($item['create_time']);
return $item;
});
$this->response('success', $images);
}

public function delete()
{
$user = new User();
$data = str_replace('', ',', $this->param('id'));
if (strpos($data, ',') !== false) {
$data = explode(',', $data);
}
if ($user->deleteImages($data)) {
return $this->response('删除成功!');
}
return $this->response('删除失败!', [], 500);
}

private function parseData($data)
{
$data['upload_time'] = $data->getData('create_time');
$data['upload_date'] = $data->create_time;
return $data;
}
}
2 changes: 2 additions & 0 deletions application/common/model/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Images extends Model

protected $insert = ['ip'];

protected $append = ['url'];

public function getUrlAttr($url, $data)
{
// 图片链接
Expand Down
82 changes: 40 additions & 42 deletions application/index/controller/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,55 +47,53 @@ public function images($keyword = '', $folderId = 0, $limit = 60)

public function deleteImages($deleteId = null)
{
if ($this->request->isPost()) {
Db::startTrans();
try {
$id = $deleteId ? $deleteId : $this->request->post('id');
$deletes = []; // 需要删除的文件
if (is_array($id)) {
$images = Images::all($id);
foreach ($images as &$value) {
$deletes[$value->strategy][] = $value->pathname;
$value->delete();
unset($value);
}
} else {
$image = Images::get($id);
if (!$image) {
throw new Exception('没有找到该图片数据');
}
$deletes[$image->strategy][] = $image->pathname;
$image->delete();
Db::startTrans();
try {
$id = $deleteId ? $deleteId : $this->request->post('id');
$deletes = []; // 需要删除的文件
if (is_array($id)) {
$images = Images::all($id);
foreach ($images as &$value) {
$deletes[$value->strategy][] = $value->pathname;
$value->delete();
unset($value);
}
} else {
$image = Images::get($id);
if (!$image) {
throw new Exception('没有找到该图片数据');
}
$deletes[$image->strategy][] = $image->pathname;
$image->delete();
}
// 是否开启软删除(开启了只删除记录,不删除文件)
if (!$this->config['soft_delete']) {
$strategy = [];
// 实例化所有储存策略驱动
$strategyAll = array_keys(Config::pull('strategy'));
foreach ($strategyAll as $value) {
// 获取储存策略驱动
$strategy[$value] = $this->getStrategyInstance($value);
}
// 是否开启软删除(开启了只删除记录,不删除文件)
if (!$this->config['soft_delete']) {
$strategy = [];
// 实例化所有储存策略驱动
$strategyAll = array_keys(Config::pull('strategy'));
foreach ($strategyAll as $value) {
// 获取储存策略驱动
$strategy[$value] = $this->getStrategyInstance($value);
}

foreach ($deletes as $key => $val) {
if (1 === count($val)) {
if (!$strategy[$key]->delete(isset($val[0]) ? $val[0] : null)) {
throw new Exception('删除失败');
}
} else {
if (!$strategy[$key]->deletes($val)) {
throw new Exception('批量删除失败');
}
foreach ($deletes as $key => $val) {
if (1 === count($val)) {
if (!$strategy[$key]->delete(isset($val[0]) ? $val[0] : null)) {
throw new Exception('删除失败');
}
} else {
if (!$strategy[$key]->deletes($val)) {
throw new Exception('批量删除失败');
}
}
}
Db::commit();
} catch (Exception $e) {
Db::rollback();
return $deleteId ? false : $this->error($e->getMessage());
}
return $deleteId ? true : $this->success('删除成功');
Db::commit();
} catch (Exception $e) {
Db::rollback();
return $deleteId ? false : $this->error($e->getMessage());
}
return $deleteId ? true : $this->success('删除成功');
}

public function createFolder()
Expand Down
17 changes: 9 additions & 8 deletions application/index/controller/admin/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use app\common\model\Config;
use think\Db;
use app\common\model\Images;
use think\Exception;

/**
Expand Down Expand Up @@ -50,14 +51,14 @@ public function index()

public function console()
{
$storage = Db::name('images')->sum('size');
$imagesCount = Db::name('images')->count();
$suspiciousImagesCount = Db::name('images')->where('suspicious', 1)->count();
$users_count = Db::name('users')->count();
$today = Db::name('images')->whereTime('create_time', 'today')->count();
$yesterday = Db::name('images')->whereTime('create_time', 'yesterday')->count();
$month = Db::name('images')->whereTime('create_time', 'month')->count();
$tourists = Db::name('images')->where('user_id', 0)->count();
$storage = Images::sum('size');
$imagesCount = Images::count();
$suspiciousImagesCount = Images::where('suspicious', 1)->count();
$users_count = \app\common\model\Users::count();
$today = Images::whereTime('create_time', 'today')->count();
$yesterday = Images::whereTime('create_time', 'yesterday')->count();
$month = Images::whereTime('create_time', 'month')->count();
$tourists = Images::where('user_id', 0)->count();

$this->assign([
'storage' => format_size($storage, true), // 占用储存
Expand Down
1 change: 1 addition & 0 deletions application/index/controller/admin/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Update extends Base
{
public function index()
{
die;
// https://dev.tencent.com/u/wispx/p/lsky-pro-releases/git/raw/master/releases/lsky-pro-1.5.4.zip
echo <<<EOT
<style>
Expand Down
4 changes: 3 additions & 1 deletion application/index/view/admin/system/console.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<div class="mdui-col item mdui-m-b-2">
<div class="mdui-color-blue mdui-text-center mdui-text-color-white mdui-p-a-2 mdui-shadow-4 mdui-hoverable">
<p><i class="mdui-icon material-icons">&#xe623;</i> 占用储存</p>
<span class="mdui-text-color-amber">{$storage[0]} <small class="mdui-text-color-white">{$storage[1]}</small></span>
<span class="mdui-text-color-amber">{$storage[0]}
<small class="mdui-text-color-white">{if $storage[0]}{$storage[1]}{else/}Kb{/if}</small>
</span>
</div>
</div>
<div class="mdui-col item mdui-m-b-2">
Expand Down
4 changes: 2 additions & 2 deletions application/index/view/auth/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{block name="title"}登录 - {$config.site_name}{/block}

{block name="css"}
<link href="/static/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
{/block}

{block name="main"}
Expand Down Expand Up @@ -42,5 +42,5 @@
{/block}

{block name="js"}
<script src="/static/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="/static/bootstrap/4.3.1/js/bootstrap.min.js"></script>
{/block}
4 changes: 2 additions & 2 deletions application/index/view/auth/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{block name="title"}注册 - {$config.site_name}{/block}

{block name="css"}
<link href="/static/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
{/block}

{block name="main"}
Expand Down Expand Up @@ -67,5 +67,5 @@ <h3>站点已关闭注册</h3>
{/block}

{block name="js"}
<script src="/static/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="/static/bootstrap/4.3.1/js/bootstrap.min.js"></script>
{/block}
Loading

0 comments on commit a3ff28d

Please sign in to comment.