mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: disable copy snippet button for github.com
This commit is contained in:
parent
ab82cf783e
commit
da494982dd
3 changed files with 60 additions and 20 deletions
|
|
@ -1,7 +1,5 @@
|
|||
import { storageHelper } from 'utils/storageHelper'
|
||||
import { Migration } from '.'
|
||||
import { Storage } from '../../storageHelper'
|
||||
import { VersionedConfig } from '../helper'
|
||||
import { Migration, onConfigOutdated } from '.'
|
||||
|
||||
export const migration: Migration = {
|
||||
version: '2.6.0',
|
||||
|
|
@ -13,29 +11,24 @@ export const migration: Migration = {
|
|||
accessToken?: string
|
||||
}
|
||||
|
||||
const config = await storageHelper.get<VersionedConfig<ConfigBeforeMigrate> & Storage>()
|
||||
if (config && config.configVersion < version) {
|
||||
const { configVersion, ...restConfig } = config
|
||||
for (const key of Object.keys(restConfig)) {
|
||||
onConfigOutdated(version, async configs => {
|
||||
for (const key of Object.keys(configs)) {
|
||||
if (
|
||||
typeof restConfig[key] === 'object' &&
|
||||
restConfig[key] &&
|
||||
'access_token' in restConfig[key]
|
||||
typeof configs[key] === 'object' &&
|
||||
configs[key] !== null &&
|
||||
'access_token' in configs[key]
|
||||
) {
|
||||
const config: ConfigBeforeMigrate = restConfig[key]
|
||||
const { access_token: accessToken, ...legacy } = config
|
||||
const migrated: ConfigAfterMigrate = {
|
||||
...legacy,
|
||||
const configBeforeMigrate: ConfigBeforeMigrate = configs[key]
|
||||
const { access_token: accessToken, ...rest } = configBeforeMigrate
|
||||
const configAfterMigrate: ConfigAfterMigrate = {
|
||||
...rest,
|
||||
accessToken,
|
||||
}
|
||||
await storageHelper.set({
|
||||
[key]: migrated,
|
||||
[key]: configAfterMigrate,
|
||||
})
|
||||
}
|
||||
}
|
||||
await storageHelper.set({
|
||||
configVersion: version,
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
|
|
|
|||
33
src/utils/config/migrations/3.0.0.ts
Normal file
33
src/utils/config/migrations/3.0.0.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { storageHelper } from 'utils/storageHelper'
|
||||
import { Migration, onConfigOutdated } from '.'
|
||||
|
||||
export const migration: Migration = {
|
||||
version: '3.0.0',
|
||||
async migrate(version) {
|
||||
// disable copy snippet button for github.com
|
||||
type ConfigBeforeMigrate = {
|
||||
copySnippetButton: boolean
|
||||
}
|
||||
type ConfigAfterMigrate = {
|
||||
copySnippetButton: boolean
|
||||
}
|
||||
|
||||
onConfigOutdated(version, async configs => {
|
||||
const key = 'platform_github.com'
|
||||
const config = configs[key]
|
||||
if (typeof config === 'object' && config !== null && 'copySnippetButton' in config) {
|
||||
const configBeforeMigrate: ConfigBeforeMigrate = config
|
||||
const { copySnippetButton, ...rest } = configBeforeMigrate
|
||||
if (copySnippetButton) {
|
||||
const configAfterMigrate: ConfigAfterMigrate = {
|
||||
...rest,
|
||||
copySnippetButton: false,
|
||||
}
|
||||
await storageHelper.set({
|
||||
[key]: configAfterMigrate,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ import { Storage } from '../../storageHelper'
|
|||
import { migration as v1v0v1 } from './1.0.1'
|
||||
import { migration as v1v3v4 } from './1.3.4'
|
||||
import { migration as v2v6v0 } from './2.6.0'
|
||||
import { migration as v3v0v0 } from './3.0.0'
|
||||
|
||||
export type Migration = {
|
||||
version: string
|
||||
|
|
@ -10,9 +11,22 @@ export type Migration = {
|
|||
}
|
||||
|
||||
export async function migrateConfig() {
|
||||
const migrations: Migration[] = [v1v0v1, v1v3v4, v2v6v0]
|
||||
const migrations: Migration[] = [v1v0v1, v1v3v4, v2v6v0, v3v0v0]
|
||||
|
||||
for (const { version, migrate } of migrations) {
|
||||
await migrate(version)
|
||||
}
|
||||
}
|
||||
|
||||
export async function onConfigOutdated<T extends { [key: string]: any }>(
|
||||
configVersion: string,
|
||||
runIfOutdated: (config: T) => Async<void>,
|
||||
) {
|
||||
const config = await storageHelper.get<Storage>()
|
||||
|
||||
if (config && config.configVersion < configVersion) {
|
||||
const { configVersion, ...restConfig } = config
|
||||
runIfOutdated(restConfig as T)
|
||||
await storageHelper.set({ configVersion })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue