diff --git a/Clean.ps1 b/Clean.ps1 deleted file mode 100644 index be8bd96..0000000 --- a/Clean.ps1 +++ /dev/null @@ -1,172 +0,0 @@ -# Directory containing your JSON files -$dir = "C:\Responses" - -function Matches-SetSessionStatus($content) { - $topKeys = $content.PSObject.Properties.Name - if ($topKeys.Count -ne 2 -or -not ($topKeys -contains "data") -or -not ($topKeys -contains "extensions")) { return $false } - - $dataKeys = $content.data.PSObject.Properties.Name - if ($dataKeys.Count -ne 1 -or $dataKeys -ne "setSessionStatus") { return $false } - - $ssKeys = $content.data.setSessionStatus.PSObject.Properties.Name - if ($ssKeys.Count -ne 2 -or -not ($ssKeys -contains "setAgainInSeconds") -or -not ($ssKeys -contains "__typename")) { return $false } - - if ($content.data.setSessionStatus.__typename -ne "SetSessionStatusPayload") { return $false } - - $extKeys = $content.extensions.PSObject.Properties.Name - if ($extKeys.Count -ne 3 -or -not ($extKeys -contains "durationMilliseconds") -or -not ($extKeys -contains "operationName") -or -not ($extKeys -contains "requestID")) { return $false } - - return ($content.extensions.operationName -eq "ChannelPage_SetSessionStatus") -} - -function Matches-UseLive($content) { - $topKeys = $content.PSObject.Properties.Name - if ($topKeys.Count -ne 2 -or -not ($topKeys -contains "data") -or -not ($topKeys -contains "extensions")) { return $false } - - $dataKeys = $content.data.PSObject.Properties.Name - if ($dataKeys.Count -ne 1 -or $dataKeys -ne "user") { return $false } - - $userKeys = $content.data.user.PSObject.Properties.Name - if ($userKeys.Count -ne 4 -or -not ($userKeys -contains "id") -or -not ($userKeys -contains "login") -or -not ($userKeys -contains "stream") -or -not ($userKeys -contains "__typename")) { return $false } - - if ($content.data.user.__typename -ne "User") { return $false } - - $extKeys = $content.extensions.PSObject.Properties.Name - if ($extKeys.Count -ne 3 -or -not ($extKeys -contains "durationMilliseconds") -or -not ($extKeys -contains "operationName") -or -not ($extKeys -contains "requestID")) { return $false } - - return ($content.extensions.operationName -eq "UseLive") -} - -function Matches-StoryPreviewsWithOrder($content) { - $topKeys = $content.PSObject.Properties.Name - if ($topKeys.Count -ne 2 -or -not ($topKeys -contains "data") -or -not ($topKeys -contains "extensions")) { return $false } - - $dataKeys = $content.data.PSObject.Properties.Name - if ($dataKeys.Count -ne 1 -or $dataKeys -ne "storyPreviewsWithOrder") { return $false } - - $spKeys = $content.data.storyPreviewsWithOrder.PSObject.Properties.Name - if ($spKeys.Count -ne 4 -or -not ($spKeys -contains "previews") -or -not ($spKeys -contains "hasNextPage") -or -not ($spKeys -contains "isFresh") -or -not ($spKeys -contains "__typename")) { return $false } - - if ($content.data.storyPreviewsWithOrder.__typename -ne "StoryPreviewsWithOrder") { return $false } - - $extKeys = $content.extensions.PSObject.Properties.Name - if ($extKeys.Count -ne 3 -or -not ($extKeys -contains "durationMilliseconds") -or -not ($extKeys -contains "operationName") -or -not ($extKeys -contains "requestID")) { return $false } - - return ($content.extensions.operationName -eq "StoryPreviewsWithOrder") -} - -function Matches-ConnectAdIdentity($content) { - $topKeys = $content.PSObject.Properties.Name - if ($topKeys.Count -ne 2 -or -not ($topKeys -contains "data") -or -not ($topKeys -contains "extensions")) { return $false } - - $dataKeys = $content.data.PSObject.Properties.Name - if ($dataKeys.Count -ne 1 -or $dataKeys -ne "connectAdIdentity") { return $false } - - $adKeys = $content.data.connectAdIdentity.PSObject.Properties.Name - if ($adKeys.Count -ne 2 -or -not ($adKeys -contains "identityURL") -or -not ($adKeys -contains "__typename")) { return $false } - - if ($content.data.connectAdIdentity.__typename -ne "ConnectAdIdentityPayload") { return $false } - - $extKeys = $content.extensions.PSObject.Properties.Name - if ($extKeys.Count -ne 3 -or -not ($extKeys -contains "durationMilliseconds") -or -not ($extKeys -contains "operationName") -or -not ($extKeys -contains "requestID")) { return $false } - - return ($content.extensions.operationName -eq "ConnectAdIdentityMutation") -} - -function Matches-CurrentUser($content) { - $topKeys = $content.PSObject.Properties.Name - if ($topKeys.Count -ne 2 -or -not ($topKeys -contains "data") -or -not ($topKeys -contains "extensions")) { return $false } - - $dataKeys = $content.data.PSObject.Properties.Name - if ($dataKeys.Count -ne 1 -or $dataKeys -ne "currentUser") { return $false } - - $cuKeys = $content.data.currentUser.PSObject.Properties.Name - if ($cuKeys.Count -ne 6 -or -not ($cuKeys -contains "id") -or -not ($cuKeys -contains "login") -or -not ($cuKeys -contains "hasTurbo") -or -not ($cuKeys -contains "hasPrime") -or -not ($cuKeys -contains "language") -or -not ($cuKeys -contains "__typename")) { return $false } - - if ($content.data.currentUser.__typename -ne "User") { return $false } - - $extKeys = $content.extensions.PSObject.Properties.Name - if ($extKeys.Count -ne 3 -or -not ($extKeys -contains "durationMilliseconds") -or -not ($extKeys -contains "operationName") -or -not ($extKeys -contains "requestID")) { return $false } - - return ($content.extensions.operationName -eq "Core_Services_Spade_CurrentUser") -} - -function Matches-CoreServicesSpadeCurrentUser { - param ($json) - return $json.data.currentUser -and - $json.extensions.operationName -eq "Core_Services_Spade_CurrentUser" -} - -function Matches-TopNavCurrentUser { - param ($json) - return $json.data.currentUser -and - $json.data.requestInfo -and - $json.extensions.operationName -eq "TopNav_CurrentUser" -} - -function Matches-GuestStarBatchCollaboration { - param($json) - - return ( - $json.PSObject.Properties.Name -contains 'data' -and - $json.PSObject.Properties.Name -contains 'extensions' -and - - $json.data.PSObject.Properties.Name -contains 'guestStarChannelCollaboration' -and - $json.data.PSObject.Properties.Name -contains 'guestStarCollaborationStatuses' -and - - $json.extensions.operationName -eq 'GuestStarBatchCollaborationQuery' - ) -} - -function Matches-OnsiteNotificationsSummary { - param($json) - - return ( - $json.PSObject.Properties.Name -contains 'data' -and - $json.PSObject.Properties.Name -contains 'extensions' -and - - $json.data.PSObject.Properties.Name -contains 'currentUser' -and - $json.data.currentUser.PSObject.Properties.Name -contains 'id' -and - $json.data.currentUser.PSObject.Properties.Name -contains 'notifications' -and - $json.data.currentUser.notifications.PSObject.Properties.Name -contains 'summary' -and - $json.data.currentUser.notifications.summary.PSObject.Properties.Name -contains 'unseenCount' -and - $json.data.currentUser.notifications.summary.PSObject.Properties.Name -contains 'viewerUnreadSummary' -and - $json.data.currentUser.notifications.summary.PSObject.Properties.Name -contains 'creatorUnreadSummary' -and - - $json.extensions.operationName -eq 'OnsiteNotifications_Summary' - ) -} - -# Counter -$deleted = 0 -$skipped = 0 - -# Loop through files and check -Get-ChildItem -Path $dir -Filter *.json | ForEach-Object { - try { - $content = Get-Content $_.FullName -Raw | ConvertFrom-Json -ErrorAction Stop - - if ((Matches-SetSessionStatus $content) -or - (Matches-UseLive $content) -or - (Matches-StoryPreviewsWithOrder $content) -or - (Matches-ConnectAdIdentity $content) -or - (Matches-CoreServicesSpadeCurrentUser $content) -or - (Matches-TopNavCurrentUser $content) -or - (Matches-GuestStarBatchCollaboration $content) -or - (Matches-OnsiteNotificationsSummary $content)) { - - Write-Host "Deleting file: $($_.FullName)" - Remove-Item $_.FullName -Force - $deleted++ - } - else { - $skipped++ - } - } - catch { - Write-Host "Skipping invalid JSON file: $($_.FullName)" - $skipped++ - } -} - -Write-Host "Done. Deleted: $deleted, Skipped: $skipped" diff --git a/powerboi.ps1 b/powerboi.ps1 deleted file mode 100644 index 7e6f9e1..0000000 --- a/powerboi.ps1 +++ /dev/null @@ -1,58 +0,0 @@ -$src = "C:\Responses\processed" -$dest = "C:\Responses" -$deg = 16000 - -# What to do when a destination file with the same name exists and contents are identical. -# Options: 'skip' - do not move the source (leave it where it is) -# 'overwrite' - replace the destination with the source -$SameFileAction = 'skip' - -New-Item -ItemType Directory -Path $dest -Force | Out-Null - -Get-ChildItem -Path $src -Filter *.json -Recurse -File | -ForEach-Object -Parallel { - $dest = $using:dest - # copy the using-scoped setting into a local variable for safe use inside the scriptblock - $sameAction = $using:SameFileAction - $name = $_.Name - $target = Join-Path $dest $name - - if (Test-Path -LiteralPath $target) { - # Try comparing contents by hash. If identical, either skip or overwrite based on $using:SameFileAction. - try { - $srcHash = Get-FileHash -Algorithm SHA256 -Path $_.FullName - $dstHash = Get-FileHash -Algorithm SHA256 -Path $target - if ($srcHash.Hash -eq $dstHash.Hash) { - switch ($sameAction.ToLower()) { - 'skip' { - Write-Verbose "Skipping move for identical file: $name" - return - } - 'overwrite' { - Move-Item -LiteralPath $_.FullName -Destination $target -Force - return - } - default { - Write-Verbose "Unknown SameFileAction '$sameAction', skipping $name" - return - } - } - } - } - catch { - # If hashing failed for any reason, fall back to the existing collision-avoidance behavior. - Write-Verbose "Hash comparison failed for $($name): $($_)" - } - - # If we reach here, target exists and contents differ: find a non-colliding name (foo (1).json, etc.) - $i = 1 - while (Test-Path -LiteralPath $target) { - $base = [IO.Path]::GetFileNameWithoutExtension($name) - $ext = [IO.Path]::GetExtension($name) - $target = Join-Path $dest ("{0} ({1}){2}" -f $base, $i, $ext) - $i++ - } - } - - Move-Item -LiteralPath $_.FullName -Destination $target -Force -} -ThrottleLimit $deg \ No newline at end of file