Jelajahi Sumber

更新内容

moshaorui 2 bulan lalu
induk
melakukan
6d50923837

+ 2 - 0
app/Http/Controllers/AuthController.php

@@ -35,6 +35,8 @@ class AuthController extends BaseController
         }
         }
 
 
         if (Auth::guard('web')->attempt($credentials, false)) {
         if (Auth::guard('web')->attempt($credentials, false)) {
+
+
             // 登录成功
             // 登录成功
             return ['status'=>'success','message'=>'登录成功'];
             return ['status'=>'success','message'=>'登录成功'];
         }
         }

+ 4 - 0
app/Http/Controllers/Controller.php

@@ -6,6 +6,7 @@ use App\Models\SiteAlbumFolder;
 use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Routing\Controller as BaseController;
 use Illuminate\Routing\Controller as BaseController;
+use Illuminate\Support\Facades\Auth;
 
 
 class Controller extends BaseController
 class Controller extends BaseController
 {
 {
@@ -42,5 +43,8 @@ class Controller extends BaseController
         //dd($result);
         //dd($result);
         $this->foldersTree = $result;
         $this->foldersTree = $result;
 
 
+
+
+
     }
     }
 }
 }

+ 50 - 0
app/Http/Controllers/HomeController.php

@@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Support\Facades\Validator;
 use ZipArchive;
 use ZipArchive;
 use Illuminate\Support\Facades\Session;
 use Illuminate\Support\Facades\Session;
+use Illuminate\Support\Str;
 
 
 class HomeController extends Controller
 class HomeController extends Controller
 {
 {
@@ -28,6 +29,7 @@ class HomeController extends Controller
 
 
     public function main(Request $request)
     public function main(Request $request)
     {
     {
+
         return view('main',['foldersTree' => $this->foldersTree]);
         return view('main',['foldersTree' => $this->foldersTree]);
     }
     }
 
 
@@ -199,6 +201,54 @@ class HomeController extends Controller
         }
         }
     }
     }
 
 
