refactor: native feature management (#2350)

This commit is contained in:
Mo
2023-07-12 12:56:08 -05:00
committed by GitHub
parent 49f7581cd8
commit 078ef3772c
223 changed files with 3996 additions and 3438 deletions

View File

@@ -0,0 +1,32 @@
import { SettingsClientInterface } from '@Lib/Services/Settings/SettingsClientInterface'
import { SNFeatureRepo } from '@standardnotes/models'
import { MutatorClientInterface } from '@standardnotes/services'
import { SettingName } from '@standardnotes/settings'
export class MigrateFeatureRepoToUserSettingUseCase {
constructor(private mutator: MutatorClientInterface, private settings: SettingsClientInterface) {}
async execute(featureRepos: SNFeatureRepo[] = []): Promise<void> {
for (const item of featureRepos) {
if (item.migratedToUserSetting) {
continue
}
if (!item.onlineUrl) {
continue
}
const repoUrl: string = item.onlineUrl
const userKeyMatch = repoUrl.match(/\w{32,64}/)
if (userKeyMatch && userKeyMatch.length > 0) {
const userKey = userKeyMatch[0]
await this.settings.updateSetting(SettingName.create(SettingName.NAMES.ExtensionKey).getValue(), userKey, true)
await this.mutator.changeFeatureRepo(item, (m) => {
m.migratedToUserSetting = true
})
}
}
}
}