1
0
mirror of https://github.com/cjango/dcat-vue.git synced 2025-12-06 22:40:03 +08:00

同步存储

This commit is contained in:
weiwait
2023-02-11 10:46:29 +08:00
parent 9bda6574be
commit 4f4b21a290
4 changed files with 134 additions and 0 deletions

View File

@@ -120,4 +120,53 @@ class DcatVueController extends Controller
{
return Http::get("https://apis.map.qq.com/ws/geocoder/v1/?location={$request['lat']},{$request['lng']}&key=ZZQBZ-WE6E2-FCMUZ-CBUZ7-ZW5I3-I7BIX&get_poi=1")->body();
}
public function syncStorage(Request $request)
{
$request->validate([
'source' => 'required|string',
'target' => 'required|string',
'timeout' => 'required|integer',
'max' => 'required|integer',
]);
$start = now();
try {
$source = Storage::disk($request['source']);
$source->put('/sync-touch', 'touch');
$source->delete('sync-touch');
$target = Storage::disk($request['target']);
$target->put('/sync-touch', 'touch');
$target->delete('sync-touch');
} catch (\Throwable $exception) {
return 2;
}
try {
$sources = $source->allFiles('/');
$targets = $target->allFiles('/');
$files = array_diff($sources, $targets);
foreach ($files as $file) {
if (now()->diffInSeconds($start) > $request['timeout']) {
return 0;
}
if ($source->size($file) > ($request['max'] * 1024 * 1024)) {
return 1;
}
$target->put($file, $source->get($file));
}
return 1;
} catch (\Throwable $exception) {
}
return 0;
}
}