Skip to content

Commit

Permalink
added: 图片素材删除接口
Browse files Browse the repository at this point in the history
  • Loading branch information
xxx committed Oct 31, 2023
1 parent bbf5d50 commit bea8a86
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
31 changes: 31 additions & 0 deletions app/Http/Controllers/Backend/Api/V1/MediaImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use App\Models\MediaImage;
use Illuminate\Http\Request;
use App\Models\AdministratorLog;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use App\Http\Requests\Backend\ImageUploadRequest;

class MediaImageController extends BaseController
Expand Down Expand Up @@ -83,4 +85,33 @@ public function upload(ImageUploadRequest $request)

return $this->successData($data);
}

public function destroy(Request $request)
{
$ids = $request->input('ids');
if (!$ids || !is_array($ids)) {
return $this->error(__('参数错误'));
}

$images = MediaImage::query()
->select(['id', 'disk', 'path'])
->whereIn('id', $ids)
->get();

if ($images->isNotEmpty()) {
foreach ($images as $imageItem) {
$disk = $imageItem['disk'];
$path = $imageItem['path'];

try {
$imageItem->delete();
Storage::disk($imageItem['disk'])->delete($imageItem['path']);
} catch (\Exception $e) {
Log::error(__METHOD__, ['msg' => $e->getMessage(), 'path' => $path, 'disk' => $disk]);
}
}
}

return $this->success();
}
}
6 changes: 6 additions & 0 deletions database/seeders/AdministratorPermissionSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,12 @@ public function run()
'method' => 'POST',
'url' => '(^video\/token\/aliyun\/refresh$|^video\/token\/aliyun\/create$)',
],
[
'display_name' => '素材库-图片-删除',
'slug' => 'media.image.delete.multi',
'method' => 'POST',
'url' => 'media/image/delete/multi',
],
],
],

Expand Down
3 changes: 3 additions & 0 deletions routes/backend-v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
Route::get('/dashboard/system/info', 'DashboardController@systemInfo');
Route::get('/dashboard/graph', 'DashboardController@graph');

// 素材库-图片-批量删除
Route::post('/media/image/delete/multi', 'MediaImageController@destroy');

Route::group(['prefix' => 'media/videos'], function () {
Route::get('/index', 'MediaVideoController@index');
Route::post('/create', 'MediaVideoController@store');
Expand Down

0 comments on commit bea8a86

Please sign in to comment.