Files
standardnotes-app-web/packages/snjs/lib/Services/Features/UseCase/MigrateFeatureRepoToUserSetting.ts
Mo 4a29e2a24c chore: upgrade eslint and prettier (#2376)
* chore: upgrade eslint and prettier

* chore: add restrict-template-expressions
2023-07-27 14:36:05 -05:00

36 lines
1.1 KiB
TypeScript

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
})
}
}
}
}