mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-20 00:30:50 +08:00
tag add more customized options + NexusDB::rememter()
This commit is contained in:
@@ -7,10 +7,30 @@
|
||||
<el-input v-model="formData.name" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="Color" prop="color">
|
||||
<el-form-item label="Background color" prop="color">
|
||||
<el-input v-model="formData.color" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="Font color" prop="font_color">
|
||||
<el-input v-model="formData.font_color" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="Font size" prop="font_size">
|
||||
<el-input v-model="formData.font_size" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="Padding" prop="padding">
|
||||
<el-input v-model="formData.padding" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="Margin" prop="margin">
|
||||
<el-input v-model="formData.margin" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="Border radius" prop="border_radius">
|
||||
<el-input v-model="formData.border_radius" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="Priority" prop="priority">
|
||||
<el-input v-model="formData.priority" placeholder="The higher the value, the higher the ranking"></el-input>
|
||||
</el-form-item>
|
||||
@@ -47,7 +67,12 @@ export default {
|
||||
formData: {
|
||||
color: '',
|
||||
name: '',
|
||||
priority: ''
|
||||
priority: '',
|
||||
font_color: '#ffffff',
|
||||
font_size: '12px',
|
||||
margin: 0,
|
||||
padding: 0,
|
||||
border_radius: 0,
|
||||
},
|
||||
rules: {
|
||||
color: [
|
||||
@@ -64,6 +89,11 @@ export default {
|
||||
state.formData.name = res.data.name
|
||||
state.formData.color = res.data.color
|
||||
state.formData.priority = res.data.priority
|
||||
state.formData.font_color = res.data.font_color
|
||||
state.formData.font_size = res.data.font_size
|
||||
state.formData.margin = res.data.margin
|
||||
state.formData.padding = res.data.padding
|
||||
state.formData.border_radius = res.data.border_radius
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -33,7 +33,37 @@
|
||||
|
||||
<el-table-column
|
||||
prop="color"
|
||||
label="Color"
|
||||
label="Background color"
|
||||
>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="font_color"
|
||||
label="Font color"
|
||||
>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="font_size"
|
||||
label="Font size"
|
||||
>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="margin"
|
||||
label="Margin"
|
||||
>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="padding"
|
||||
label="Padding"
|
||||
>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="border_radius"
|
||||
label="Border radius"
|
||||
>
|
||||
</el-table-column>
|
||||
|
||||
@@ -48,12 +78,6 @@
|
||||
label="Updated at"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="created_at"
|
||||
label="Created at"
|
||||
></el-table-column>
|
||||
|
||||
|
||||
<el-table-column
|
||||
label="Action"
|
||||
width="120"
|
||||
|
||||
@@ -46,10 +46,7 @@ class TagController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate($this->getRules());
|
||||
$data = $request->all();
|
||||
if (isset($data['priority'])) {
|
||||
$data['priority'] = intval($data['priority']);
|
||||
}
|
||||
$data = array_filter($request->all());
|
||||
$result = $this->repository->store($data);
|
||||
$resource = new TagResource($result);
|
||||
return $this->success($resource);
|
||||
|
||||
@@ -18,6 +18,11 @@ class TagResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'color' => $this->color,
|
||||
'font_color' => $this->font_color,
|
||||
'font_size' => $this->font_size,
|
||||
'padding' => $this->padding,
|
||||
'margin' => $this->margin,
|
||||
'border_radius' => $this->border_radius,
|
||||
'priority' => $this->priority,
|
||||
'created_at' => format_datetime($this->created_at),
|
||||
'updated_at' => format_datetime($this->updated_at),
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class Setting extends NexusModel
|
||||
{
|
||||
@@ -10,9 +12,9 @@ class Setting extends NexusModel
|
||||
|
||||
public static function get($name = null)
|
||||
{
|
||||
static $settings;
|
||||
if (is_null($settings)) {
|
||||
$settings = NexusDB::remember("nexus_settings_in_laravel", 10, function () {
|
||||
$rows = self::query()->get(['name', 'value']);
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
$value = $row->value;
|
||||
if (!is_null($value)) {
|
||||
@@ -21,9 +23,10 @@ class Setting extends NexusModel
|
||||
$value = $arr;
|
||||
}
|
||||
}
|
||||
Arr::set($settings, $row->name, $value);
|
||||
Arr::set($result, $row->name, $value);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
});
|
||||
if (is_null($name)) {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ class Tag extends NexusModel
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = [
|
||||
'id', 'name', 'color', 'priority', 'created_at', 'updated_at'
|
||||
'id', 'name', 'color', 'priority', 'created_at', 'updated_at', 'font_size', 'font_color', 'padding', 'margin', 'border_radius'
|
||||
];
|
||||
|
||||
const DEFAULTS = [
|
||||
|
||||
@@ -67,7 +67,10 @@ class TagRepository extends BaseRepository
|
||||
foreach ($renderIdArr as $tagId) {
|
||||
$value = $tagKeyById->get($tagId);
|
||||
if ($value) {
|
||||
$item = "<span style=\"background-color:{$value->color};color:white;border-radius:15%\">{$value->name}</span> ";
|
||||
$item = sprintf(
|
||||
"<span style=\"background-color:%s;color:%s;border-radius:%s;font-size:%s;margin:%s;padding:%s\">%s</span>",
|
||||
$value->color, $value->font_color, $value->border_radius, $value->font_size, $value->margin, $value->padding, $value->name
|
||||
);
|
||||
if ($withFilterLink) {
|
||||
$html .= sprintf('<a href="torrents.php?tag_id=%s">%s</a>', $tagId, $item);
|
||||
} else {
|
||||
|
||||
@@ -661,8 +661,17 @@ class TrackerRepository extends BaseRepository
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Torrent $torrent
|
||||
* @param $queries
|
||||
*/
|
||||
private function updateTorrent(Torrent $torrent, $queries)
|
||||
{
|
||||
if (empty($queries['event'])) {
|
||||
do_log("no event, return", 'debug');
|
||||
return;
|
||||
}
|
||||
$torrent->seeders = Peer::query()
|
||||
->where('torrent', $torrent->id)
|
||||
->where('to_go', '=',0)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddMarginPaddingToTagsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tags', function (Blueprint $table) {
|
||||
$table->string('padding')->default(0);
|
||||
$table->string('margin')->default('0 4px 0 0');
|
||||
$table->string('border_radius')->default(0);
|
||||
$table->string('font_size')->default('12px');
|
||||
$table->string('font_color')->default('#ffffff');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('tags', function (Blueprint $table) {
|
||||
$table->dropColumn(['padding', 'margin', 'font_size', 'font_color', 'border_radius']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ if (!file_exists($rootpath . '.env')) {
|
||||
require $rootpath . 'nexus/Database/helpers.php';
|
||||
require $rootpath . 'classes/class_cache_redis.php';
|
||||
require $rootpath . 'include/eloquent.php';
|
||||
require $rootpath . 'include/config.php';
|
||||
|
||||
ini_set('date.timezone', nexus_config('nexus.timezone'));
|
||||
ini_set('error_reporting', E_ALL);
|
||||
@@ -24,6 +23,8 @@ if (!in_array(nexus()->getScript(), ['announce', 'scrape'])) {
|
||||
}
|
||||
$Cache = new class_cache_redis(); //Load the caching class
|
||||
$Cache->setLanguageFolderArray(get_langfolder_list());
|
||||
require $rootpath . 'include/config.php';
|
||||
|
||||
define('TIMENOW', time());
|
||||
$USERUPDATESET = array();
|
||||
$query_name=array();
|
||||
|
||||
@@ -282,19 +282,23 @@ function get_setting($name = null)
|
||||
{
|
||||
static $settings;
|
||||
if (is_null($settings)) {
|
||||
//get all settings from database
|
||||
$sql = "select name, value from settings";
|
||||
$result = sql_query($sql);
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$value = $row['value'];
|
||||
if (!is_null($value)) {
|
||||
$arr = json_decode($value, true);
|
||||
if (is_array($arr)) {
|
||||
$value = $arr;
|
||||
$settings = \Nexus\Database\NexusDB::remember("nexus_settings_in_nexus" . __METHOD__, 10, function () {
|
||||
//get all settings from database
|
||||
$sql = "select name, value from settings";
|
||||
$result = sql_query($sql);
|
||||
$final = [];
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$value = $row['value'];
|
||||
if (!is_null($value)) {
|
||||
$arr = json_decode($value, true);
|
||||
if (is_array($arr)) {
|
||||
$value = $arr;
|
||||
}
|
||||
}
|
||||
arr_set($final, $row['name'], $value);
|
||||
}
|
||||
arr_set($settings, $row['name'], $value);
|
||||
}
|
||||
return $final;
|
||||
});
|
||||
}
|
||||
if (is_null($name)) {
|
||||
return $settings;
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Nexus\Database;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class NexusDB
|
||||
@@ -267,6 +268,24 @@ class NexusDB
|
||||
return DB::transaction($callback, $attempts);
|
||||
}
|
||||
|
||||
public static function remember($key, $ttl, \Closure $callback)
|
||||
{
|
||||
if (IN_NEXUS) {
|
||||
global $Cache;
|
||||
$result = $Cache->get_value($key);
|
||||
if ($result === false) {
|
||||
do_log("cache miss, get from database.");
|
||||
$result = $callback();
|
||||
$Cache->cache_value($key, $result, $ttl);
|
||||
} else {
|
||||
do_log("cache hit.");
|
||||
}
|
||||
return $result;
|
||||
} else {
|
||||
return Cache::remember($key, $ttl, $callback);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getMysqlColumnInfo($table, $column)
|
||||
{
|
||||
static $driver;
|
||||
|
||||
@@ -164,7 +164,7 @@ else{
|
||||
if ($newnumpeers > $rsize)
|
||||
$limit = " ORDER BY RAND() LIMIT $rsize";
|
||||
else $limit = "";
|
||||
$announce_wait = 30;
|
||||
$announce_wait = \App\Repositories\TrackerRepository::MIN_ANNOUNCE_WAIT_SECOND;
|
||||
|
||||
$fields = "seeder, peer_id, ip, port, uploaded, downloaded, (".TIMENOW." - UNIX_TIMESTAMP(last_action)) AS announcetime, UNIX_TIMESTAMP(prev_action) AS prevts";
|
||||
//$peerlistsql = "SELECT ".$fields." FROM peers WHERE torrent = ".$torrentid." AND connectable = 'yes' ".$only_leech_query.$limit;
|
||||
@@ -199,7 +199,7 @@ $params = $_GET;
|
||||
unset($params['key']);
|
||||
$lockKey = md5(http_build_query($params));
|
||||
$redis = $Cache->getRedis();
|
||||
if (!$redis->set($lockKey, TIMENOW, ['nx', 'ex' => $announce_wait])) {
|
||||
if (!$redis->set($lockKey, TIMENOW, ['nx', 'ex' => 5])) {
|
||||
do_log('ReAnnounce');
|
||||
benc_resp($rep_dict);
|
||||
exit();
|
||||
|
||||
Reference in New Issue
Block a user