+
+
+
+    public function downloadImage(Request $request)
+    {
+        Session::put('downloadAllStatus', '1');
+        // Get the URL from the request parameter
+        $imageUrl = $request->input('url');
+
+        // Validate the URL
+        if (filter_var($imageUrl, FILTER_VALIDATE_URL) === false) {
+            return response()->json(['error' => 'Invalid URL'], 400);
+        }
+
+        try {
+            // Initialize cURL
+            $ch = curl_init($imageUrl);
+
+            // Set cURL options
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Allow HTTPS (disable SSL peer verification)
+            curl_setopt($ch, CURLOPT_TIMEOUT, 30); // Set timeout to prevent hanging
+
+            // Execute cURL request
+            $imageContent = curl_exec($ch);
+            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+            if ($httpCode !== 200) {
+                return response()->json(['error' => 'Failed to download image'], 500);
+            }
+
+            curl_close($ch);
+
+            // Generate a random filename
+            $fileName = Str::random(32) . '.jpg';
+
+            Session::put('downloadAllStatus', '0');
+            // Return the image as a download
+            return response($imageContent)
+                ->header('Content-Type', 'image/jpeg')
+                ->header('Content-Disposition', 'attachment; filename="' . $fileName . '"');
+        } catch (\Exception $e) {
+            Session::put('downloadAllStatus', '0');
+            return response()->json(['error' => 'Error downloading image: ' . $e->getMessage()], 500);
+        }
+    }
+
+
     public function getDownloadAllStatus()
     public function getDownloadAllStatus()
     {
     {
         $status = Session::get('downloadAllStatus',0);
         $status = Session::get('downloadAllStatus',0);

+ 1 - 0
app/Http/Kernel.php

@@ -36,6 +36,7 @@ class Kernel extends HttpKernel
             \Illuminate\View\Middleware\ShareErrorsFromSession::class,
             \Illuminate\View\Middleware\ShareErrorsFromSession::class,
             \App\Http\Middleware\VerifyCsrfToken::class,
             \App\Http\Middleware\VerifyCsrfToken::class,
             \Illuminate\Routing\Middleware\SubstituteBindings::class,
             \Illuminate\Routing\Middleware\SubstituteBindings::class,
+            \App\Http\Middleware\Auth::class,
         ],
         ],
 
 
         'api' => [
         'api' => [

+ 17 - 0
app/Http/Middleware/Auth.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+
+class Auth
+{
+    public function handle($request, Closure $next)
+    {
+        if (\Illuminate\Support\Facades\Auth::guard('web')->check() == false) {
+            die('未登录');
+        }
+        //否则继续处理当前请求
+        return $next($request);
+    }
+}

+ 14 - 1
public/static/css/main.css

@@ -1904,7 +1904,7 @@ a {
 table.album_table {
 table.album_table {
   width: 100%;
   width: 100%;
   border-collapse: collapse;
   border-collapse: collapse;
-  margin: 20px 0;
+  margin: 20px 0px 30px;
 }
 }
 table.album_table th, table.album_table td {
 table.album_table th, table.album_table td {
   padding: 12px;
   padding: 12px;
@@ -2065,6 +2065,19 @@ video {
     visibility: hidden;
     visibility: hidden;
 }
 }
 
 
+.fullscreen-btn-download {
+    position: absolute;
+    bottom: 35px;
+    right: 20px;
+    font-size: 24px;
+    cursor: pointer;
+    color: #fff;
+    background-color: rgba(0, 0, 0, 0.5);
+    padding: 10px;
+    border-radius: 50%;
+    top: 90%;
+}
+
 
 
 
 
 
 

+ 96 - 75
public/static/js/script.js

@@ -1,4 +1,5 @@
 $(document).ready(function() {
 $(document).ready(function() {
+    var loadIndex = null;
 
 
 	new WOW({
 	new WOW({
 		mobile: false,
 		mobile: false,
@@ -243,70 +244,104 @@ $(document).ready(function() {
 	});
 	});
 
 
 
 
-	// 创建全屏遮罩层
-	$('.album-thumb-detail').on('click', function (event) {
-		// 如果点击的是 download-icon,阻止后续代码执行
-		if ($(event.target).closest('.download-icon').length) {
-			return;
-		}
+    var checkDownloadStatus = function() {
+        var intervalId = setInterval(function() {
+            $.ajax({
+                url: '/download-status',
+                method: 'GET',
+                dataType: 'json',
+                success: function(response) {
+                    if (response.status == 0) {
+                        clearInterval(intervalId);
+                        layer.close(loadIndex); // 关闭加载层
+                    }
+                }
+            });
+        }, 1000); // 每秒请求一次
+    }
 
 
-		// 获取当前点击的 .album-thumb-detail 的父级 .grid-album 元素
-		var $parentAlbum = $(this).closest('.grid-album');
+    // 放大图片 start
+// 创建全屏遮罩层
+    $('.album-thumb-detail').on('click', function (event) {
+        // 如果点击的是 download-icon,阻止后续代码执行
+        if ($(event.target).closest('.download-icon').length) {
+            return;
+        }
 
 
-		// 获取当前父级下所有 .album-thumb-detail img 的 src
-		var imageSrcArray = [];
-		$parentAlbum.find('.album-thumb-detail img').each(function () {
-            src = $(this).attr('data-src')
-           // newSrc = src.split('?')[0];
-			imageSrcArray.push(src);
-		});
+        // 获取当前点击的 .album-thumb-detail 的父级 .grid-album 元素
+        var $parentAlbum = $(this).closest('.grid-album');
 
 
-		// 获取当前点击图片在数组中的索引
-		var $albumThumbs = $parentAlbum.find('.album-thumb-detail');
-		var currentImageIndex = $albumThumbs.index(this);
-		// console.log(currentImageIndex);
-
-		const $fullscreenMask = $('<div>').addClass('fullscreen-mask');
-		const $fullscreenImg = $('<img>').attr('src', imageSrcArray[currentImageIndex]);
-		const $btnLeft = $('<div>').addClass('fullscreen-btn fullscreen-btn-left').html('&lt;');
-		const $btnRight = $('<div>').addClass('fullscreen-btn fullscreen-btn-right').html('&gt;');
-
-		$fullscreenMask.append($fullscreenImg, $btnLeft, $btnRight);
-
-		// 将遮罩层添加到 body
-		$('body').append($fullscreenMask);
-		setTimeout(function () {
-			$fullscreenMask.addClass('active');
-		}, 10);
-
-		// 点击遮罩层时关闭
-		$fullscreenMask.on('click', function (e) {
-			if (!$(e.target).is($btnLeft) && !$(e.target).is($btnRight)) {
-				$fullscreenMask.removeClass('active');
-				setTimeout(function () {
-					$fullscreenMask.remove();
-				}, 300);
-			}
-		});
+        // 获取当前父级下所有 .album-thumb-detail img 的 src
+        var imageSrcArray = [];
+        $parentAlbum.find('.album-thumb-detail img').each(function () {
+            src = $(this).attr('data-src');
+            // newSrc = src.split('?')[0];
+            imageSrcArray.push(src);
+        });
 
 
-		// 点击左按钮显示上一张图片
-		$btnLeft.on('click', function () {
-			currentImageIndex--;
-			if (currentImageIndex < 0) {
-				currentImageIndex = imageSrcArray.length - 1;
-			}
-			$fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
-		});
+        // 获取当前点击图片在数组中的索引
+        var $albumThumbs = $parentAlbum.find('.album-thumb-detail');
+        var currentImageIndex = $albumThumbs.index(this);
+        // console.log(currentImageIndex);
+
+        const $fullscreenMask = $('<div>').addClass('fullscreen-mask');
+        const $fullscreenImg = $('<img>').attr('src', imageSrcArray[currentImageIndex]);
+        const $btnLeft = $('<div>').addClass('fullscreen-btn fullscreen-btn-left').html('&lt;');
+        const $btnRight = $('<div>').addClass('fullscreen-btn fullscreen-btn-right').html('&gt;');
+        const $btnDownload = $('<div>').addClass('fullscreen-btn fullscreen-btn-download').html('&#11123;'); // 下载图标
+
+        $fullscreenMask.append($fullscreenImg, $btnLeft, $btnRight, $btnDownload);
+
+        // 将遮罩层添加到 body
+        $('body').append($fullscreenMask);
+        setTimeout(function () {
+            $fullscreenMask.addClass('active');
+        }, 10);
+
+        // 点击遮罩层时关闭
+        $fullscreenMask.on('click', function (e) {
+            if (!$(e.target).is($btnLeft) && !$(e.target).is($btnRight) && !$(e.target).is($btnDownload)) {
+                $fullscreenMask.removeClass('active');
+                setTimeout(function () {
+                    $fullscreenMask.remove();
+                }, 300);
+            }
+        });
 
 
-		// 点击右按钮显示下一张图片
-		$btnRight.on('click', function () {
-			currentImageIndex++;
-			if (currentImageIndex >= imageSrcArray.length) {
-				currentImageIndex = 0;
-			}
-			$fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
-		});
-	});
+        // 点击左按钮显示上一张图片
+        $btnLeft.on('click', function () {
+            currentImageIndex--;
+            if (currentImageIndex < 0) {
+                currentImageIndex = imageSrcArray.length - 1;
+            }
+            $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
+        });
+
+        // 点击右按钮显示下一张图片
+        $btnRight.on('click', function () {
+            currentImageIndex++;
+            if (currentImageIndex >= imageSrcArray.length) {
+                currentImageIndex = 0;
+            }
+            $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
+        });
+
+        // 点击下载按钮下载当前图片
+        $btnDownload.on('click', function (e) {
+
+            e.stopPropagation(); // 阻止事件冒泡
+            const currentImageSrc = imageSrcArray[currentImageIndex];
+
+            // 下载图片 js urlencode
+            url = '/download-image?url='+encodeURIComponent(currentImageSrc);
+            window.location.href = url;
+            console.log(url);
+            loadIndex = layer.load(2, { shade: [0.8, '#000'] });
+            checkDownloadStatus();
+        });
+    });
+
+    // 放大图片 end
 
 
 
 
 	const $overlay = $('#overlay');
 	const $overlay = $('#overlay');
@@ -384,7 +419,7 @@ $(document).ready(function() {
         setInterval(fetchUpdate, 20000); // 10000 毫秒 = 10 秒
         setInterval(fetchUpdate, 20000); // 10000 毫秒 = 10 秒
     }
     }
 
 
-    var loadIndex = null;
+
     var downdHref = function() {
     var downdHref = function() {
         // 查找 .album-tab 中带有 is-active 类的 <a> 标签
         // 查找 .album-tab 中带有 is-active 类的 <a> 标签
         let activeTab = $('.album-tab a.is-active').attr('href');
         let activeTab = $('.album-tab a.is-active').attr('href');
@@ -401,21 +436,7 @@ $(document).ready(function() {
     }
     }
 
 
     //ajax 定时请求 /download-status,直到返回状态为 0 时
     //ajax 定时请求 /download-status,直到返回状态为 0 时
-    var checkDownloadStatus = function() {
-        var intervalId = setInterval(function() {
-            $.ajax({
-                url: '/download-status',
-                method: 'GET',
-                dataType: 'json',
-                success: function(response) {
-                    if (response.status == 0) {
-                        clearInterval(intervalId);
-                        layer.close(loadIndex); // 关闭加载层
-                    }
-                }
-            });
-        }, 1000); // 每秒请求一次
-    }
+
 
 
     // 监听 .download-all 的点击事件
     // 监听 .download-all 的点击事件
     $('.download-all').on('click', function() {
     $('.download-all').on('click', function() {

+ 7 - 2
resources/views/gallery-detail.blade.php

@@ -68,12 +68,14 @@
                     @endphp
                     @endphp
                     @if (empty($content))
                     @if (empty($content))
                         数据为空
                         数据为空
-                    @else
-                        <div class="grid-sizer"></div>
                     @endif
                     @endif
 
 
                     @if ($tab['column'] == 'video' || $tab['column'] == 'pdf')
                     @if ($tab['column'] == 'video' || $tab['column'] == 'pdf')
                         @if ($tab['column'] == 'video' && empty($content) == false)
                         @if ($tab['column'] == 'video' && empty($content) == false)
+                            <?php
+                                //$content倒序
+                                $content = array_reverse($content);
+                            ?>
                             <table class="album_table">
                             <table class="album_table">
                                 <thead>
                                 <thead>
                                 <tr>
                                 <tr>
@@ -97,6 +99,7 @@
                                 @endforeach
                                 @endforeach
                                 </tbody>
                                 </tbody>
                             </table>
                             </table>
+                            <br/>
                         @endif
                         @endif
 
 
                         @if ($tab['column'] == 'pdf' && empty($content) == false)
                         @if ($tab['column'] == 'pdf' && empty($content) == false)
@@ -118,8 +121,10 @@
                                     @endforeach
                                     @endforeach
                                     </tbody>
                                     </tbody>
                                 </table>
                                 </table>
+                            <br/>
                         @endif
                         @endif
                     @else
                     @else
+                        <div class="grid-sizer"></div>
                         @foreach($content as $item)
                         @foreach($content as $item)
                         <div class="grid-item album-item">
                         <div class="grid-item album-item">
                             <div class="album-thumb album-thumb-detail">
                             <div class="album-thumb album-thumb-detail">

+ 12 - 8
routes/web.php

@@ -16,14 +16,18 @@ use Illuminate\Support\Facades\Route;
 
 
 Route::get('/', [AuthController::class, 'getLogin']);
 Route::get('/', [AuthController::class, 'getLogin']);
 Route::post('/post-login', [AuthController::class, 'postLogin']);
 Route::post('/post-login', [AuthController::class, 'postLogin']);
-Route::get('/index', [HomeController::class, 'index']);
-Route::get('/main', [HomeController::class, 'main']);
-Route::get('/gallery', [HomeController::class, 'gallery']);
-Route::get('/next-log', [HomeController::class, 'nextLog']);
-Route::get('/update-log', [HomeController::class, 'updateLog']);
-Route::get('/detail', [HomeController::class, 'detail']);
-Route::get('/download-all', [HomeController::class, 'downloadAll']);
-Route::get('/download-status', [HomeController::class, 'getDownloadAllStatus']);
 
 
+Route::middleware(['web'])->group(function () {
+    // 此处放置你的路由
+    Route::get('/index', [HomeController::class, 'index']);
+    Route::get('/main', [HomeController::class, 'main']);
+    Route::get('/gallery', [HomeController::class, 'gallery']);
+    Route::get('/next-log', [HomeController::class, 'nextLog']);
+    Route::get('/update-log', [HomeController::class, 'updateLog']);
+    Route::get('/detail', [HomeController::class, 'detail']);
+    Route::get('/download-all', [HomeController::class, 'downloadAll']);
+    Route::get('/download-status', [HomeController::class, 'getDownloadAllStatus']);
+    Route::get('/download-image', [HomeController::class, 'downloadImage']);
+});