refactor: native feature management (#2350)
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user