Browse Source

Merge branch 'dev' of http://134.175.228.187:10880/kyle/autocde2.0 into dev

moell 10 months ago
parent
commit
c258a2d348

+ 4 - 4
app/Http/Controllers/API/ShareFileController.php

@@ -26,10 +26,10 @@ class ShareFileController extends Controller
             'object_id' => $object->id,
         ];
 
-        $shareFile = ShareFile::query()->where($objectFields)->first();
-        if ($shareFile) {
-            return $this->badRequest("Please do not re-share");
-        }
+//        $shareFile = ShareFile::query()->where($objectFields)->first();
+//        if ($shareFile) {
+//            return $this->badRequest("Please do not re-share");
+//        }
 
         $files = File::query()->where($objectFields)->whereIn("id", $request->file_ids)->pluck("id");
         if (! $files) {

+ 6 - 1
app/Services/File/DownloadService.php

@@ -9,6 +9,7 @@ use App\Models\Enums\ShareFileObjectType;
 use App\Models\File;
 use App\Models\Folder;
 use App\Models\ShareFile;
+use Carbon\Carbon;
 use Illuminate\Support\Collection;
 
 class DownloadService
@@ -33,7 +34,11 @@ class DownloadService
         $objectType = ShareFileObjectType::from($shareFile->object_type);
 
         $objectType->modelBuilderAllowed($shareFile->object_id)->findOrFail($shareFile->object_id);
-
+        $now = Carbon::now();
+        $expirationTime = Carbon::parse($shareFile->expiration_time);
+        if($now->gt($expirationTime)){
+            return [];
+        }
         $files = File::query()->with(['folder'])->whereIn("id", $shareFile->files)->get();
 
         return $this->filesFormat($files);

+ 4 - 2
routes/api.php

@@ -16,6 +16,9 @@ use App\Http\Controllers\API;
 */
 
 Route::post("/login", [API\AuthController::class, "login"]);
+//暂时为免登录
+Route::get("file/download/{uuid}/share-file", [API\FileController::class, "downloadShareFile"])
+    ->name("file.download-share-file");
 
 Route::middleware(['auth:sanctum'])->group(function () {
     Route::post("/logout", [API\AuthController::class, "logout"]);
@@ -165,8 +168,7 @@ Route::middleware(['auth:sanctum'])->group(function () {
         Route::post("file/download-zip", [API\FileController::class, "downloadZip"])->name("file.download-zip");
         Route::get("file/download-all-latest/{object_type}/{object_id}", [API\FileController::class, "downloadAllLatest"])
             ->name("file.download-all-latest");
-        Route::get("file/download/{uuid}/share-file", [API\FileController::class, "downloadShareFile"])
-            ->name("file.download-share-file");
+
 
         Route::patch("file/{file}/change-name", [API\FileController::class, "changeName"])->name("file.change-name");
         Route::delete("file/{file}/destroy", [API\FileController::class, "destroy"])->name("file.destroy");