Skip to content

Commit

Permalink
fix(core): import followings
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilfish committed Mar 29, 2024
1 parent 56d7de8 commit 7af724a
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 9 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## v0.3.11

[compare changes](https://github.com/Chilfish/Weibo-archiver/compare/v0.3.10...v0.3.11)

### 🚀 Enhancements

- Add fetching user followings ([#44](https://github.com/Chilfish/Weibo-archiver/pull/44))

### 🩹 Fixes

- **core:** Transform old data before import ([2cde106](https://github.com/Chilfish/Weibo-archiver/commit/2cde106))
- **web:** 迁移旧版数据 ([5c7e2b7](https://github.com/Chilfish/Weibo-archiver/commit/5c7e2b7))

### 💅 Refactors

- 移出导出数据中的 post.user ([#43](https://github.com/Chilfish/Weibo-archiver/pull/43))

### ❤️ Contributors

- Chilfish ([@Chilfish](http://github.com/Chilfish))

## v0.3.10

[compare changes](https://github.com/Chilfish/Weibo-archiver/compare/v0.3.9...v0.3.10)
Expand Down
2 changes: 1 addition & 1 deletion apps/monkey/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@weibo-archiver/monkey",
"type": "module",
"version": "0.3.10",
"version": "0.3.11",
"private": true,
"author": "Chilfish",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion apps/monkey/src/Ctrl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ async function startFetch() {
duration: 5000,
})
postStore.setDB()
await postStore.setDB()
isStart.value = true
isFinish.value = false
isStop.value = false
Expand Down
4 changes: 3 additions & 1 deletion apps/monkey/src/stores/postStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export const usePostStore = defineStore('post', () => {

const idb = ref<IDB>(new EmptyIDB())

function setDB() {
async function setDB() {
const wrappedUid = `uid-${config.value.uid}` as UID
if (idb.value.name === wrappedUid)
return
idb.value = new IDB(wrappedUid)

await idb.value.clearFollowings()
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@weibo-archiver/web",
"type": "module",
"version": "0.3.10",
"version": "0.3.11",
"private": true,
"description": "",
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "weibo-archiver",
"type": "module",
"version": "0.3.10",
"version": "0.3.11",
"packageManager": "[email protected]",
"description": "Archive your Weibo posts before being banned completely.",
"author": {
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/stores/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ export const usePostStore = defineStore('post', () => {
async function set(
data: Post[],
user: UserInfo,
followings?: UserBio[],
_followings?: UserBio[],
isReplace = false,
) {
await waitIDB()

if (followings && followings.length)
await idb.value.addFollowings(followings)
if (_followings && _followings.length) {
await idb.value.clearFollowings()
followings.value = _followings
await idb.value.addFollowings(_followings)
}

const { count, search } = await idb.value.addDBPosts(data, isReplace)
totalDB.value = count
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,17 @@ export class IDB {
*/
async clearDB() {
const db = await this.idb
await db.clear(POST_STORE)

await Promise.all([
db.clear(POST_STORE),
db.clear(USER_STORE),
db.clear(FOLLOWERINGS_STORE),
])
}

async clearFollowings() {
const db = await this.idb
await db.clear(FOLLOWERINGS_STORE)
}

/**
Expand Down

0 comments on commit 7af724a

Please sign in to comment.