Skip to content

Commit

Permalink
fix: export data & remove save userInfo in monkey
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilfish committed Mar 29, 2024
1 parent 3b3c2b3 commit b9a8729
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 36 deletions.
28 changes: 0 additions & 28 deletions apps/monkey/src/Ctrl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,6 @@ const { config } = storeToRefs(configStore)
const percentage = computed(() => config.value.fetchedCount / postStore.total * 100)
const progressText = computed(() => () => `${config.value.fetchedCount}/${postStore.total} 条`)
/**
* 保存用户信息,以在预览页中获取这些信息
*/
async function saveUserInfo() {
const user = await userDetail(config.value.uid)
user.exportedAt = new Date().toLocaleString()
const users = GM_getValue<any[]>('users') ?? []
const index = users.findIndex((u: any) => u.uid === user.uid)
if (index !== -1)
Object.assign(users[index], user)
else
users.push(user)
GM_setValue('users', users)
console.log('已同步的用户信息', users)
message.success('用户信息同步成功')
}
/**
* 导出数据
*/
Expand All @@ -53,8 +33,6 @@ async function exportDatas() {
return
const scripts = 'https://github.com/Chilfish/Weibo-archiver/raw/monkey/scripts.zip'
saveAs(scripts, 'scripts.zip')
await saveUserInfo()
}
const { pause, start } = fetchPosts({
Expand Down Expand Up @@ -186,12 +164,6 @@ function toggleStop() {
>
导出
</button>

<button
@click="saveUserInfo"
>
同步信息
</button>
</div>
</div>

Expand Down
8 changes: 4 additions & 4 deletions apps/monkey/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ if (document.location.hostname === 'weibo.com') {
initApp()
console.log('weibo-archiver 加载成功')
}
else {
const users = GM_getValue('users') || []
// else {
// const users = GM_getValue('users') || []

localStorage.setItem('users', JSON.stringify(users))
}
// localStorage.setItem('users', JSON.stringify(users))
// }
2 changes: 1 addition & 1 deletion apps/monkey/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default defineConfig({
match: [
'https://weibo.com/u/*',
'https://weibo.com/n/*',
'https://weibo.chilfish.top/*',
// 'https://weibo.chilfish.top/*',
],
grant: [
'GM_setValue',
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/stores/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export const usePublicStore = defineStore('public', () => {
curUid.value = users.value[0]?.uid || ''
}

function importUser(user: UserInfo) {
curUid.value = user.uid
addUser(user)
}

/**
* 从旧版中迁移 user 数据到 idb 中
*/
Expand All @@ -54,5 +59,6 @@ export const usePublicStore = defineStore('public', () => {
addUser,
rmUser,
migrateUser,
importUser,
}
})
5 changes: 2 additions & 3 deletions packages/ui/src/settings/base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ function onImportData({ file }: UploadCustomRequestOptions) {
user = data.user
}
publicStore.curUid = user.uid
publicStore.users.push(user)
publicStore.importUser(user)
await postStore.set(posts, user, coverMode.value)
user.postCount = postStore.total
Expand All @@ -82,7 +81,7 @@ function onImportData({ file }: UploadCustomRequestOptions) {
async function exportDatas() {
isExporting.value = true
const data = await postStore.getAll()
await exportData(data)
await exportData(data, publicStore.curUser)
isExporting.value = false
}
Expand Down

0 comments on commit b9a8729

Please sign in to comment.