-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
monorepo: rework filter suspension extra monitoring
- Loading branch information
Showing
13 changed files
with
326 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
api/Sources/Api/Models/User/User+ExtraMonitoringOptions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import Gertie | ||
|
||
extension FilterSuspensionDecision.ExtraMonitoring { | ||
var magicString: String { | ||
switch self { | ||
case .addKeylogging: | ||
return "k" | ||
case .setScreenshotFreq(let frequency): | ||
return "@\(frequency)" | ||
case .addKeyloggingAndSetScreenshotFreq(let frequency): | ||
return "@\(frequency)+k" | ||
} | ||
} | ||
|
||
init?(magicString: String) { | ||
var input = magicString | ||
if input == "k" { | ||
self = .addKeylogging | ||
} else if input.hasPrefix("@") { | ||
input.removeFirst() | ||
var withKeylogging = false | ||
if input.hasSuffix("+k") { | ||
withKeylogging = true | ||
input.removeLast(2) | ||
} | ||
guard let frequency = Int(input) else { | ||
return nil | ||
} | ||
if withKeylogging { | ||
self = .addKeyloggingAndSetScreenshotFreq(frequency) | ||
} else { | ||
self = .setScreenshotFreq(frequency) | ||
} | ||
} else { | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
extension User { | ||
var extraMonitoringOptions: [FilterSuspensionDecision.ExtraMonitoring: String] { | ||
var opts: [FilterSuspensionDecision.ExtraMonitoring: String] = [:] | ||
if !keyloggingEnabled { | ||
opts[.addKeylogging] = "keylogging" | ||
} | ||
|
||
if !screenshotsEnabled { | ||
opts[.setScreenshotFreq(120)] = "Screenshot every 2m" | ||
opts[.setScreenshotFreq(90)] = "Screenshot every 90s" | ||
opts[.setScreenshotFreq(60)] = "Screenshot every 60s" | ||
opts[.setScreenshotFreq(30)] = "Screenshot every 30s" | ||
|
||
if !keyloggingEnabled { | ||
opts[.addKeyloggingAndSetScreenshotFreq(120)] = "Screenshot every 2m + keylogging" | ||
opts[.addKeyloggingAndSetScreenshotFreq(90)] = "Screenshot every 90s + keylogging" | ||
opts[.addKeyloggingAndSetScreenshotFreq(60)] = "Screenshot every 60s + keylogging" | ||
opts[.addKeyloggingAndSetScreenshotFreq(30)] = "Screenshot every 30s + keylogging" | ||
} | ||
} else { | ||
opts[.setScreenshotFreq(Int(Double(screenshotsFrequency) / 1.5))] = "1.5x screenshots" | ||
opts[.setScreenshotFreq(screenshotsFrequency / 2)] = "2x screenshots" | ||
opts[.setScreenshotFreq(screenshotsFrequency / 3)] = "3x screenshots" | ||
|
||
if !keyloggingEnabled { | ||
opts[.addKeyloggingAndSetScreenshotFreq(Int(Double(screenshotsFrequency) / 1.5))] = | ||
"1.5x screenshots + keylogging" | ||
opts[.addKeyloggingAndSetScreenshotFreq(screenshotsFrequency / 2)] = | ||
"2x screenshots + keylogging" | ||
opts[.addKeyloggingAndSetScreenshotFreq(screenshotsFrequency / 3)] = | ||
"3x screenshots + keylogging" | ||
} | ||
} | ||
|
||
opts = opts.filter { opt, _ in | ||
opt.screenshotsFrequency ?? Int.max > 10 | ||
} | ||
|
||
return opts | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.