Skip to content

Commit

Permalink
feat(migrate old data): migrate Boorus
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Nov 13, 2023
1 parent 70c0c15 commit 6d1d6b8
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 10 deletions.
18 changes: 10 additions & 8 deletions assets/js/BackupHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { db as postsDb, type ISavedPost } from '~/store/SavedPosts'
import type { ITagCollection } from '~/assets/js/tagCollection.dto'
import type { VuexUser } from '~/assets/js/oldLocalStorage.dto'
import { cloneDeep, toLower, union } from 'lodash-es'
import { cloneDeep, toLower, union, unionWith } from 'lodash-es'
import type { Domain } from '~/assets/js/domain'
import { booruTypeList } from '~/assets/lib/rule-34-shared-resources/src/util/BooruUtils'

Expand Down Expand Up @@ -97,7 +97,7 @@ export function migrateOldVersionState(): void {

const vuexUser: VuexUser = JSON.parse(localStorage.getItem('vuex-user')!)

// Migrate settings
// === Migrate settings
if (vuexUser.user.settings.touchGestures)
userSettings.navigationTouchGestures = vuexUser.user.settings.touchGestures.value

Expand All @@ -107,27 +107,29 @@ export function migrateOldVersionState(): void {
if (vuexUser.user.settings.postsPerPage)
userSettings.postsPerPage = vuexUser.user.settings.postsPerPage.value

// Migrate tag collections
// === Migrate tag collections
if (vuexUser.user.custom.tagCollections) {
tagCollections.value = mergeBlocklists(tagCollections.value, vuexUser.user.custom.tagCollections)
}

// Migrate Boorus
// === Migrate Boorus
const vuexUserBoorusMigrated = vuexUser.user.custom.boorus.map(booru => {
// TODO: Find defaults and return that

return {
domain: booru.domain,

type: booruTypeList.find(type => type.type === booru.type),

config: booru.config,

isPremium: true
}
}) as Domain[]

booruList.value = union(booruList.value, vuexUserBoorusMigrated)
booruList.value = unionWith(booruList.value, vuexUserBoorusMigrated, (obj1, obj2) => {
return obj1.domain === obj2.domain
})

// Migrate saved posts
// === Migrate saved posts


removeOldVersionState()
Expand Down
77 changes: 77 additions & 0 deletions test/feature/pages/premium/migrate-old-data.mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,80 @@ export const migratedTagCollectionsMock = [
]
}
]

/**
* Manual migration of the following:
* @see oldLocalStorageVuexUserMock
* @see useBooruList
*/
export const migratedBooruListMock = [{
'domain': 'rule34.xxx',
'type': { 'type': 'rule34.xxx', 'initialPageID': 0, 'posts': true, 'singlePost': true, 'tags': true, 'random': false },
'config': null,
'isPremium': false
}, {
'domain': 'rule34.paheal.net',
'type': { 'type': 'rule34.paheal.net', 'initialPageID': 0, 'posts': true, 'singlePost': true, 'tags': true, 'random': false },
'config': { 'options': { 'HTTPScheme': 'http' } },
'isPremium': false
}, {
'domain': 'danbooru.donmai.us',
'type': { 'type': 'danbooru2', 'initialPageID': 1, 'posts': true, 'singlePost': true, 'tags': true, 'random': true },
'config': null,
'isPremium': false
}, {
'domain': 'gelbooru.com',
'type': { 'type': 'gelbooru.com', 'initialPageID': 0, 'posts': true, 'singlePost': true, 'tags': true, 'random': false },
'config': null,
'isPremium': false
}, {
'domain': 'safebooru.org',
'type': { 'type': 'gelbooru', 'initialPageID': 0, 'posts': true, 'singlePost': true, 'tags': true, 'random': false },
'config': null,
'isPremium': false
}, {
'domain': 'e621.net',
'type': { 'type': 'e621.net', 'initialPageID': 1, 'posts': true, 'singlePost': true, 'tags': true, 'random': true },
'config': null,
'isPremium': false
}, {
'domain': 'e926.net',
'type': { 'type': 'e621.net', 'initialPageID': 1, 'posts': true, 'singlePost': true, 'tags': true, 'random': true },
'config': null,
'isPremium': false
}, {
'domain': 'xbooru.com',
'type': { 'type': 'gelbooru', 'initialPageID': 0, 'posts': true, 'singlePost': true, 'tags': true, 'random': false },
'config': null,
'isPremium': true
}, {
'domain': 'hypnohub.net',
'type': { 'type': 'danbooru', 'initialPageID': 1, 'posts': true, 'singlePost': false, 'tags': true, 'random': true },
'config': null,
'isPremium': true
}, {
'domain': 'yande.re',
'type': { 'type': 'danbooru', 'initialPageID': 1, 'posts': true, 'singlePost': false, 'tags': true, 'random': true },
'config': null,
'isPremium': true
}, {
'domain': 'konachan.com',
'type': { 'type': 'danbooru', 'initialPageID': 1, 'posts': true, 'singlePost': false, 'tags': true, 'random': true },
'config': null,
'isPremium': true
}, {
'domain': 'lolibooru.moe',
'type': { 'type': 'danbooru', 'initialPageID': 1, 'posts': true, 'singlePost': false, 'tags': true, 'random': true },
'config': null,
'isPremium': true
}, {
'domain': 'booru.allthefallen.moe',
'type': { 'type': 'danbooru', 'initialPageID': 1, 'posts': true, 'singlePost': false, 'tags': true, 'random': true },
'config': null,
'isPremium': true
}, {
'domain': 'realbooru.com',
'type': { 'type': 'gelbooru', 'initialPageID': 0, 'posts': true, 'singlePost': true, 'tags': true, 'random': false },
'config': null,
'isPremium': true
}]
4 changes: 2 additions & 2 deletions test/feature/pages/premium/migrate-old-data.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { createPage, setup } from '@nuxt/test-utils'
import { migratedTagCollectionsMock, oldLocalStorageVuexUserMock } from './migrate-old-data.mock-data'
import { migratedBooruListMock, migratedTagCollectionsMock, oldLocalStorageVuexUserMock } from './migrate-old-data.mock-data'

oldLocalStorageVuexUserMock

Expand Down Expand Up @@ -70,7 +70,7 @@ describe('/premium/migrate-old-data', async () => {

expect(migratedTagCollections).toEqual(migratedTagCollectionsMock)

expect(migratedBoorus).toEqual()
expect(migratedBoorus).toEqual(migratedBooruListMock)

expect(isLocalStorageCleaned).toBe(true)
})
Expand Down

0 comments on commit 6d1d6b8

Please sign in to comment.